#luckperms-api
1 messages · Page 17 of 1
?. only performs the operation on the right if the result of the value on the left is not null.
// This statement assigns someValue to the value returned by GetSomeBool(). If myPossiblyNullInstance is null, then the ?? operator kicks in.
// The ?? operator returns the value of the left side unless it is null; otherwise, the right side.
bool someValue = myPossiblyNullInstance?.GetSomeBool() ?? false;
That’s essentially what Optional is for
@nocturne elbow make sure your plugin depends on LP/loads after it
how get specific perms from a user?
@gloomy linden do you want to check if a player has a permission?
yes
Then just use the platform’s method for that @gloomy linden
Hey PerryPlaysMC! Please don't tag staff members.
@jaunty pecan, Why won't Commodore work?
Hey PerryPlaysMC! Please don't tag staff members.
maybe try explaining your issue? no one is going to help when you don't supply information
well, I followed his tut exactly
but it does nothing
commands still do what they did before
What's shown here https://www.spigotmc.org/threads/commodore-utility-for-using-minecrafts-1-13-brigadier-library-in-bukkit-plugins.329682/ doesn't work for me
you need to explain HOW it doesn't work
maybe some code samples?
i can't actually help because i'm not a developer but this is generally required information
and stop tagging staff, it's against our #rules
I pre register all my commands,
if (CommodoreProvider.isSupported()) {
// get a commodore instance
Commodore commodore = CommodoreProvider.getCommodore(this);
// register your completions.
registerCompletions(commodore, Miniverse.parseCmdFull("teleport"));
}``` and I get the command with Miniverse.parseCMD
That is shown in the tut
I had a Debug in it saying "registered"
but it doesn't work
hello?
Patience. Not everyone can help
Also Brainstone on a cruise so any development process is halted for me currently but once I get back I'll start looking over everything. Got my new computer setup and the plugins I was interested pulled :)
Cool 😃
api
Alright so my question is not completely related to LP but in a way it still is
I need to send a message when the Join event is called but that message needs to contain the players name and their prefix/suffix so it needs to be loaded after luck perms have assigned them their prefix/suffix
I’ve tested my plugin and the message is sent with only their name and no prefix but the leave message does contain the prefix. So I believe it’s just not loaded when the message is sent on join
What priority are you using?
I tried Monitor, high and low
Are you using Vault or the LP API?
Hello, I use this method to implment a simple permission system for some reason, but LP seemed removed my permission attachment, after I delete LP, it works
Is there any way to solve the problem?
So I've added LuckPerms API to my plugin using maven, and did LuckPermsApi api = LuckPerms.getApi();. Everything compiles but when I start the server with the plugin, it says that API is not loaded (I do have LuckPerms installed on the server). What am I doing wrong?
@obtuse rapids make sure that you're not shading the API in and that your plugin loads after
I added softdepend: [LuckPerms], it didn't work, depend: [LuckPerms] didn't work either
And all I'm doing with the API right now is
LuckPermsApi api = LuckPerms.getApi();
and
api.getUser(event.getPlayer().getName()).getPrimaryGroup()
@obtuse rapids How are you building your plugin?
I am not quite sure if I understood the question correctly, but here are the building dependencies
and here's a screenshot of the artifacts tab in project structure settings
What are you using to build the jar? Maven or Gradle? The "build" button in your IDE?
It looks like Maven
it is maven
where are you calling getApi from?
main class
where abouts in the main class
move it to inside of onEnable
the reason it's throwing that exception is because the main classes of all plugins are initialised before the process of enabling them starts
so the constructor of your plugin (which is effectively what you're initialising in) is called before LP enables
oh I see
Thanks, it finally works
Also, is there no way to get group's display name?
I found this but I think that's only for sponge
Maybe via Vault?
Not sure if this is what you want
https://github.com/MilkBowl/VaultAPI/blob/master/src/main/java/net/milkbowl/vault/chat/Chat.java#L245
@obtuse rapids
Are there any limits on group names?
Hey, how i should do to get number of home count with LP api ? its metaData ? Thanks !
String homecountS = metaData.getMeta().get("home-count");
int homecount = Integer.valueOf(homecountS);
int totalhome = homecount + Integer.valueOf(args[1]);
metaData.getMeta().replace("home-count",String.valueOf(totalhome));```
Isnt correct ? thats return me an error :p
```java.lang.RuntimeException: java.lang.UnsupportedOperationException``` i got this 🤔
@obtuse rapids late reply but i think the method you are looking for is getFriendlyName()
@polar cargo setting meta values works differently
There should be examples on the wiki
i didnt find the example <w<
already tried it i think
{
String key = entry.getKey();
if (key.equalsIgnoreCase("home-count")){
//String value = entry.getValue();
entry.setValue(String.valueOf(totalhome));
}
}```
that too
yeah thatss a bit weird for me, i dont use this api often^^
I'm not sure to understand, i created a class that have LP Event
public class LuckPermEvent {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance().getServer();
public void onUserPromote(UserTrackEvent event)
{
//
}
}```
How i can register it ?
```Java
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
LuckPermsApi api = LuckPerms.getApi();
api.getEventBus().subscribe(UserTrackEvent.class, ?);
}
Not sure to understand, its not like forge/sponge <w<
How would I check if a group exists?
Ok so this code is throwing a null pointer exception
And here is the error I get:
08.04 22:16:32 [Server] ERROR Error occurred while enabling CommandCheckerBlocker v1.0 (Is it up to date?)
08.04 22:16:32 [Server] INFO java.lang.NullPointerException: null
08.04 22:16:32 [Server] INFO at me.ase.CommandCheckerBlocker.Main.onEnable(Main.java:27) ~[?:?]
08.04 22:16:32 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:254) ~[spigot-1.13.2.jar:git-Spigot-518206a-c4a67ee]
08.04 22:16:32 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) ~[spigot-1.13.2.jar:git-Spigot-518206a-```
And line 27 is me registering the GiveRank command
🤔
@nocturne elbow use their lp editor on web, or just download an add-on named lp gui for lp
MOSS's tribute to @frank drift
hi i have luck perms on my network and wen i do /lp networksync it seys it worked bet on the other servers it dus not work wat do i do ??
using plugin manger
How'd you set the prefix of a player programatically?
use essenshalsx
Why? He wants to know how to set a prefix of a user using the LuckPerms API. What has EssentialsX have to do with that?
I've never really used LP before (At least not the API), and there seems to be no documentation at first glance. Maybe documentation could be added on how to edit prefixes and suffixes on the JavaDoc for getPrefixes on MetaData. Still leaves me wondering how to actually set a prefix with a specific weight on a player
If there's no obvious method, you could construct the node yourself and add it
API equivalent of giving the player/group prefix.<weight>.<prefix>: true
I don't actually know of any "add prefix" method in the API
Alright
I looked at the command but sadly that depends on common which is not included in api
@marble shore the wiki has plenty of expamples
@cunning halo check these two guides:
!bungee
!sync
Also #support-1 is the right place for normal support
thanks
ProviderRegistration<LuckPermsApi> provider =
Sponge.getServiceManager().getRegistration(LuckPermsApi.class).orElseThrow(NullPointerException::new);
LuckPermsApi api = provider.getProvider();
User user = api.getUser(player.getUniqueId());
if (user == null) {
player.sendMessage(Text.of(TextColors.RED, "LuckPerms profile not found."));
return;
}
DataMutateResult result = user.setPermission(api.getNodeFactory().makePrefixNode(1000, text).setValue(true).build());
System.out.println(result);``` results in "SUCCESS"
But the prefix was not set
@marble shore you need to save the changes
And also you can just pass the player instance. No need to get the UUID
Also passing Player does not work with Sponge on API version 4.4
Really? That’s a bug then
Probably not, as it's a shared library
I mean did you try?
Yeah, Intellij does not recognize it as valid
Hm. There should be a method that accepts an object
I see
Which is used to accept native player instances
Would be very surprised if that was gone
No such method in getUserManager either
So getting an user returns a mutable version that is not linked to the storage
In essence
@shadow fjord I asked how to do it with the API, not the editor
@nocturne elbow the error is being thrown in your onEnable. Not in the command handler
Having a look at the stack trace usually helps 😉
Yes I figured that out already
But I have a question with something else now
if (!api.isGroupLoaded(args[0])) {
api.getGroupManager().createAndLoadGroup(args[0]);
Group group = api.getGroupManager().getGroup(args[0]);
}```
Apparantly group is not loaded
It brings an error null
even though I just created and loaded it
Guys, I'm having issues with the setPrimary group within the API.
I've checked the API but it doesn't seem to work.
Could you guys give an example on how it would work, this would be amazing! 😃
Can you send the part of the code you use
?
Also, if aanyone can help me for event LP that can be cool xD
@polar cargo we used this
before we used the api but it doesnt work.
also that does apply as quick as we hope
Anyone?
if you use command, use switchprimarygroup ?
i mean, what you want to do ?
i want to remove the group Z
and then add the group A
I know EzRanksPro does it but how?
I dont use bukkit plugin so i cant says for it
if you have only one group, you can do parent set A ?
im doing Java...
Yes but I wan't to switch to the API but it doesn't work..
I want the error or the part of the code you tried to use
for group you have something like user.setPrimayGroup(string)
Yeah, but i just started to use LP as API
The primary group has nothing to do with the actual groups
i just successfully use Event, and for setPrimary group i didnt test but pretty sure it work
Oh hello.
but you need to add the group first
With the default settings it can’t even be set
i think
As it’s calculated automatically
You need to assign the groups
Or the permission for it
There are examples on the wiki for that
Brain, is there not anyway to add the group to the user without it lagging?
EzRanksPro does it and I don't know how.
Of course it doesn’t lag
As I said. Check the wiki
There are plenty of examples
Stone, the thing is, I have.
It takes a while and it can glitch EzRanksPro.
If you’re using the API and it takes a while, then you’re doing it wrong. And if it glitches out ERP, then that’s not on LP
No we're now using the commands.
Due to the API not working for us.
If you could give us an example, this would be amazing 😃
W I K I
Send us a link please.
:paperclip: https://github.com/lucko/LuckPerms/wiki
Thank you 😃
You’re welcome
I'll contact if I need anymore help.
Sorry for wasting your time.
Be sure to read people’s responses next time. Though all good
I’ll be off btw
Just so you know
@crystal sonnet sorry for the tag.
How would you make it so you can add a group?
Please help me.
Hey kyle! Please don't tag staff members.
If I’m not entirely mistaken, there’s an example for that
I can't see one.
In essence you need to add the group node
Never mind.
Is it Modifying user/group data?
Told you
Oh. I misread
My bad
In any case you need to add the group node
And there’s a node builder for that
Where?
Please tell me where..
Then this is the wrong place to start
Minecraft plugins are not suitable for beginners
I need to add A group
and then remove Z group without no lagg.
and? I don't even know Java but I know that reading the documentation is important before asking questions
Especially when using external APIs
@upper blaze do you understand any of this?
one of my devs
he struggling with the API as you just say reAd TRhe WiKi
Sounds like you need a better understanding of Java, not the LuckPerms API
And then there are also the super useful javadocs
Turbo I just need help and an example.
I know docs are here for a reason
I've been trying for hours no with no luck.
Then read them
fSJKBFDSJHNFQDJMK,LMSFNKJGFPHDFGJKL
The thing is even if I wanted to provide an example or more details, I can’t
I’m on my phone in bed
protected void execute(Event e) {
Optional<LuckPermsApi> api = LuckPerms.getApiSafe();
for (Group g : api.get().getGroups()) {
if (g.getName().equals(group.getSingle(e))) {
api.get().getStorage().deleteGroup(g).thenAcceptAsync(wasSuccessful -> {
if (!wasSuccessful) {
return;
}
api.get().getStorage().loadAllGroups();
}, api.get().getStorage().getAsyncExecutor());
break;
}
}
}
what would that do?
And I know I figured that stuff out easily with the wiki and javadocs
I literally need
Remove group
and then add group.
hey
%luckperms_groups% have placeholder
but
%luckperms_groups_prefix%
😦
no
no have
&7[&aDefault&7] &7[&aSilver1&7] nickname: hi
sample
please
use the #support-1 channel please
okey sorry
@proud crypt I'm still having issues, man please give me the way to do it.
Hey kyle! Please don't tag staff members.
I already told you I don't know Java, so I can't.
😦
I can get the meta value via this function, but how would I get the expiry time?
http://prntscr.com/nb9sx4
how do i add/remove groups from the player ?
I dunno if this is just a stupid question... but how do you "load" the api?
Check If plugin is loaded If not send message if it is use that bit of code
I'm not working quite much with Plugins, but I think this could work:
public void onEnable() {
if(Bukkit.getServer().getPluginManager().isPluginEnabled("LuckPerms")) {
// do stuff
}
}
Did you mark LuckPerms as a dependency in your plugin.yml?
does LP fully support SubjectCollections besides users and groups? I'm wanting a separate collection to store a town's permission groups in
I can create alternative collections and subjects through the sponge permissions service, but it won't let me add the subjects as a user's parent
sorry for late reply @midnight wren i have the chat muted so didnt see your messageJAVA if (getServer().getPluginManager().isPluginEnabled("LuckPerms")) { LuckPermsApi api = LuckPerms.getApi(); } else { getLogger().info("LuckPerms was not found."); getLogger().info("API will not be used."); }
yes
Thank you SO much
np
How do you get a user's group?
String group = plugin.lapi.getUser(p.getName()).getPrimaryGroup();
that's sending me a nullpointexception
NPEs are caused by the assumption that something isn't null
We can't really say from a singular line of code, pretty much anything could be null there, but methods like getUser should generally always be checked for a null return
My guess that either plugin or plugin.lapi is null
The rest shouldn’t be null ever
It's the getPrimaryGroup() that's causing the error
The plugin and lapi are variables
lapi is for LuckPermsAPI
and plugin is the instance to my main class where I have a few other functions stored that I use
Do I have to check to make sure it isn't null?
Like to make sure the player actually has a group?
How do I add or remove a user's parent groups?
nvm figured it out
Hey MrIvanPlays! Please don't tag staff members.
i looked and found nothing
Using the api you set or unset the permission node group.RANKNAME
then luckpermsapi.getusermamaner.save(user);
@fierce dew
Which Luckperm version I need for Minecraft 1.12.2?
The normal one?
Yes
I mean the normal one should just work fine
I can't open the online editor
How do I change the "permissions message", (ex. you dont have the permission blah blah..... missing -mutliverse.tp to you dont have that permission.)?
that would be up to the plugin that throws that error
luckperms doesn't tell users the permissions they are lacking.
oh it does not
unless you are using verbose mode.
dont think so
There is a normal vanilla message in spigot.yml or the plugin specified one
commands:
some-command:
permission-message: No perm
permission: some.perm
This can be used in plugin.yml or a simply
if(Player.hasPermissiin("some.perm")) {
// do stuff
} else {
Player.sendMessage("No perm");
}
It’s always the plugin itself that sends the lacking permissions message
I’ve yet to see a single exception
You may be able to set a no-permission message in the config of the plugin, but not all plugins have to support this
ah okay, well thanks for the fast support!
You’re welcome
I know I'm a little bit late, but why was this even asked in #luckperms-api?
in case of multiverse, it looks like the 'no permission' prompts are hard coded and not configurable.
hello
can anyone help me with luckperms?
i need to connect this two queries:
SELECT
username,
FROM_UNIXTIME(lastlogin/1000)
FROM
`accounts`
WHERE
FROM_UNIXTIME(lastlogin/1000) < NOW() - INTERVAL 1 MONTH
and
SELECT count(*)
FROM
`luckperms_players` as player,
`luckperms_user_permissions` as perm
WHERE
`username` = '{PLAYER}' AND
`player`.`uuid` = `perm`.`uuid` AND
`perm`.`permission` != 'group.default' AND
`perm`.`permission` LIKE 'group.%';
i want to delete accounts where lastlogin is greater than 30 days
and player doesn't have any group
@nocturne elbow use api it's there for reason
Hey,
I wanted to make my own BungeeCord Command and wanted to do the command / ranginfo for users where the player can see how long his rank is. Is that possible? (I do not mean the / lp user <name> info Commad)
Yes
You can pretty much get all info from the API
There’s a section on the API in the wiki
@pliant ocean
Using the API is not meant for programming beginners
And neither is plugin programming
It's not that it's not meant for beginners - everyone has to start somewhere :p
It's more just that you're not going to learn how to do things yourself by just asking other people to write the code for you 😉
People have to start from somewhere :p
Indeeeed
And Minecraft plugins and mods proof to be a terrible choice for (absolute) programming beginners every time
You really need a solid grasp of the language and programming itself to not get stuck on literally everything when making plugins or mods
Very true
Figure out how the console works, then play around with things like basic math or maybe random numbers if you're feeling up for a challenge. But game design is not the place to start.
We run into people all the time in a general C# community I'm in that have no coding experience at all but decide that developing a game in Unity is definitely the best way to learn how to code.
You say that, but I was that beginner once
I imagine there's still logs of me not knowing what a field was in Forge's IRC from many years ago
Also somehow I completely missed Luck's first message that was 90% the same as what I posted shh I can read
Never said it can’t be done. Just that it’s by far not the best place to get started @gilded bane
Have you the methode to do this? -> I wanted to make my own BungeeCord Command and wanted to do the command / ranginfo for users where the player can see how long his rank is. Is that possible? (I do not mean the / lp user <name> info Commad)
I might sit down with Helper and come up with a plugin that lets people develop their own commands through a text file. Make it a bit more flexible than Bukkit's commands.yml (and x-plat). Probably just some sort of macro-like system which allows you to define commands, typed strongly named arguments, and a few method-like commands. I may format it something similar to how appveyor does their script files https://github.com/LuzFaltex/docs/blob/master/appveyor.yml
Unless you guys think that's not a good idea. ¯_(ツ)_/¯
Currently I'm using lpUser.hasPermission(permissionNode).asBoolean();
and it doesnt seem like it takes into account inheritance
am I doing this wrong?
@fallow grotto if you're just doing a permission check, use the platform's permission methods
And the Javadocs should tell you if it does or doesn't
Then refer to the Javadocs
you want inheritsPermission()
is there an event that I can listen for when someone's groups/permissions change?
Foxtrek: I mean, there's already projects like helper-js, Denizen and Skript
What you're describing sounds closest to Denizen to me, though I found Denizen is pretty hard to understand
How do we use the bungeecord version of this plugin?
@primal eagle API wise or just normally?
hey can i get the patreon tag :3
also is there a way to get a player's player permissions (not group)
You caaan!
Thanks for contributing 😃
There is a way, what were you trying to accomplish though?
check if a player has a specific player permission, and if so, give an item & revoke perm
and np, glad to support this amazing project 😃
You can use user.hasPermission for that
If it’s a LP user that should only check directly assigned permissions
tyvm
How do I obtain the metadata?
Get nodes for a user and apply a stream filter for Node::isMetaNode
Whats wrong with this?
It does not apply the perm at all
http://prntscr.com/ngrrv9
it works when applying to a user though
Nevermind, used the wrong setExpiry overload
```java
// Your code here
Some.Java.method(argument);
```
// Your code here
Some.Java.method(argument):
any help?
@eager lark https://github.com/lucko/LuckPerms/wiki/Developer-API:-Usage#obtaining-a-grouptrack-instance
When in doubt, RTFM. It may be from a bungee server, but that group is cached in the local server's memory, so the methodology for retrieving the value doesn't change.
how do i make it so people are automatically in default group?
@heady valley people automatically end up the group called default. And for more possibilities, read this page:
!default
@crystal sonnet im having trouble with perm working with slashwarp
Hey cOOM! Please don't tag staff members.
@hollow grotto i would get primary group of lp
Have you tried the link I sent you?
I sent link to dev, im not a dev
The plugin is TAB reborn
And if it on bungee dont return lp primary group if player have a server context
On that same page there's an entire section talking about context.
And how to work with it within the context of the API.
he would like to know the method, I believe he has already read it
I don't know off the top of my head.
That said, if he has questions about the API, bring him in. We may be able to help him better if we're not communicating through a proxy.
oh ok
String group = ChatHandlers.api.getUserSafe(player.getUniqueId()).get().getPrimaryGroup().toUpperCase();
I can't getUser as getOfflinePlayer() ?
@stray dock you need to load offline players
The wiki has an example on how to do that
Hello, I'm writing my own permission manager and I'd like to use LuckPerms' API for this purpose, but for only adding permissions to players. Since LuckPerms doesn't work if the server is in offline mode I can't use the API either. So is there any way to use the API's permission manager functions in offline mode?
@vagrant rose lp works on offline mode servers but i don't think you can do that
That's sad, but thanks for the reply.
@vagrant rose I don’t see a reason why you wouldn’t be able to do that in offline mode
Because I can't join to the server if the plugin is loaded and if the plugin isn't loaded then my plugin can't use the API
Well if you’re using Craftbukkit, then offline mode doesn’t work
In fact that should be in the join message
It works fine with Spigot @vagrant rose
I will give it a try, but I had some trouble with Spigot last time, this is why I still using CraftBukkit
And if there really wasn’t an error message telling you to use Spigot if you want to use offline mode, then I’d be quite surprised tbh
As that would mean you have a very old version of LP
I got the message, but I just wanted to know that is it possible with CraftBukkit offline mode
I switched to spigot and everything looks fine
Think about it
If there is a message explicitly telling you, you need x to be able to y, what on earth makes you think it’s possible to do it without it?
Because the AsyncPlayerJoinEvent was the problem I tought that there is a way to ignore this and only use the working part. Now the permissions works with Spigot and LP but the command auto complete doesn't. What can I do to fix it? The player has the permission but the command is red when typing and auto complete doesn't show some command.
Is the latest version LuckPerms compatible with 1.14?
Possibly? I read 1.13 was supposed to have some big changes in how mods were supposed to attach so version upgrades would have less of an impact, though that was on Sponge's side. Idk what Bukkit is doing.
Sponge for 1.13 and 1.14 isn't even out yet, so you can't run LuckPerms on Sponge on those versions
From what I've heard, LP runs as-is on Bukkit/Spigot
Ok that's true
I tried to use commodore(lucko's brigadier library). but, it does not work (tab complete not shown).
SourceCode: https://github.com/ken-kentan/CommodoreTest
Jar: https://github.com/ken-kentan/CommodoreTest/releases
Can anybody help me😭 ?
It should work, i don't see something wrong in code
@teal tartan I add screenshot. https://github.com/ken-kentan/CommodoreTest/issues/1
Hey together 😃 I have a question: Is it possible to stop or pause the time from a temp permission?
Thanks for help 😃
Hi everyone, I have got a question: How can I set the user prefix with the api?
Try:
Node prefix = api.getNodeFactory().makePrefixNode(100, "[Some Prefix]").build();
user.setPermission(prefix);
i'll try
and how can I check if the user has the prefix now?
cause I want to check if it works with my nick system
[16:17:38 INFO]: [LP] - Prefix: None
[16:17:38 INFO]: [LP] - Suffix: None
uhm
@verbal terrace ?
Have you saved the user?
"api.getUserManager().saveUser(user);"
After add or remove somthing you must save the changes
Ja spreche ich ^^
danke 😄
Kein Problem. da muss man auch erstmal richtig durchblicken ^^
ja xD
Can someone help me? How can i pause the time from a temp permission?
No real way
As the permission saves the end time
So my best idea would be to constantly push the end time back
Like once every second
@verbal terrace
Or once hour push it for hour 😉
Depends on how long the freeze will be
But in any case, you’ll need to push the end timestamp further
Ok thank you 😃
Heyy, I am using the API for changing a suffix.
But when a player logs off & on it disappears.
p.sendMessage(chatutils.format("&8[&4Supreme&8] &7Je hebt succesvol de tag " + tagname + " &7geselecteerd!"));
playerUser.clearMatching(n -> n.isSuffix() && n.getSuffix().getKey() == 50);
playerUser.setPermission(prefix);
api.getUserManager().saveUser(playerUser);
p.closeInventory();
This is what I got rn.
How are you getting the playerUser?
LuckPermsApi api = LuckPerms.getApi();
User playerUser = api.getUser(p.getUniqueId());
That’s odd. What LP Version? @grim echo
Its for 1.7
But I already found it. There is nothing wrong with the code.
The server is hosting the database in NA. So its to slow.
Ok
And well, that doesn’t answer the which LP question
Funnily enough I was gonna suggest to see if normal commands work
4.3.39 bukkit legacy is the one we are using.
You really could update. That’s half a year old
Quick question, so I handle permissions in my plugin via Vault. Some users are getting an issue with it running sync. Is there something I need to do special for luck perms to tell it to run async?
@grim echo well since the issue is a slow database, I’d say no
But there are several other improvements and fixes
@dull rover LuckPerms does everything async. But when you change something through the vault API while you’re in a sync context, it’ll block your current thread. As the Vault API demands that methods wait until doing the change is finished
That’s why you need to make the calls async.
Is there a list of groups obtainable? Trying to do a for loop with for (String g : lp.groups)
Pretty sure there’s a list
Yeah I figured so I should be able to just run it via TaskChain async and have no issues.
It gives me an error when I created the set @teal tartan
Hm?
It wants me to remove the set in the ()
You can use set in for
When I’m doing List<Group> list = ArrayList<Group>(Set) wants me to remove the (set) and replace with ()
You can use Set in for loop you don't need that
Getting a weird issue
i’m giving a player a permission in first join, and it works
but when i do /lp user (username) permission info
it says the player has no permissions and the perm gets deleted
Do you save the player after adding the permission?
how to use commondore?
Did you check the Javadocs?
where ? @crystal sonnet
Hey MrIvanPlays! Please don't tag staff members.
@frank drift stfu
Then I think it's time you learn how to add a library to your project so your IDE has the source and Javadocs
I personally would recommend gradle
Though I've heard people saying maven is easier
i hate gradle
In any case use maven then to include the library and make sure your IDE pulls sources and javadocs
how do i check on what argument i am ?
for example i need that on argument 2 on the command
i have the others made already via the bukkit tab completion for example
@crystal sonnet
Hey MrIvanPlays! Please don't tag staff members.
I know nothing about that library
Hey MarinusX! Please don't tag staff members.
Hey, how can I get all groups that are active on the server? Api.getGroupManager.getLoadedGroups doesn’t work...
What do you even mean by that?
So you want all groups?
yep
Did you check the other methods of group manager?
The Javadocs are typically pretty helpful
I checked...
I think you will have to load all groups first
Groups are loaded by default
And even if not, there’s a way to get all existing groups
Okay? may I get that way?
Is there a way to get all of a player's groups, in https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/me/lucko/luckperms/api/User.java there is only get primary
From a quick glance, you could iterate over all groups then check which ones user inherits?
@zenith linden did you check the wiki? There are plenty of usage examples
Hi there.
I used to use Vault to interact with LuckPerms' API but I figured it's time to just fully integrate with LuckPerms (this is a private plugin so there's no worry about compatibility)
I used to use vaultChat.getPlayerPrefix(player) to get a players prefix. I took a peek at LuckPerms' API usage and I just wanted to doublecheck that this is the correct way to get a prefix.
main.getLuckPermsApi().getUserManager().getUser(player.getUniqueId()).getCachedData().getMetaData(Contexts.allowAll()).getMeta().getOrDefault("prefix", "ERROR")
Or should I just use main.getLuckPermsApi().getUserManager().getUser(player.getUniqueId()).getCachedData().getMetaData(Contexts.allowAll()).getPrefix()?
@bright tapir I’d recommend you read the code InsideIntel posted
And the wiki has good examples too
Isn't that basically what I'm doing but with more variables?
Or is there something I'm missing..
The major difference is that he gets the players contexts
Which means per server groups and and prefixes are considered correctly
anyone knwo how to use User Track Event api barely says anything
The Javadocs explain it fairly well iirc
Sorry thats what I meant, the docs dont show any examples or anything
Okay, hi there.
public static String getPlayerPrefix(Player player) {
Contexts contexts = luckPermsApi.getContextManager().getApplicableContexts(player);
return luckPermsApi.getUserManager().getUser(player.getUniqueId()).getCachedData().getMetaData(contexts).getPrefix();
}
I'm using this little snippet of code to get a player's prefix, but for some reason it's throwing a nullpointerexception.
IntelliJ seems to be saying that getCachedData could produce the nullpointerexception, so I'm wondering how to avoid this.
Do I have to load the user first?
Or check if the user is null and then getCachedData()?
If a method can return null, there really isn't a way to prevent that
Only thing you can do is error handling
Or checking if it returns null
Also you should get the user instance first, and use it in getApplicableContexts instead of the player
@bright tapir
Thanks for the ping, wasn't sure if anyone responded
getApplicableContexts takes in an Object so it might implicitly need to to take in a User and not a Player, or else it'll error?
That's probably why it wasn't saying anything was wrong.
@crystal sonnet is this looking a bit better:
public static String getPlayerPrefix(Player player) {
User user = luckPermsApi.getUserManager().getUser(player.getUniqueId());
Contexts contexts = luckPermsApi.getContextManager().getApplicableContexts(user);
return user.getCachedData().getMetaData(contexts).getPrefix();
}
Hey TehBrian! Please don't tag staff members.
Sorry ;/
I'm pretty sure it would've worked that way
But doing that is more efficient and safer
Okay I'll try that.
And your IDE can't do code analysis that deep
I'm going to bet it's going to work now, it probably just needed user passed in rather than player.
As I said, I think it would've worked either way
Hmm, here's to hoping.
Before it was just throwing NullPointerExceptions so I guess we'll see.
Throwing.
Ok. Then yeah
Like, I'd get an error in my console and my entire Event wouldn't work (it's for playerchat event.)
Said, exception NullPointerException occurred and gave me a stack trace.
Yeah
Restarting server now, here's to hoping.
It's still not working.
It's giving a different exception now! Which is good!
public static String getPlayerPrefix(Player player) {
User user = luckPermsApi.getUserManager().getUser(player.getUniqueId());
Contexts contexts = luckPermsApi.getContextManager().getApplicableContexts(user);
return user.getCachedData().getMetaData(contexts).getPrefix();
}
``` using this code, I'm getting this stack trace:
oh..
I think I need to use a player..
Which is line 19?
The line where I get contexts from.
And that's the line we just changed from player to user.
So it needs to be a player, but a player returns a nullpointerexception.
Where does it throw the NPE?
If you don't know, store the return value of each function in a variable
That's my chat event handler.
If I replace LuckPermsUtils.getPlayerPrefix(player) and the suffix variant aswell, to say, "Prefix" and "Suffix", it works fine.
Of course it literally shows up in chat as "Prefix" and "Suffix" but that just shows it's not a problem with that.
.. seems to just be inside the getPlayerPrefix/Suffix methods, but the methods are doing everything that the Usage in the Wiki seems to say..
Seems to say to give it a Player not a User so I suppose I'll put that back to player..
And then combining that with this..
it seems like I'm doing everything perfectly by the book
it just won't work
I'm going to take a further peek into getCachedData, that seems to be the best bet.
This is infuriating.
OK I've devised a little test, it's possible that we're getting a null user somehow.
It's
so the user isn't null??
Try using the debugger to step through the code to find out what throws null
Alternatively print out every return value of every method
I'm going to try that.
Alright first I'm trying this:
public static String getPlayerPrefix(Player player) {
User user = luckPermsApi.getUserManager().getUser(player.getUniqueId());
Contexts contexts = luckPermsApi.getContextManager().getApplicableContexts(player);
if (user == null) {
return "User was null.";
}
MetaData metaData = user.getCachedData().getMetaData(contexts);
return metaData.getPrefix();
}
Being used by this:
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (player.hasPermission("tfcplugin.chatcolor")) {
event.setMessage(MiscUtils.color(event.getMessage()));
}
event.setFormat(MiscUtils.color(main.getConfig().getString("chat_format")
.replace("{prefix}", LuckPermsUtils.getPlayerPrefix(player))
.replace("{suffix}", LuckPermsUtils.getPlayerSuffix(player))));
}
I know that EventHandler works with regular strings.
Is it possible that getPrefix() is returning null?
Alright, using that, I'm getting this stacktrace:
I'm going to try with this event now:
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (player.hasPermission("tfcplugin.chatcolor")) {
event.setMessage(MiscUtils.color(event.getMessage()));
}
event.setFormat(MiscUtils.color(main.getConfig().getString("chat_format")
.replace("{prefix}", LuckPermsUtils.getPlayerPrefix(player) == null ? "NOLL" : LuckPermsUtils.getPlayerPrefix(player))
.replace("{suffix}", LuckPermsUtils.getPlayerSuffix(player) == null ? "NULE" : LuckPermsUtils.getPlayerSuffix(player))));
}
Simple difference, hopefully I get NOLL TehBrianNULE in chat.
And based on the stack trace, I'm going to HIGHLY guess that it's just returning null. Let's see.
OH
I GOT IT
That's so simple.
Prefix was working fine, it's just since I don't have a suffix, it's returning null.
I feel so silly now, that makes sense.
Simple fix:
return metaData.getPrefix() == null ? "" : metaData.getPrefix();
instead of
return metaData.getPrefix();
Do the same thing with suffix counterpart and there you go.
Alright. Thanks a bunch haha. Perhaps on the wiki there should be "Note: Will return null if the player doesn't have one." or something like that.
That's to be assumed
nothing = null
And I'm pretty sure the Javadocs say so too
Huh.
Mainly just for people coming from Vault.
With Vault it just returns an empty string.
Well, there's you're issue. You've committed one of the deadly sins of programming:
Because API x does y, I'm assuming API y does so too
Especially atrocious when applied to different (but similar (sounding)) programming languages
Yeah, issue, I suppose.
okay I had a question about the plugin luck perms how would I get it to work on 1.7.10 if It's not loading into the server what version do I need??
Okay thanks
@bright tapir glad you worked it out eventually! :p
just a small pointer for future reference - you're likely to be able to apply this to other projects too
All of the API methods are annotated with @Nullable and @NonNull labels
These show up in the source code, and also in the javadocs
Nullable means a method could return null, NonNull means it never will
your IDE, if it's smart enough, should warn you about it too 😉
Oh I've seen those around, I've never really thought to look into them much. That makes a lot of sense haha.
Thanks a bunch! :)
this is what I mean about your IDE warning you
:p
pretty neat
it detects that getPrefix might return null, so realises that could throw an NPE
has saved me many times 😃
Oh, that makes so much sense. I was looking at that and thinking that, in your example, it was saying that because .length() itself could return null.
I just need to look at what it's referring to instead. Nonnull and Nullable make a lot more sense now, thank you so much haha.
cool! no worries 😃
So The legacy link for 1.7.10 dose not work or load
okay I had a question about the plugin luck perms how would I get it to work on 1.7.10 if It's not loading into the server what version do I need?? The Link too 4.4.19 does not work and legacy 4.4.21 will not load
Hey guys, so in my plugin I'm setting the player's primary group but when i check the player's info it says that their primary group is the same then i try to change it by command and it says that their group is already what i tried to change it to? the prefix stays the same throughout
@lyric solstice I’ve asked you before and I will again. Please check the startup logs for errors
And send them here
And you want 4.4.21
@lyric solstice also this belongs in #support-1
can someone help me set luckyperms up?
Okay
Explain ur problem.
hey guys, would https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/me/lucko/luckperms/api/event/player/PlayerDataSaveEvent.java be called after a palyer's rank is changed?
Yes
However this is probably more appropriate
Node cooldown = LuckpermsBridge.getPermission().getNodeFactory().newBuilder(permissionString).setNegated(negated).setServer("gta").setExpiry(length, TimeUnit.MINUTES).build();
Group group = permission.getGroup("il");
group.setPermission(cooldown);
LuckpermsBridge.getPermission().getGroupManager().saveGroup(group);
group.refreshCachedData();
}```
Using this code to set temp perms. I have a mysql backend. The perm shows up in the db instanntly, but a Vault perm check only "registers" the perms after /lp sync. Any ideas? Didnt have the problem with yaml backend
[03:20:54 INFO]: [LP] - Platform: Bukkit
[03:20:54 INFO]: [LP] - Server Brand: Paper
[03:20:54 INFO]: [LP] - Server Version:
[03:20:54 INFO]: [LP] - git-Paper-624 (MC: 1.13.2) - 1.13.2-R0.1-SNAPSHOT
[03:20:54 INFO]: [LP] - Storage:
[03:20:54 INFO]: [LP] - Type: MariaDB
[03:20:54 INFO]: [LP] - Ping: 16ms
[03:20:54 INFO]: [LP] - Connected: true
[03:20:54 INFO]: [LP] - Messaging: Redis
[03:20:54 INFO]: [LP] - Instance:
[03:20:54 INFO]: [LP] - Static contexts: server=gta
[03:20:54 INFO]: [LP] - Online Players: 1 (1 unique)
[03:20:54 INFO]: [LP] - Uptime: 10m 5s
[03:20:54 INFO]: [LP] - Local Data: 1 users, 15 groups, 0 tracks
Might be also an issue though. But maybe I have to do something special when using remote database + messaging service when using the api
Oh well, happens with yaml aswell, no idea why I didn't catch that before
In Bukkit, the correct way to abort loading your plugin was to return. What is the proper way to do so in Sponge?
@Listener
public void onServerStart(GameStartedServerEvent event) {
lpTools = new LuckPermsTools();
if (!lpTools.GetLuckPermsApi().isPresent())
return;
}```
LuckPermsTools#GetLuckPermsApi just puts the LuckPermsApi instance in a Nullable. The tools class is provided for other things though - it's where I'll stick my methods for interfacing with LuckPerms.
Essentially though, LP is a hard dependency, so I need to abort loading my plugin should LP not be present.
Or is that what the dependencies block of the plugin annotation is for?
@sudden kelp Would you mind creating a GitHub issue for that 😃
Barring the fact that this isn't world- or server-sensitive, does anyone have any problems with the way I'm doing this? Dove into CompletableFutures for the first time today.
@Override
public CompletableFuture<String> getMeta(UUID uuid, String key) {
if (_tools.GetLuckPermsApi().isPresent()) {
LuckPermsApi api = _tools.GetLuckPermsApi().get();
return api.getUserManager().loadUser(uuid)
.thenApplyAsync(user -> user.getOwnNodes().stream()
.filter(Node::isMeta)
.filter(n -> n.getMeta().getKey().equals(key))
.collect(Collectors.toList())
.get(0))
.thenApplyAsync(Node::getMeta)
.thenApplyAsync(Map.Entry::getValue);
} else return CompletableFuture.completedFuture("");
}```
On my to-do list for now is to change the key comparison to be case-insensitive, but otherwise I'm pretty happy with it.
I can then call it like this:
CompletableFuture<String> titleFuture =
luckPermsService.getMeta(player.getUniqueId(), SelectedTitle);```
SelectedTitle is a const string with a value of "selectedtitle", the name of the meta key for this item.
Er, const being a C# keyword roughly analogous to static final
Is it possible to get all users in a group including offline ones?
Yup! Though I don't know whether you'll want to get all users and get a stream going that filters by group membership or if you can get a list by getting a handle on the group and asking it for its members.
And I don't have an IDE open currently to poke at it.
The way to do it is by loading all players and checking if they are in the group you want
return player.hasPermission("group." + group);
}```
This doesn't work for me :c
I already checked that but It doesn't work.
Like I don't have any result
But the group exists. And my player has it in parent groups
So always false?
And keep in mind that way of checking for a player being in a group ownership is a LP only thing
Okay, and there is no method to get all groups of a player?
You have to use the API directly
Which method?
Get all permission nodes a player has and check if they are group nodes
Alright ty 😃
Just ask your question @delicate wren
How do I make it so all players on my server can use the plug ins? So far only OPs can use them and not people that don't have OP
@delicate wren #support-1
hey hal luckperms eine placeholder api z.b. das ich mir den rang namen anzeigen lassen kann z.b. auf nem scoreboad
Ja
wo finde ich eine liste der placeholder apis?
In deren Liste der Erweiterungen
kannst du mir nen link schicken? pls
Nein, weil
a) ich bin nicht dein Link Buttler
b) ich bin mir ziemlich sicher Google funktioniert auch für dich
c) Ich benutze PAPI nicht, weiß somit nicht, wo die Dokumentationen liegen
ok sorry das ich frage
Das hat nichts mit Fragen an sich zu tun. Sondern eher mit einer Erwartungshaltung und eigener Faulheit.
Und außerdem sollte der Server-Admin in der Lage sein Plugin-Dokumentationen zu finden und zu verstehen können
I wanted to know if its possible to get the users in like a list from a group name but not getting every single user on the server and checking if they have the group.groupname permission. The server I'm on has a bunch of unique users
Alright, thanks
hi anyone knows how to install tool Main items in version 1.8.8?
Screaming, probably.
Hi, is there an event for the changes of an player's nodes? (Also Offlineplayers)
Mention me 😉
There’s is an event for when nodes change @wispy harness
Hey iFlyinq! Please don't tag staff members.
Hey
Kann wer mir helfen wenn ich die LuckPermsAPI nutzen will geht sie net (will es mit meaven machen) kann wer mir die pom.xml schicken ?
?
Sollte im Wiki sein, lass mich mal nachschauen
https://github.com/lucko/LuckPerms/wiki/Developer-API#maven, yup, hier is es
How can I check if a user is in a specific group?
is it literally just the permission group.GROUP
@sick elbow yes
@clever plank Tobi hat dir den Link gegeben
/lp is not working for my 3.0.14 vershen
they only work in console
i did the thing to give me all perms
every time i do a /lp it tells me running luckperms v 3.0.14
do /lp help
This shouldn't be in the API channel btw. Use #support-1 please
eine eine frage ich kann die api net nutzen xD
ist egal xD
Polish helppp
Hat sich erledigt
Hi, I'm trying to use the API to read out how long a player has a particular group that has been set with "addtemp". Does anyone happen to have an example?
I don’t think you can
The players should be able to read it out via ingame command /ranginfo
also yes the remaining time
Then you need to track that part yourself
Why isn't this working? ```Java
public EventBusListener(LuckPermsApi api) {
EventBus eventBus = api.getEventBus();
eventBus.subscribe(NodeMutateEvent.class, (e) -> {
System.out.println("Event triggered, NodeMutateEvent");
System.out.println(e.getTarget().getFriendlyName());
});
}```
When i do /lp user [player] parent add [group] it's not triggering (Bungee)
Are you getting any errors during startup?
Also make sure the object doesn't get destroyed/gc'ed
Not working and no errors & not garbage collected.
Have you doubled check that the subscribe method is called?
Using LocalizedNode#getPrefix returns an Entry<Integer, String>. The String is clearly the text of the prefix, but what does the Integer represent?
Probably the priority
That's what I would guess, but I thought I'd triple check.
Did you check the Javadocs of the method?
...that would be a good idea, wouldn't it?
I mean I certainly don’t know for sure.
And Javadocs exist for a reason
Always a good idea to make sure the IDE has them included
So the wiki says it's the weight. I'll hang onto those.
Or the source. So it can show the docs in the tooltips
And normally they are, but IntelliJ isn't happy with me currently and isn't showing any of the javadocs.
That’s something you should fix
Yeah, I'll knock that out now. Just got this method finished that's been a headache for a bit.
@Override
public CompletableFuture<List<Map.Entry<Integer, String>>> getUserEvaluatedPrefixes(UUID uuid, Contexts contexts) {
if (_tools.getLuckPermsApi().isPresent()) {
LuckPermsApi api = _tools.getLuckPermsApi().get();
return api.getUserManager().loadUser(uuid)
.thenApplyAsync(user -> user.getAllNodes(contexts).stream()
.filter(Node::isPrefix)
.map(Node::getPrefix)
.collect(Collectors.toList()));
} else return CompletableFuture.completedFuture(Collections.EMPTY_LIST);
}```
I assume Collections.EMPTY_LIST does some compiler magic to find the type of list... I hope
Reee
api.getUserManager.loadUser(uuid); // CompletableFuture<User>
api.getGroupManager.loadGroup(groupName); // CompletableFuture<Optional<Group>>```
This code seem sane enough?
@Override
public CompletableFuture<String> getGroupPrefix(String groupName) {
if (_tools.getLuckPermsApi().isPresent()) {
LuckPermsApi api = _tools.getLuckPermsApi().get();
return api.getGroupManager().loadGroup(groupName)
.thenApplyAsync(group -> {
if (group.isPresent()) {
Group g = group.get();
return g.getOwnNodes().stream()
.filter(Node::isPrefix)
.collect(Collectors.toList())
.get(0);
} else {
return api.getNodeFactory().makePrefixNode(0, "").build();
}
})
.thenApplyAsync(Node::getPrefix)
.thenApplyAsync(Map.Entry::getValue);
} else return CompletableFuture.completedFuture("");
}```
@hollow grotto isn't there also Vault? to collect the prefix from?
Idk I don't really dev but my dev guy said something along those lines
This is a Sponge plugin. Sponge might have a way to get user prefixes, but groups are an unknown concept to Sponge that LP owns.
Ah fair enough
Is there a limit to the amount of text that I can store in a meta node? My plan is to serialize a List<Entry<Integer, String>> into json and store that under a meta node.
Actually, let me re-think this. If this were a static list, this would be easy to deal with, but it's dynamic. I may need to approach this from a different angle.
@hollow grotto the limit depends on the storage type
I'm using the default h2 database. But what I've decided to do instead is since the integer part of that entry represents a unique id, it'd be much easier just to use a database of my own and just set up a key column that automatically generates itself.
Then I can just rely on the database to keep track of those details and I don't have to code it myself.
I'm working with a SQLite database to store titles for a Minecraft server. Titles are a cosmetic chat feature which shows up before the person's name, like so: [Title] Name: Hello World!
Titles, at their most basic level, have two properties: a unique id and the text of the title. This is pretty easy - just an integer key field that auto-increments and a string value.
This is where it gets a bit more complicated though. Not all titles are available to everyone. This falls under two conditions:
- Titles owned by the player (e.g. players can donate to get custom titles)
- Titles owned by a group (e.g. staff members playing as DMs can have special titles for gods, etc.)
To complicate things further, players are stored using a unique Guid but groups are stored by a name.
What's the best way to handle keeping track of ownership? I figure there are two options for this, but I'm interested to see if you guys have any ideas.
+---------------+---------------+---------------+------------------------+
| Id (key, int) | Text (string) | Type (string) | Owner (string) |
+---------------+---------------+---------------+------------------------+
| 0 | Peasant | Group | some-random-guid-value |
| 1 | Acolyte | Player | Foxtrek_64 |
+---------------+---------------+---------------+------------------------+
+---------------+---------------+
| Id (key, int) | Text (string) |
+---------------+---------------+
| 0 | Peasant |
| 1 | Acolyte |
+---------------+---------------+
+---------------+----------------+
| Id (key, int) | Owner (string) |
+---------------+----------------+
| 1 | Admin |
+---------------+----------------+
+---------------+------------------------+
| Id (key, int) | Owner (Guid) |
+---------------+------------------------+
| 0 | Some-random-guid-value |
+---------------+------------------------+```
The Type column in the first example would be mapped to an enum and would determine how to parse the owner bit.
Another idea would be to create a master table holding all titles (named "Titles") and then create a database for each user and each group, but I could see that becoming unmanageable pretty quickly.
Fortunately though, one saving grace would be that titles would only ever have one owner.
Also, I know I'll catch flak for using sqlite instead of h2, but I need this to interop with C#, and there's no good way to do that with an h2 database.
I ended up going with the separate tables option.
... and now I'm questioning that decision.
I would have 3 tables
Titles: id, prefix
Players: player_guid, title_id, other player data fields.....
Groups: id, title_id, other group data fields
So what I ended up doing was to have a single table:
+---------------+----------------+---------------------+
| Id (key, int) | Title (string) | TitleGroup (string) |
+---------------+----------------+---------------------+
| 0 | Traveler | admin |
| 1 | Merchant | Foxtrek_64 |
+---------------+----------------+---------------------+```
This `TitleGroup` is then mapped to a permission node and the permission node is applied either to the user or the group.
This gives me a common "owner" no matter what the end result is, and it makes it so that the database does not care about the underlying data type of the owner itself.
So my permission node would look something like titles.group.admin or titles.group.foxtrek_64
What should I be returning here instead of CompletableFuture<?>? It feels like I should be explicit in my return type, but thenApplyAsync(user -> user.setPermission(metaNode)); doesn't have a return type.
@Override
public CompletableFuture<?> setUserMeta(UUID uuid, String key, String value) {
if (getLuckPermsApi().isPresent()) {
Node metaNode = api.getNodeFactory().makeMetaNode(key, value).build();
return api.getUserManager().loadUser(uuid)
.thenApplyAsync(user -> user.setPermission(metaNode));
} else return CompletableFuture.completedFuture(null);
}```
And CompletableFuture<null> isn't allowed
Does it have to return a value?
Can you not just use your own method for setting the data, without the override. Sorry not a sponge person
user.setPermission(node) is a void method. .thenApplyAsync gets its return type from the lambda, and with a void lambda, the return type is... ¯_(ツ)_/¯
What do you mean by "without the override?"
[00:51:25 INFO]: Registering EventBus
[00:51:25 INFO]: Done registering EventBus true```
public EventBusListener(LuckPermsApi api) {
System.out.println("Registering EventBus");
EventBus eventBus = api.getEventBus();
boolean isSubscribed = eventBus.subscribe(NodeMutateEvent.class, (e) -> {
System.out.println("Event triggered, NodeMutateEvent");
System.out.println(e.getTarget().getFriendlyName());
}).isActive();
System.out.println("Done registering EventBus " + isSubscribed);
}```
And as said, i'm using bungee maybe its not supported or something idk. (Mention me when you answer)
How do I add a user to a group with the API?
Not the primary group
as in /lp user <user> group add <group>
but programatically
Create a group node with the nodebuilder and apply it to the LP user instance
More info in the lp wiki under usage
First time using the API, any docs anywhere, apart from the brief page on GH?
ah
missed that one
cheers
Node node = api.getNodeFactory().makeGroupNode(x).build();``` what do i put where x is? or am i missing something. first time using the API as well, so learning a lot
That’s the group name @azure latch
In case it’s not the case, make sure your IDE has the API’s Javadocs or Source
it does, thanks
how do i add a group to a player/player to a group?
ive got an instance of a player, i just cant find a way to add a player to a group
Yes
It's under the developer section
Click on that and then more navigation should be expanded/extended
im looking at the usage and cant see anything to do with adding groups. ive looked at modifying group data already
sorry about this, but if you have a second can you link me?
so i would use user.setPermission(thegroupnode)?
Yes
huh ok. thanks. clearly didnt read that right
Using that command from earlier, no group gets assigned to me, and im not in the groups listmembers command. My code for this is here https://hastebin.com/osogokowuf.cs and there are no errors in the console or eclipse. Also, i know the worldguard API isnt the problem since the sendMessage works.
the tabbing on that looks really weird, but in eclipse its perfectly fine
i am so dumb. this is my last one today, i promise
@azure latch code: https://paste.themelvin.nl/LTYYev
im looking
honestly, i have never used this with bungeecord before, but it looks like it could be from around for (ProxiedPlayer players: ProxyServer.getInstance().getPlayers()) { BaseComponent[] mes = TextComponent.fromLegacyText(format); players.sendMessage(mes); to me
but dont take my word for it, look for examples if you can find them, and see if any of the more experienced people will answer
@azure latch what?
not trying to lead extreme unlucky down the completely wrong path, so wanted to see if people like you could help him
his original question is in #support-1
yup
public void PlayerEnterRegion(RegionEnterEvent e) {
LuckPermsApi api = LuckPerms.getApi();
Node node = api.getNodeFactory().makeGroupNode("grinder_game").build();
if (e.getRegion().getId().equals("grinder0")) {
loadUser(e.getPlayer()).setPermission(node);
api.getUserManager().saveUser(e.getPlayer());
e.getPlayer().sendMessage(ChatColor.AQUA +"Welcome to the Grinder Minigame!");
}``` can anyone tell me why .saveUser isnt working? it says it is not acceptable parameters for player
@azure latch you need to pass a User instance
``` will this work? the error highlighting is gone but want to be sure
No
You need to save the instance loadUser(e.getPlayer()) returns in a variable
Though I'm not gonna lie, this isn't programming 101 course here
im completely new to java
never touched it before this morning
i know, but i need this making for my server and thought id give it a shot
If you need Java help, check out the TogetherJava discord
ok
so would User user = loadUser(e.getPlayer()); and api.getUserManager().saveUser((user)); work? sorry to keep bothering you, but id be completely lost with the console errors
Yes
As I said, best to ask for general Java help on TogetherJava
And well best to learn Java before
I hope you have at least some programming experience
i know python very well, but had a mental block when i looked at the syntax
i know
Would anyone find it useful if I genericized this and provided it in a Maven package? https://github.com/Foxtrek64/Titles/blob/master/src/main/java/com/luzfaltex/sponge/titles/services/luckperms/LuckPermsService.java
Actually, that may not work, since these Sponge plugins don't have a base class for their main class. I'd have to provide my own framework for that.
Ah well
Hey. I'm trying to get the prefix of a player while the player is offline, but I'm having trouble doing so.
This is the code:
api.getUserManager().loadUser(pair.getKey().getUniqueId()); // Loads user from Entry key
User luckPlayer = api.getUserManager().getUser(pair.getKey().getUniqueId()); // Get User using Entry key
BungeeLogger.getGlobal().info(luckPlayer.getName()); //This prints out the correct username
Contexts contexts = api.getContextManager().lookupApplicableContexts(luckPlayer).get(); // Error occurs here
MetaData metaData = luckPlayer.getCachedData().getMetaData(contexts);
String prefix = metaData.getPrefix();```
This is the error:
```15:06:04 [WARNING] Error in dispatching command
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at commands.social.Friends.execute(Friends.java:77)
How do I solve this?
Nevermind I solved it (using deprecated methods unfortunately)
@dreamy jasper Take a look at the link I sent above.
Or just this block:
@Override
public CompletableFuture<String> getUserPrefix(UUID uuid) {
if (getLuckPermsApi().isPresent()) {
return api.getUserManager().loadUser(uuid)
.thenApplyAsync(user -> user.getOwnNodes().stream()
.filter(Node::isPrefix)
.collect(Collectors.toList())
.get(0))
.thenApplyAsync(Node::getPrefix)
.thenApplyAsync(Map.Entry::getValue);
} else return CompletableFuture.completedFuture("");
}```
You should avoid developing new code using deprecated methods.
The code sample there works using up-to-date code
The server is 1.8 Bungee and won't be moving from that, so if the deprecated method works right now, it'll be fine for use
As I don't have plans to run anything higher than 1.8
Fair. Still poor practice.
I know, but in my eyes, if it works, why bother replacing it?
"Deprecated" is another way of saying "not maintained." Should you run into any issues with the code later, any dev worth his salt will tell you to update the code to the current standard.
Also, in the event that things go against your plan and you end up needing it on later versions, the old code may not have a comparable version in the new API, causing you to need to rewrite that code anyways.
Generally, you should only use deprecated code when it either already exists or there is no code available that you should be using instead (though I would argue that in the latter case it shouldn't be deprecated).
Up to you though, really. It's your code.
Is there a simpler way of doing it without using that giant block of code you sent?
Or something that is just more readable?
It's really not that bad. The worst part is that it's using a CompletableFuture.
Though that's an API choice, not mine.
And idk, I'd call that pretty legible.
I put in a new line break each time the operation changes so it's clear what's going on.
The code I'm using is much more clearer. However deprecated, it's still easier to tell what is exactly going on
loadUser(uuid).join() might cause the if check to block, depending on how long it takes to retrieve the user. contexts doesn't need to exist, you can just call .getMetaData(Contexts.allowAll()); Beyond those housecleaning changes and the excess of line returns, I'd say that block is mostly okay.
Also, no point in calling .loadUser(uuid).join() if you're not going to do anything with the returned value. It's an expensive operation.
So how else do I get the user?
I need to load it from the storage in case the user is offline
api.getUserManager().loadUser(uuid);
Where api is an instance of LuckPermsApi
My code will retrieve the prefix of the user regardless of whether they're on or offline, and it does it in three lines of code.
Yea but yours is extremely hard to read in my eyes
In my defense, I'm a C# developer, not a Java developer.
Also, I put in those line breaks to make it easier to read.
@Override
public CompletableFuture<String> getUserPrefix(UUID uuid) {
if (getLuckPermsApi().isPresent()) {
return api.getUserManager().loadUser(uuid).thenApplyAsync(user -> user.getOwnNodes().stream().filter(Node::isPrefix).collect(Collectors.toList()).get(0)).thenApplyAsync(Node::getPrefix).thenApplyAsync(Map.Entry::getValue);
} else return CompletableFuture.completedFuture("");
}```
It's still way too much in just one call
That's what it looks like if you put it all in one line
Welcome to CompletableFutures and streaming?
I'm not sure what to tell you there.
If you look at code for professional products like what Google writes, that's exactly how it looks.
Well, the first example, not this abomination.
When you get into reading it, it's not terrible to look at
Will this work?
User metadata is stored as a KeyValuePair in a Map.Entry<K, V>
iow I don't think your method would do much of anything... unless you're trying to get all of their meta items?
@Override
public CompletableFuture<String> getUserMeta(UUID uuid, String key) {
if (getLuckPermsApi().isPresent()) {
return api.getUserManager().loadUser(uuid)
.thenApplyAsync(user -> user.getOwnNodes().stream()
.filter(Node::isMeta)
.filter(n -> n.getMeta().getKey().equals(key))
.collect(Collectors.toList())
.get(0))
.thenApplyAsync(Node::getMeta)
.thenApplyAsync(Map.Entry::getValue);
} else return CompletableFuture.completedFuture("");
}```
Any time you call user.get() or user.join(), you run the risk of blocking.
So you should keep it as a CompletableFuture<String> until the last possible moment.
And then you should pass it off to a threading service.
uh well so far this has been working with no problems
You've been lucky then. Blocking = lag.
The database for luck perms has 4 players in it atm

