#luckperms-api
1 messages · Page 18 of 1
There must be another way that does not involve having one call on 3 different lines.
You're welcome to read the API documentation. If you find a better way, I'm all ears. ¯_(ツ)_/¯
Thanks
My code is based off of the docs
Just looking at your code I have no idea what it's doing.
I'm happy to answer any questions
I need some help
What's up, Venom?
I'm using rankup, and delux menus. I'm trying to make a /titles gui but i have no clue on how to get this to work with luck perms
I'm not quite sure what you're trying to accomplish
To set the prefix basically if they passed a group in that track
They can select something in the menu which will set their prefix to that groups
@hollow grotto 1. What is the key variable? What is that doing? 2. CompletableFuture.completedFuture(""); gives an error.
You'll need a permission node for their prefix. If you can fetch their prefix node, then you can call node.toBuilder().setValue("newPrefix").build() and then apply that user object.
Alternatively, if you want to follow the RBAC guideslines, it's as simple as removing the old group and adding a new one. Once they inherit from the new group, they'll pick up that group's prefix, which is probably the better way to go.
@dreamy jasper The key variable is the key in the Map.Entry<K, V>, where K means Key and V means Value.
Metadata in LP is stored as these KeyValuePairs, where you have a unique key that identifies a certain value. For instance, in my case, I have a key called selectedtitle which maps to an integer for their selected title.
If you want to get a specific metadata value, you find it using its key.
What's the key for a prefix?
Yes the second group does inherit from the default group, i just don't know what command to use and to check if the player has access to that group
Another example is Nucleus has the max-homes meta value, where max-homes is the key and the value is whatever their max homes are set to.
For the prefix, you don't get that as meta. You get that as a prefix. Note the difference between these two lines:
.filter(Node::isPrefix)
.filter(Node::isMeta)```
They're two different types of node
Sorry, i'm really confused.
- '[close]'
- '[console] lp user %player_name% promote standard'```
If you want to see if a player is a member of a group, then use player.hasPermission("group." + group);
I think i'm in the wrong channel
Where group is the group name
If you're using commands, then ye. You'll want this page. https://github.com/lucko/LuckPerms/wiki/Command-Usage:-Parent
Or perhaps this one, if you're using tracks https://github.com/lucko/LuckPerms/wiki/Command-Usage:-User#lp-user-user-promote
If I just want the prefix, do I need the key variable?
I don't see any need for it
No, you do not need a key if you're getting a prefix.
That's for user meta.
@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("");
}```
That's how you get the user prefix.
Note two important lines:
.filter(Node::isPrefix)
.thenApplyAsync(Node::getPrefix)```
the :: block is short hand for node -> node.isPrefix() and node -> node.getPrefix(), respectively.
I don't want them getting access to a title when they haven't ranked up to it yet, I'm using just basic config's from; luck perms, delux menus, and rankup.
I use stream() because I have to get all of the user's permission nodes (in this case, only their own, not those they inherit), and then I have to filter all of those by whether they're a prefix node.
@foggy warren You seem to be doing everything correctly on the LuckPerms end. It's just up to those plugins now.
Yea, just don't know how to check if they have gotten those ranks
/lp user <user> info should list all of the groups they are a member of.
Heres and example of what im trying to do.
So they can activate the title from a previous rank
Yeah, that's outside of the scope of LP
Actually, I'm building a plugin that does exactly that, though without the gui element.
It's for Sponge though-
Yeah the gui is easy. Just dont know how to do the perm stuff though
Like check if they have access to the group, or have access to the "rank"
@hollow grotto Now that this is a CompletableFuture string, how on earth do I use this in sending it as a message to a player?
Use completableFuture.join(), but carefully. It should be done in its own thread, and I'm not entirely certain how to do that yet.
I have an AsyncService that I have set up, but it doesn't do much at this point.
I just want to send the message to a player...
do I really have to do all of this
Just to send a message
Tbch, I wish this system wasn't here either. But Java is years behind on a proper concurrency library.
This is how you'd do it in C#:
public async Task<string> GetUserPrefix(Guid guid)
{
// ?. is effectively wrapping the "is present" check into a single line.
// The code to the right of the . is only executed if it is present
// .Where() and .FirstOrDefault() are part of C#'s LINQ library. This is roughly analogous to Java's stream library.
// Notice how some things are no longer methods? This is because C# has read-only properties.
// ?? is the short-hand null coalescence operator. If the left side is null, it gets the value of the item on the right.
// In this case, it's used to say that "if the api is NOT present, return an empty string"
return luckPermsApi?.GetUserManager().LoadUser(guid) // We have the user handle
.GetOwnNodes() // Get a collection of their nodes
// .Where(x -> x.IsPrefix)[0]
.FirstOrDefault(x -> x.isPrefix) // This returns only one result instead of an entire collection. The "Default" is null
?.Prefix // If it's not null, grab the prefix
?.Value ?? ""; // If the prefix is not null, get its value. Otherwise, if anything is null, return ""
}
// How to actually get the prefix
string prefix = await GetUserPrefix(Player.Guid);
// Alternatively, if you're not in an async method (which gives you the await keyword)
string prefix = GetUserPrefix(Player.Guid).GetAwaiter().GetResult();
The GetUserPrefix function is identical to the Java version with the CompletableFuture in operation. There is an equivalent to the .thenApplyAsync() method in C#, but that belongs to Task. As you can see here, we don't interact with the Task library directly until we get to calling this method. Then we just await it, which automatically handles concurrency and just returns a string.
Can anyone check that code and tell me, if it is correct, or if there is a more "correct" way.
@toxic marlin you need to save the changes
Thx a lot mate, didn't read the developer guide this far
@bold crypt
no, this: https://github.com/lucko/LuckPerms/wiki/Developer-API:-Usage#retrieving-prefixessuffixes
Yes, and a line below is a example on how to retrive Meta data
Yes, but how do I get the MetaData
MetaData metaData = group.getCachedData().getMetaData(contexts);
LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(p.getUniqueId());
ContextManager contextManager = api.getContextManager();
Contexts contexts = contextManager.lookupApplicableContexts(user).orElseGet(contextManager::getStaticContexts);
MetaData metaData = user.getCachedData().getMetaData(contexts);
final String prefix = metaData.getPrefix();
so
but that's not possible
Looks right to me, also write it like
this
this is easier to read, for your case:
```java
<code>
```
< LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(p.getUniqueId());
ContextManager contextManager = api.getContextManager();
Contexts contexts = contextManager.lookupApplicableContexts(user).orElseGet(contextManager::getStaticContexts);
MetaData metaData = user.getCachedData().getMetaData(contexts);
final String prefix = metaData.getPrefix();>
´´´java
LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(p.getUniqueId());
ContextManager contextManager = api.getContextManager();
Contexts contexts = contextManager.lookupApplicableContexts(user).orElseGet(contextManager::getStaticContexts);
MetaData metaData = user.getCachedData().getMetaData(contexts);
final String prefix = metaData.getPrefix();
Other `
Alter, du schreibst
```java
code
```
`
LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(p.getUniqueId());
ContextManager contextManager = api.getContextManager();
Contexts contexts = contextManager.lookupApplicableContexts(user).orElseGet(contextManager::getStaticContexts);
MetaData metaData = user.getCachedData().getMetaData(contexts);
final String prefix = metaData.getPrefix();`
LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(p.getUniqueId());
ContextManager contextManager = api.getContextManager();
Contexts contexts = contextManager.lookupApplicableContexts(user).orElseGet(contextManager::getStaticContexts);
MetaData metaData = user.getCachedData().getMetaData(contexts);
final String prefix = metaData.getPrefix();
*don't work
The code?
Well, I am no Java developer, but I read the Wiki page
Yes
Debug the single variables to find out when it errors out
Oh boy
what for a Command
!meta
How can I get the server context of a server defined in the config?
Nevermind, I got it with api.getConfiguration().getServer()
#support-1 - command is /lp user <user> permission add <node> Or you can create a group, add the node to the group, then add the player to the group
What does node stand for
How can i set an player's prefix for 1 specific server? (With API)
The struggle is to get the Contexts object for the current server.
@bitter gulch @wispy harness have a look at the usage page for devs on the wiki
And for specifics like that @wispy harness have a look at the Javadocs
I probably would at least point you in the right direction if I knew @wispy harness
But you don't know? 😂
And really no need to remove your messages
No. I don’t know that
I am not involved in the development of the plugin
User user = api.getUser(player.getUniqueId());
Node node = api.getNodeFactory().makePrefixNode(1000, ChatColor.stripColor(prefix).replaceAll("§", "&")).setServer(api.getConfiguration().getServer()).build();
user.setPermission(node);```
👍🏻
Hmm
When i restart or open the editor of the player it's gone
Solved, just used Vault 😂
@wispy harness you need to save the changes
@bitter gulch there’s a special context that matches any
Use that
The context class should have a bunch of static contexts for you to use
wdym special context? Sorry, I did read the thing on contexts
isn't really just clicking in my head
I assume I would be fine using a global context for getting a group's prefix?
Sure
@EventHandler
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);
User user = loadUser(e.getPlayer());
api.getUserManager().saveUser((user));
e.getPlayer().sendMessage(ChatColor.AQUA +"Welcome to the Grinder Minigame!");
}
}```
this was working a few days ago, but now nothing happens in my server if i enter the region "grinder0". Can anyone see some obvious mistakes?
full code here https://pastebin.com/WiZdVdkF
There are also no errors to the console
Can anyone help with this? im so confused atm
Still no clue, can anyone take a look/glance over the code?
I don't know, sorry :/
Massive noob question: What is the ‘api’?
For plugin devs to interact with the plugin @old relic
Also you can easily google the meaning of API
Hello, i write this Code: https://hastebin.com/lurepepihi.cs to get the Groups and Groups weight for the Tablist
But when the Owner group have weight 200 and VIP 100. Is VIP on the top from Tablist and Owner in second place but when owner have 90 is owner in first place in the Tablist. What is wrong?
How do I have my own plugin's permission nodes show up in the tab completer of the LuckPerms commands
Have you referenced your plugins jar?
@patent mulch Spigot or Sponge?
Put them in your plugin.yml @patent mulch
Thank you, I figured it out. It's working great!
👍🏻
this isn't so much an api question but an impl one: why does Vault hook's #getPlayerGroups only return one group if a user is in multiple?
is the default group not considered a group? trying to reproduce an issue users tend to have a lot
ugh, well i can't reproduce
no clue how people are setting things up but it works when i get groups from superperms myself, but not through vault
¯_(ツ)_/¯
i mean i'm really unsure how to reproduce atm, but the gist of it is that this code https://github.com/EngineHub/WorldGuard/blob/029f867a4146bfa97acd10ed625ea6729261fc4a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java#L219 returns the wrong groups when https://github.com/EngineHub/WorldEdit/blob/master/worldedit-bukkit/src/main/java/com/sk89q/wepif/VaultResolver.java#L115 is called, but not when https://github.com/EngineHub/WorldEdit/blob/master/worldedit-bukkit/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java#L112 is
(but note that "#inGroup(Player,String)" is correct - which is checked for e.g. region membership, just not "#getGroups" which is checked for that region count)
if someone else comes to me with the problem i'll try nailing down what LP/Vault/etc they are using ¯_(ツ)_/¯
so the difference between those two
The vault method will return a list of the groups the player has "directly"
whereas the wepif method will return a list of all groups the player has, including inheritance
for example, if my only group is "admin", but admin inherits from moderator
vault would return [admin]
wepif would return [admin, moderator]
so I suspect that's where the difference is
vault doesn't really say whether inheritance should be included in that call
¯_(ツ)_/¯
I can't seem to find a simple API method to return all users that are part of a group
so for example, why can't there be a method like group.getUsers() ?
and vice versa for users , user.getGroups()
ah, makes sense luck
there's no way to get a list of inherited groups through vault tho is there
should probably just write a perms resolver that hooks LP directly lol. sounds like work tho. ¯_(ツ)_/¯
Trying to use Helper promises, quite confused on the implementation. How would I write a method with an async promise to run a database query, and return the results when done?
Is there like a ContextChangeEvent or equivalent ?
(Ping me if answering)
An event called each time there's a permission / context update would work too.
how can I check if a player has a group permanently
is there a method in the lp api that gets the storage type?
nvm
How do I give myself rights for bungeecord with Luckperms bungee
lpb user <user> permission set <permission> true
You should ask this in the #support-1 chat though, this channel is intended for questions about the api
Hay, how can I interrogate the group?
I used to do it this way with Pex.
if (PermissionsEx.getUser(p).inGroup("Player")) {
if(plugin.api.getUserManager().getUser(p.getUniqueId()).inheritsGroup(plugin.api.getGroup("group"))) { try this @lyric crypt
ofcours change the plugin.api to how you call the api
and also make sure you do a null check before: if(plugin.api.getGroup("group") != null) {
@lyric crypt are you trying to see if a user is in a group?
String rank = api.getUserManager().getUser(p.getUniqueId()).getPrimaryGroup()```
That’s getting the primary group. Not checking if the player is in a group
16.06 20:43:33 [Server] INFO Caused by: java.lang.NullPointerException: permission what does this mean?
seems to only happen to my plugin when users use lp
why would a permission node be null
Seems like you're passing null as a permission somewhere @tender walrus
Weird, because this only happens with LP.
Debugging rn
@crystal sonnet I can confirm that the permissions exist. I'm not sure if they have to be in a specific format?
Hey Demeng7215! Please don't tag staff members.
kk
These are the permissions:
-custom.permission
-rankgrantplus.grant
Plugin name is RankGrant+.
can you send the full stack trace please @tender walrus
ye got it, sending it on github
the only way for that exception to be thrown is if the permission is null
so, definitely an issue with your code, not LP
Weird, but I debugged
might be related to the configuration?
were you debugging using the same config file as PreciseKill?
yes
can you show me the code you were using to debug?
they are the same
this is super confusing, i have no idea why this would happen.
nvm, we solved it lol
there was a miscommunication
go away @valid cove
Hi, my english is a bit rusty, but I hope you can help me.
I build a Synchronisation betweeen WoltLab (Website CMS) and LuckPerms-Bungee. (WSC -> LuckPerms-Bungee)
// Methode called in PostLoginEvent
ProxiedPlayer player = event.getPlayer();
LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(player.getUniqueId());
// Remove all Groups the User is currently in.
user.clearMatching(Node::isGroupNode);
List<Group> assignGroups = new ArrayList<Group>();
// API fill the list with Groups... (working fine, contains 2 Groups in my test case)
for (Group group : assignGroups) {
if (!user.setPermission(api.getNodeFactory().makeGroupNode(group).build()).asBoolean()) {
getLogger().warning("Group assignment failed: " + player.getName() + " to group: " + group.getName());
} else {
getLogger().info("Group assignment success: " + player.getName() + " to group: " + group.getName());
}
}
api.getUserManager().saveUser(user).thenRunAsync(user::refreshCachedData); //https://github.com/lucko/LuckPerms/wiki/Developer-API:-Usage#saving-changes
Groups from API are assigned, but also the default group, I'm unable to remove the default Group..
Before I build a "dirty" working version, I ask, how I should do this?
Isn't default default group?
yes, but I don't add the default group.
I think after user.clearMatching(Node::isGroupNode); the default group was added, now I don't know how to remove it correctly..
I Missing a Methode like group.isDefault()
Or I should say, I miss this in the API: https://github.com/lucko/LuckPerms/blob/ffe6c24b53e75af2aa94def451c183795026fd36/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java#L706
Well when you remove all groups it adds default
Because player does not have groups then
remove all Groups -> assign Groups -> Save Changes -> default group is obsolet.
remove all Groups -> Save Changes -> default group is ok.
lpb user <user> parent set <group> do the same: https://github.com/lucko/LuckPerms/blob/ee13540d7886e3c847d48d3524c692430d6a9404/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java#L83
So there is no way by using the api to do the same as the command? -.-
now I build the "dirty" version, remove all groups not in assignGroups and it works....
hey guys, i have a permission node (a string) that I want to give to a player. I looked at NodeFactory but this seems a bit cryptic
all i want to do is the java equivelant of /lp user <user> set <node>
ok i found the solution, im just gonna use sponge's subjectData
@umbral bough pretty sure that tab completion showed you the wrong class
yeah that might be the case
i ended up doing this
just using the sponge userStorageService
i hope luckperms picks that up and updates its cache
What's the difference between: luckPermsApi.getTrack();
luckPermsApi.getTrackManager().getTrack();
Also how do I get a users group on a specific track
Hey, can somebody tell me how to query via the API if a particular player has a certain rank?
Hi i am having a bit of issue with luck perms essentialsx permission nodes are not picking up in the server people can't build or use any of the permissions in the server
sad no response
@spring helm
luckPermsApi.getUser(player.getUniqueId()).inheritsGroup(GROUP)
Maybe try luckPermsApi.getGroupManager().getLoadedGroups().size();
Already tried that
Why does track.getGroups() return the groups as strings?
is there a way to return them as a list of groups
Track track = luckPermsApi.getTrack("default");
User user = luckPermsApi.getUser(player.getUniqueId());
for (String groupName : track.getGroups()) {
Group group = luckPermsApi.getGroup(groupName);
if (user.inheritsGroup(group)) {
return group;
}
}
return null;
Is there a better way to get the group of a player on a specific track?
@polar egret what doesn’t work about that?
Im getting a nullpointer when I try to convert the set into a list: List<Group> groups = new ArrayList<Group>(plugin.api.getGroupManager().getLoadedGroups());
@polar egret When are you calling that?
when I use command /grant to open an inventory
like it's in bungee
There isn't an event for that
(too much of a performance hit to call an event for every check)
How do you get the time remaining on a permission node of a player? We set a temporary permission on the player to grant them access to certain features, but I want to add a message to say how long they have access to the features
How do I sort groups according to their weight?
This is my current code but I am not sure if there's any better ways as the wiki discourages use of PermissionHolder#getAllNodes due to it's slow nature:
User user = LuckPerms.getApi().getUserManager().getUser(player.getUniqueId());
user.getAllNodes().stream()
.filter(it -> it.getPermission().equalsIgnoreCase("my.perm.node"))
.findFirst()
.ifPresent(node -> {
long remaining = node.getSecondsTilExpiry();
});```
Generally, use getOwnNodes if you're sure the node will always definitely belong to the player object. Use getAllNodes if the node will belong to a group from which the user inherits.
how do i grab prefixes
hello everyone im having an issue checking inherited groups on a player. so basically the player is in group.b and group.b inherits group.a. when i check if the player has group.a using the function inheritsGroup("a"); it returns false.
shouldnt it be returning true since the player is in group.b and group.b inherits group.a?
how to get a player group username color
any help would be great
How do I sort all the groups by weight and if the weight is the same by name
Because I am pretty sure the Group class in luckperms doesnt have a compareTo method
Maybe don't swear and you might get a useful response
dont type if ur not gonna help
@polar egret You can compare Group#getWeight?
f u lel
[@]MCHQ: Maybe that helps you: https://github.com/lucko/LuckPerms/wiki/Developer-API:-Usage#retrieving-prefixessuffixes
yeah that doesnt work properly
plus thats prefixs
im trying find group name color
So the displayname of a group?
@gilded bane How do I compare it then? You linked me to getUserChatPrefix
That was an example of LuckPerms' API being used to retrieve metadata for a group for MCHQ @polar egret
Ah ok
If the group has a weight, group.getWeight().get() will give you that weight as an int
But how do I compare two if I want to print them in chat so the one with the highest weight is on top etc just like in listgroups
but I need it in a GUI
But I gtg now cya
md how do i get the username colors for the lp groups?
whats the instance name of luckperms
when importing it
no no no
not an instance of the api
an instance of the plugin itself
so i can check if its lodaded
Depends on the platform
Bukkit
https://github.com/lucko/LuckPerms/wiki/Developer-API#obtaining-an-instance-of-the-api
Wouldn't that be this section? If it doesn't exist it would be null right?
And even then, just because the plugin loaded doesn't mean it's working or that the API is available
i only want my plugin to be useable if the plugin is enabled
plugin.yml has a depends section
im trying to send a message when it doesnt work tho
so they know why it doesnt work
but this happens even if it is loaded
If the plugin isn't installed, LuckPerms.getApi will cause a NoClassDefFoundError, and if LuckPerms didn't load properly, it will throw an IllegalStateException
If your plugin enables before LuckPerms, it won't work, which is why you need depends
hello everyone im having an issue checking inherited groups on a player. so basically the player is in group.b and group.b inherits group.a. when i check if the player has group.a using the function inheritsGroup("a"); it returns false.
shouldnt it be returning true since the player is in group.b and group.b inherits group.a?
nope
You are checking if the player inherits group a and it doesnt if you check if group b inherits group a if will return true
How could I add an user to a group without overriding its other parents ?
I know I can do that using commands, but is that doable through the API ?
Just give them the permission
yeah that could work
Sorry noob question here. To import the API classes, would I obtain the api folder from https://github.com/lucko/LuckPerms/tree/master/api/src/main/java/me/lucko/luckperms and move this folder somewhere in my project?
I've added LuckPerms as a dependency in my pom.xml however it's saying the dependency cannot be found.
(IntelliJ IDEA)
I have added
<dependency> <groupId>me.locko.luckperms</groupId> <artifactId>luckperms-api</artifactId> <version>4.4</version> <scope>provided</scope> </dependency>
to my pom.xml but it's not working?
@wet veldt it's lucko
ok yes i just noticed sorry
but then what do i import?
getting "Cannot resolve symbol LuckPermsApi"
You need to import the class(es)
from where?
usually IntelliJ does this for me but it seems it cannot find them
maybe it is not an instance of ServicesManager?
That is something completely diifferent
And are you sure you have imported the class?
IntelliJ can do it for you
I don't think so, I've just added the dependency
But you need to tell it do it
I would like IntelliJ to but idk how
Then it's about time you learn that
what would the class be called?
Stuff like that is trivial to google
Pretty sure it's LuckPermsApi
And the docs on the wiki should also tell you
yeah but in IntelliJ it would automatically import the relevant class matching LuckPermsApi if it's found
it can't be found which is worrying
Pretty sure you have to at least hit a shortcut
Well, did you have a look at the docs on the wiki?
yes
https://github.com/lucko/LuckPerms/wiki/Developer-API#maven you mean this?
it's just using LuckPermsApi without detail on importing it
like for the bukkit classes it would just automatically import them
it seems to not be recognising LuckPermsApi
i have no idea what to do
should work
ugh works now no idea what was causing it, thanks for your patience anyway
"No LuckPerms Plugin Not Found Disabling"
First of all: Why Every Word Starts Uppercase?
Next: Does two no not result in a yes? (negativ + negative = positive)
negative * negative = positive*
Would I need to construct a Node object then pass this to hasPermission to simply check if a User possesses a permission node with true? I only am caring about the node string and the boolean...
Like, there are so many abstract methods for a Node object
ah I can provide a NodeEqualityPredicate and just fill the remainder of the abstract methods with garbage I guess
You really don't need to implement any classes/interfaces to use the API
well I had to construct a Node object
and a comparator
but that's fine, unless there's an easier way?
Did you see this page?
I was looking for something like that but missed it! many thanks
how would i do lp user username permission set via luckperms Api? get confused with this Node's
How do i get already exsiting standart perms as a node for example the * perm ?
@stuck furnace what do you mean with standard permissions?
Yea but it doesnt work for me thats my problem so i thought i would do smth wrong
Im just trying to remove the perm from every online player with a for statement
and the user.unsetPermission(node)
Read the section about saving changes
Not sure what I'm doing wrong:
` User pu = luckPermsApi.getUser(event.getPlayer().getUniqueId());
MetaData meta = pu.getCachedData().getMetaData(Contexts.allowAll());
meta.getPrefix();`
Attempting to get the current prefix, whether it's personal, or set by the group
It only works on personal prefix's though.
Ik, the priority is messed up. I just imported from pex, need to fix some stuff
Oh I see what happened. LuckPerms didn't import my suffix's. I manually added suffix's and now the problem is resolved
Hello
I just installed LuckPerms
And I don't understand how my data are stocked
And how I can edit it
How can i put meta to user? I getMeta than u put in it key and value, save user and its making nothing. I cant even remove meta from user.
@nocturne elbow #support-1. This channel is for devs using the LP API
@tawny aspen there’s an API usage page on the wiki
so to add meta i need to use .setPermission?
Pretty sure there is a meta node builder at least
And there might even be a method to set it directly
Though it'll be explained on the page
yeap first i makeMetaNode and then add/remove it from user
Hey! Is there a way to add a player for eg 1 day to a group with Vault? Or would I have to do it with the LuckPermsAPI directly? If yes how would I do that?
99% sure you have to use the LP API for that
And how to use it is explained on the wiki @wicked flame
hey, how do i set a default group for the world and how do I add individual players to a group
?^!
@near ferry are you trying to do this with a self written plugin?
For questions on how to do things with the plugin itself, pleas use #support-1
there is some possibility of sending a message in the rule such as:
message: "Congratulations"
in the configuration below!!
I want to make a bungeecord command called /resetrank
so how can i delete all player groups and set the player to the default group ?
LuckPerms.getApi().getUser(target.getUniqueId()).clearParents(); ?
``` ??
what does http://prntscr.com/o8w2gs means
@knotty jolt the above should do. And assigned permissions are called nodes.
Be aware that you need to save your changes
alright
@hasty harbor I think this belongs in #support-1. As #luckperms-api is for devs that have questions about the LP API
And the answer is no. The rules are applied when the player joins and only when they join
@knotty jolt no. They change live.
But you need to call the method that saves the changes
It’s explained on the API usage page
No
Takes effect immediately
You can’t even disable that
If you change it on the bungee and it’s for the backend servers, then that means your messaging service isn’t set up correctly
And this belongs in #support-1 btw
@crystal sonnet ops!!
sorry for posting here on this channel # talk-API, but thank you for your attention with the subject, my thanks and have a great week.
Hey MESKITA! Please don't tag staff members.
Does this api have maven support?
how do i use the API
!wiki
:paperclip: https://github.com/lucko/LuckPerms/wiki
Yo
LuckPermsApi api = LuckPerms.getApi();
User user = api.getUser(p.getUniqueId());
Group group1 = api.getGroup("Owner");
User user1 = luckPermsApi.
if(user.inheritsGroup("owner")) { For getting if group.equals
If anyone could get us a fix for this, that would be fantastic ^
We are trying to convert from PermissionsEx and it's a pain in the ass especially when converting with our custom plugins, so we need some API help ASAP.
What are you guys even trying? Why is there a user and a user1.
how can i set a user to a group?
LuckPerms.getApi().getUser(target.getUniqueId()).setPrimaryGroup(rank);
is this right?
I also have not the slightest idea what you are trying to do
Also group names are always lowercase
I'm trying to use LuckPerms API to get if group.equalsIgnoreCase("owner") basically
You have to use the static boolean or just p.haspermission?
the boolean just returns true or false
So use p.hasPermission basically?
How?
i think user.getPrimaryGroup(); works fine
and then you could just ask if that group is equal to the one you are searching for
I rlly appreciate the help, I didnt want to switch but my Owner instisted compared to PermissionsEX
User user = api.getUser(p.getUniqueId()); now this is coming back as an error?
Tell me that this isn't better than permissionsex... There is no comparison, Pex hasn't been touched in years
Have I made any mistakes here? Normaly it should add a player the group VIP for 7 days but it doesnt seem to be working.
unixTime = unixTime + 604800;
Node node = Lobby.permsApi.getNodeFactory().makeGroupNode("vip").setExpiry(unixTime).build();
Lobby.permsApi.getUser(player.getUniqueId()).setPermission(node);```
Oh and the permsAPI is defined as follows:
RegisteredServiceProvider<LuckPermsApi> provider = Bukkit.getServicesManager().getRegistration(LuckPermsApi.class);
if (provider != null) {
permsApi = provider.getProvider();
}```
@wicked flame what is happening?
Welp that could it be ._.
Hi, question. The suffix isn't showing in chat
do you have vault and essentailasx chat?
Caused by: java.lang.NoSuchMethodError: me.lucko.luckperms.common.plugin.LuckPermsPlugin.getApiProvider()Lme/lucko/luckperms/common/api/LuckPermsApiProvider;``` why am i getting this
fixed it by getting the apiprovider instead of getting the plugin and getting its api provider
Trying to use Helper promises, quite confused on the implementation. How would I write a method with an async promise to run a database query, and return the results when done?
And as I've told you before, I highly recommend you use the Vault API instead. Because if you had done that before you wouldn't be needing to replace the PEX API with the LP API. And if you use it now, it's easier to use and you'll support any permission plugin that supports Vault (which is pretty much all of them (LP and PEX included)) @nocturne elbow
I have an issue.
I use LuckPerms in bungeecord for permissions to get permissions player on all my servers from bungee plugins.
But i use LuckPerms in Nukkit too, but not with bungeecord, i use for myself because i don't want all permissions to be the same on all servers.
And when i want to get UUID to one OfflinePlayer, on server i have one UUID, and in bungee i have another
And i don't know what to do, to getUser
private User giveMeADamnUser(UUID uuid) {
UserManager userManager = ChatHandlers.api.getUserManager();
CompletableFuture<User> userFuture = userManager.loadUser(uuid);
return userFuture.join(); // ouch!
}
I can't get User using them name?
What isn't working with that code?
Actually, i think is not a LuckPerms issue. UUID are the same, i get null pointer on Player.getUniqueId()
Thank you for all.
You're welcome
Hi, i am new to permission, How to add a group vip1 to the player?What does primary group mean?
Hello
hi
I always feel luckperm API is not friendly, it has no user.#getGroups(), group# getmembers(), user# addGroup(string group), and other convenient way
'user#inheritsGroup' is commonly regarded as an operation to set if the prefix 'is' is not added
It's more like performing an lp user abc parent add admin operation
Can I get some help
I'm trying to get group.equals
with the API, so it doesn't run through p.hasPermission
player.hasPermission("group."+groupName)
but I want people who are op to have the correct prefix
must add group. prefix
If you have a vip group and want to check if the player include in vipgroup, run player.hasPermission("group.vip")
what if someone is op or has star perms?
I am new to luckperms, I don't think I can answer that question, sorry😅
mk
maybe check minecraft.command.op before group.vip
If I’m not entirely mistaken internal nodes like group, prefix, etc are excluded from *
I'm still confused
@static path just give it a try
You’re confused about what?
And btw, you really shouldn’t be using the * node. It has so many side effects
Can someone please help explain?
What about here https://gyazo.com/fb443dc6de758779165f2926355848aa
This plugin was compatible with pex before
And as I switched over to LuckPerms, I don't know how to do things.
@turbid solar
Oh dont know about that just knew about the getUser part
rip
Checked wiki?
If your op I want the player to still have the correct prefix using p.hasPermission
How do i give out permissions for luckperms, For example how can i make it so people can put people in diff groups but like not edit the groups etc.
@static path utterly unrelated
These things have nonthing to do with eachother
@nocturne elbow ask in #support-1
This channel is for plugin devs using the LP API
Do you see that I referred to two different people there?
First two messages are for you, second two aren't
You made no sense
The question you are asking doesn't make sense
Prefixes and OP are completely unrelated
@fallow dagger the LP API is very different than the PEX API.
If all you need are stuff like prefixes, you should use Vault as your API instead. Makes your plugin compatible with almost any permissions plugin
@static path ?
Yes
I'm talking to you
im aware
I said
The question you are asking doesn't make sense
Prefixes and OP are completely unrelated
And haven't gotten a response to that
With someone being OP, I want their prefix to be the correct one based off the group they are on
Yeah
That's what happens
I have said it twice and I'll say it again:
Prefixes and OP are not related
Ok
Are you checking these things before asking?
?
You have asked a few questions
And all were the same theme. "How can I do/get x if player is OP?". And the answer always was "OP doesn't affect that". Now, I am wondering why you are not just checking these things before asking?
Will save you a lot of time
I did
Then why are you asking?
Testing it should either show you it works or if it doesn't you can tell us
So in the API there is physically no why of actually getting if (user.getgroupname.equals("owner") something of that nature?
getPermanentPermissionNodes() This is supposed to be returning non-transient permissions but it seems to ALSO include transient
fail
guess ill request a fix
looks like I had to use getNodes() instead
Using LP 4.4.26, I was originally trying to use getPermanentPermissionNodes() but I discovered the following javadocs https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/me/lucko/luckp...
@static path you have been told numerous times
User user = LuckPerms.getApi().getUser(player.getUniqueId());
Node node = LuckPerms.getApi().getNodeFactory().newBuilder("indefinite.testtesttest").build();
user.setPermission(node);```
Hi! I am trying to add a permission to a User and it doesn't seem to work.
That's what I am basically using.
Hey there, you are likely not saving the changes, which can be done using: LuckPermsAPI.getUserManager().saveUser(user);
Wow, thanks!
I completely forgot about that.
Appreciate it lol, you saved me a lot of time
No problemo :)
Yup works great, cool
I have the following method. Given the API docs, using .join() is apparently a bad idea because it runs the operation on the same thread instead of queueing another one, as far as I understand it.
I have a commented section where I tried doing some things but I'm not sure what the best option is. The api docs tell you not to use .join() but they don't tell you what to use in lieu of join.
@Placeholder(id = "title")
public String getTitle(@Source Player player) {
if (Optional.of(_databaseService).isPresent() && Optional.of(_luckPermsService).isPresent()) {
/*
AsyncService<Integer> getIdAsync = new AsyncService<>(_luckPermsService.getSelectedTitleId(player.getUniqueId()));
Thread t = new Thread(getIdAsync);
t.start();
t.wait();
int titleId = AsyncService.execute(_luckPermsService.getSelectedTitleId(player.getUniqueId()));
*/
int titleId = _luckPermsService.getSelectedTitleId(player.getUniqueId()).join();
if (-1 == titleId || 0 == titleId)
return "";
try {
Optional<TitleEntry> title = _databaseService.getTitle(titleId);
if (title.isPresent())
return title.get().Title;
return "";
} catch (SQLException se) {
return "";
}
} else return "";
}```
This is just one of many places I'm using .join()
(This is for CompletableFuture<T>
I was able to do this:
int titleId = 0;
try
{
AsyncService<Integer> getIdAsync = new AsyncService();
Thread thread = new Thread(() -> getIdAsync.run(_luckPermsService.getSelectedTitleId(player.getUniqueId())));
thread.start();
thread.wait();
thread.join();
titleId = getIdAsync.getValue();
}
catch (InterruptedException ie)
{
_logger.error(ie.getMessage(), ie);
}```
No idea if it'll work though.
public class AsyncService <T> {
private volatile T value;
public void run(CompletableFuture<T> future) {
new Thread(() -> {
value = future.join();
});
}
public T getValue() {
return value;
}
}```
Oh, I forgot I did threading in run(), good thing I looked at that.
Merged the threading into my AsyncService and placed updated my titles class to match:
AsyncService<Integer> getIdAsync = new AsyncService(_logger);
getIdAsync.run(_luckPermsService.getSelectedTitleId(player.getUniqueId()));
int titleId = getIdAsync.getValue();
// int titleId = _luckPermsService.getSelectedTitleId(player.getUniqueId()).join();```
public class AsyncService <T> {
private volatile T value;
private final Logger _logger;
public AsyncService(Logger logger) {
_logger = logger;
}
public void run(CompletableFuture<T> future) {
try {
Thread thread = new Thread(() -> future.join());
thread.start();
thread.wait();
thread.join();
} catch (InterruptedException ie) {
_logger.error(ie.getMessage(), ie);
value = null;
}
}
public T getValue() {
return value;
}
}```
@hollow grotto well the idea is to never use join on the main thread
If you’re just starting a thread for yourself, it’s perfectly fine to call join
I see. I ended up making some major changes after this but I'll keep that in mind for future reference.
As a general rule, joining is fine if thread you’re blocking is async
Use a thread pool, btw
only 20+ hours later, but \o/ Thread creation is preeeeetty expensive
Using an async handler/runner from the platform should be using one iirc
I actually ended up using Kotlin and just using completableFuture.await (I think that was it)
I have an Inventory GUI for players to switch between rank prefixes. This particular part doesn't work:
case SMITHING_TABLE: {
user.setPrimaryGroup("constructor");
}
I have absolutely no idea why it happens but it just doesn't like the group name. The group exists and I have it as a parent, yet it just refuses to set it as the primary group. I've tried changing the name to something else and that works. Does anyone have any idea on why is this a thing?
@obtuse rapids how does the enitre function look like?
User user = api.getUserManager().getUser(p.getUniqueId());
for (int i : rankSlots) {
if (e.getCurrentItem().getType() == Material.BARRIER){
p.sendMessage(ChatColor.DARK_RED + "Sorry, but you don't have this rank yet!");
break;
} else if (e.getRawSlot() == i) {
try {
switch (e.getCurrentItem().getType()) {
case PLAYER_HEAD: {
user.setPrimaryGroup("member");
break;
}
case SMITHING_TABLE: {
user.setPrimaryGroup("constructor");
break;
}
//...
} catch (NullPointerException nullPointerException) {
p.sendMessage(ChatColor.DARK_RED + "This rank does not exist!");
} catch (IllegalStateException illegalStateException) {
p.sendMessage(ChatColor.DARK_RED + "Sorry, but you don't have this rank yet.");
}
api.getUserManager().saveUser(user);
user.refreshCachedData();
p.sendMessage(ChatColor.DARK_AQUA + "Tag changed!");
}
}
It's still unfinished and the code is probably the worst thing I've ever wrote, but that's how it looks right now
@obtuse rapids now to be sure
Setting the primary group does not give the player the group
When I was testing I manually added the group to my parent groups, it still didn't work
Now what are you expecting that to do?
To change the player's primary group to the one they clicked on
as I said, there is another switch case set up identically, just with a different name, which works as expected.
Do you know what the primary group is for @obtuse rapids ?
As far as I remember, the primary group's meta is used instead of others if more than 1 group has a property set at the same weight. Also I guess same for permission nodes, but I might be wrong because I haven't set same permissions to different values for groups that a player can be in at the same time
That's precisely incorrect
All the primary group is is the answer to "Which (single) (most important) group does the player have"
Which meta is picked depends on the group weight
Do Subject#getOption correspond to the meta in LP?
So I'm making a /rank command just because it's a lot easier than doing /lp user blablabla parent set rank
And I was just executing console commands but I went on the wiki and saw there was a dev api and I'm trying to use that instead now, does anyone know how to set a user's primary group?
Also is it possible to get a prefix for a group through the api? I don't see it anywhere
@MrMaurice211#5248 no idea what you are talking about. LP has an API
@sour pawn there should be plenty of examples on how to use the API on the wiki
How I set a players group
Have a look on the wiki @snow willow
Yes but I dont find it @crystal sonnet
Hey Hallo5000! Please don't tag staff members.
hello guys, can u help me with events?
When i use /lp user nick parent set group, what event will call?
i think about UserPromoteEvent, but it didn't do anything after this command
Bukkit.dispatchCommand(LPCOMMAND)
...
anyone can help with this ☝??
Can anyone tell me what I'm doing wrong here? Group does not apply to player.
Also, how can I sync data between servers after updating it on bungeecord using api?
@nocturne elbow is the code executing?
And Syncing happens automatically if you have a proper network setup
Yes, I get a message saying rank is applied
It also doesn't sync prefix changes until i type /lp sync, all servers including bungeecord is connected to the same mysql database and using "sql" as messaging channel
I change prefixes using this code
api.getUserManager().saveUser(u);```
Hm. You might need to trigger a network sync
Should be a direct call on the API
And also worth a bug report
Couldn't find a network sync method in API, guess i'll just execute the command
will report bug, too
could anyone help me solving a vault-unsafe-lookup problem? :)
Kind of a beginning dev and really can't seem to fix it
it happens when using vault to get an offlineplayer's permissions
@cinder nexus any action that reads data from disk or network, blocking operations or waiting (blockingly (Like joining a thread or CompleteableFuture)) should never be run on the main thread!
Else you will cause lag
In other words run those things async
I tried, but I couldn't get it to work :/
I know it probably sounds like I don't know what I'm doing lol
What means you tried? @cinder nexus
what luckperms event is triggered when i using "/lp user <nick> parent set"?
A few should be
I suppose you'd get NodeAddEvent and numerous NodeRemoveEvent called. The NodeAddEvent would be the addition of the group node group.<group name>, and the NodeRemoveEvent would be called whenever the other group nodes are removed
thnx.
That may not be correct, or some more events may be called such as the UserDataRecalculateEvent, which is triggered whenever cached user data is refreshed
Is there a version of the api that's designed for or supports javascript? (This is for a DJS bot)
Assuming that pinging the server will bring up luckperms data.
There is not, no :/ The only real solution to that is to have the discord bot query the database directly, or have a bridge plugin on the mc server which can be pinged by the bot
I suppose you'd get NodeAddEvent and numerous NodeRemoveEvent called. The NodeAddEvent would be the addition of the group node group.<group name>, and the NodeRemoveEvent would be called whenever the other group nodes are removed
NodeAddEvent throws this:
[18:50:11 ERROR]: [xxI] xx v1.0.1 attempted to register an invalid EventHandler method signature "public void xx.xx.xx.handlers.listeners.permissions.ChangeGroupEvent.onGroupChange1(me.lucko.luckperms.api.event.node.NodeAddEvent) throws java.sql.SQLException" in class xx.xx.xx.handlers.listeners.permissions.ChangeGroupEvent
i need get new user's group name
Your listener method must not throw exceptions
okey. thx
@crystal sonnet I created a new thread and called my methods from the new thread, but it didn't work, I don't know what I'm doing wrong lol
Hey The_King_Senne! Please don't tag staff members.
@cinder nexus well, this is basic plugin stuff. I think you're better off asking on a Discord dedicated to bukkit/spigot plugins
And have your code handy
That will help considerably
now my listener method not throw exceptions, but error...
@EventHandler
public void onGroupChange1 (UserDataRecalculateEvent e) {
Bukkit.broadcastMessage("test");
User user1 = e.getUser();
UUID user = user1.getUuid();
}
[20:58:29 ERROR]: [xx] xx v1.0.1 attempted to register an invalid EventHandler method signature "public void xx.xx.xx.handlers.listeners.permissions.ChangeGroupEvent.onGroupChange1(me.lucko.luckperms.api.event.user.UserDataRecalculateEvent)" in class xx.xx.xx.handlers.listeners.permissions.ChangeGroupEvent
Make sure you're registing these events in the LP event handler
Not the one of the platform
are i know it right?
in onEnable():
luckPermsApi.getEventBus().subscribe(UserDataRecalculateEvent.class, new ChangeGroupEvent()::onGroupChange1);
but same error
oh, i fixed it. just removed @EventHandler annotation
okay thanks brainstone, thought I could try asking the author x)
The thing is you’ll just get the same answer: run it async
Well Thanks anyway :)
Hey! How can I force load LuckPerms API? It's throwing IllegalStateException
Using bungee btw.
@karmic steeple make your plugin depend on LuckPerms and be sure to not load the API before your onEnable
First access it during your onEnable
Like this in bungee.yml?
depends: ['LuckPerms', 'BungeeTabListPlus']```
Yes
If the dependency is optional, I think there's also SoftDepend or After
I'm not sure which one it is, but I know it exists. Check the docs if you want to make the dependency optional
I think I somehow f up the bungee.yml because it's still not working same as BungeeTabListPlus custom variable
I'm accessing it within ChatEvent
Is the error being thrown then or during the start of your plugin=
whenever I try to chat
Then check for startup errors of LP
There are none
The API not being accessible means the plugin isn't starting correctly
I should probably change implementation to compileOnly
Though we are at a point where any further diagnosis becomes impossible without code or at least log
Erm yes
Pretty sure that's pointed out pretty clearly
Greetings, Using VAULT to apply permissions, luckperms appears to only set the permissions on a per world basis, I am not supplying vault with any context for world. Is there a way to make the perms/groups apply globally or do I need to switch to the LuckPerms API for setting permissions?
Most likely the latter
Then don’t make the errors
(Again. Best I can do with the lack of information you provide)
This is the error when i don't have ranks
And this is the error when i join with a rank
In the first error the optional is empty
99% certain there’s an example on how to deal with that on the wiki
Yes but what i should do ? i don't know this api^ i don't understand all the doc i'm not english that's hard to understand
And in the second case your player object is null
How ?
How a player join can be null
And these things have nothing to do with the API itself
Now for the first problem, check the wiki on how to properly get the context
It should account for an empty optional
@crystal sonnet Something like this ? ```java
public String getPrefix(Player player) {
LuckPermsApi lpAPI = LuckPerms.getApi();
User user = lpAPI.getUser(player.getUniqueId());
Contexts userCtx = lpAPI.getContextForUser(user).orElseThrow(()
-> new IllegalStateException("Could not get LuckPerms context for player " + player.getName()));
return user.getCachedData().getMetaData(userCtx).getPrefix();
}
Hey Rourou! Please don't tag staff members.
i find it on programcreek
Do you have that from the wiki?
You’re welcome
okay so if I want to apply a permission that will return true with player.getPermission("somePerm") in ALL worlds on that server, is it as simple as: Node node = luckPermsAPI.getNodeFactory().newBuilder("permToSet").build(); luckPermsAPI.getUserManager().loadUser(playerUuid) .thenApplyAsync(user -> user.setPermission(node)); Will this create a global node, or do I have to also create a contextset? I do not want a permission to be applied based on the world the player is standing in.
this does not appear to save the changes...
@left imp Because you need to save the changes
But, yes. This will make a global node
to add a user to a group would it be the same method except luckPermsAPI.getNodeFactory().newBuilder("group.permToSet").build(); ?
ah i see it now
man this sucks, not excited about redoing all this because vault's api seems to by default add the permissions depending on the world the player is standing in.
Pretty sure you can have a look at LPs implementation of the Vault API
hey, think i could get my patreon tags?
also what's the possibility of getting bulkupdate to work on meta?
in the sponge version
i use TONS of meta and would like to be able to reset it for a map wipe
This has been moved to #support-1
Luckperms API docs say to use group.### perm to see if someone has a group, but it doesn't seem to work with OPs
any fix for that?
yeah - dont use OP with a permission plugin 😜
Alternatively you can iterate over all nodes a player has
And check if one of them is that group you want
Hi
How can I use the api to set a player group?
Like luckperms.getPlayer(p).setParent("Owner")?
How can I add a permission to a player? like "essentials.afk"?
hey, is there an event for when the users primary group changes?
still need this ^ or any event similar if there is one
NodeAddEvent UserDataRecalculateEvent
how often are these called @nocturne elbow
looking to update the users prefix whenever they change group
but i use a different chat plugin (my own)
UserDataRecalculateEvent is triggered whenever cached user data is refreshed
The NodeAddEvent would be the addition of the group node group.<group name>, and the NodeRemoveEvent would be called whenever the other group nodes are removed
I recommended u to use Vault API for chat plugin
Hi ! I would like to get how many players have a rank, is it possible ?
For example, how many players have the vip rank
@Tabbin#3874 why not just let LP handle the prefixes?
@upbeat jackal you need to iterate over all players and check if they have a certain group
If they’re offline you need to load them too
So if you’re doing that, don’t do it too often
You shouldn’t do anything else
And check the wiki
There’s a page on how to use the API
Okay thank you so much
You’re welcome
Just wanna say thank you
great plugin easy interface. Learning to use it as a first time MC server owner... So it's a learning curve but thanks for making it easy
XD
How do I use LuckPerms API to do this without a command doing a command
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player p = (Player) sender;
if (cmd.getName().equalsIgnoreCase("prisongroups")) {
if (p.hasPermission("set.display")) {
p.chat("/lp group default setdisplayname A");
p.chat("/lp createtrack prestige");
p.chat("/lp createtrack prison");
for (char value = 'A'; value <= 'Z'; value++){
p.chat("/lp creategroup " + value);
p.chat("/lp group " + value + " setdisplayname " + value);
p.chat("/lp group " + value + " meta setprefix 1 &8[&a" + value + "&8]&f");
p.chat("/lp track prison append " + value);
p.chat("/lp group " + value + " parent set A");
}
for (int i = 1; i <= 100; i++) {
p.chat("/lp creategroup " + i);
p.chat("/lp track prestige append " + i);
p.chat("/lp group " + i + " meta setprefix 1 &7[&6" + i + "&7]&f");
p.chat("/lp group " + i + " parent set A");
}
}
}
return false;
}```
without having to do all of these commands
is there an API within luckperms do this
Yes there is. The wiki has a basic documentation on how to work with the API
And the API itself has great Javadocs
Hey is there's any way to register my custom luckperms sub command without modifying the source?
Hey NotHillo! Please don't tag staff members.
I'm not sure how to do that
I joined to ask a question regarding to luck perms
Would I be able to manually add permissions into the config file of luckperms? If so, I can't seem to find it.
Because if not, I'll end up keeping on looking for other plugins.
Depends on your storage method
Try the web editor @viscid grove /lp editor
Also this channel is meant for developers who are using the API, use #support-1 for LuckPerms support
thanks but i already got this question answered about a few horus ago on one of the other channels
thanks anyways
oh and my bad
how do you add someone to a group?
Why does this not work?
if (!pl.hasPermission("rank.vip")) {
long unixTime = System.currentTimeMillis() / 1000L;
User user = Lobby.permsApi.getUser(pl.getUniqueId());
unixTime = unixTime + 259200;
Node node1 = Lobby.permsApi.getNodeFactory().makeGroupNode("vip").setExpiry(unixTime).build();
user.setPermission(node1);
Lobby.permsApi.getUserManager().saveUser(user);
Bukkit.broadcastMessage("§6§l" + pl.getName() + " §c§lgot VIP!");
}
}```
But this works:
```long unixTime = System.currentTimeMillis() / 1000L;
unixTime = unixTime + 604800;
Node node = Lobby.permsApi.getNodeFactory().makeGroupNode("vip").setExpiry(unixTime).build();
User user = Lobby.permsApi.getUser(player.getUniqueId());
user.setPermission(node);
Lobby.permsApi.getUserManager().saveUser(user);```
@wicked flame what’s not working in the above code?
Oh yea sorry forgot to mention it. The user just dosnt get the rank. It writes "username got vip" and throws no error.
Try throwing in some debug statements
Hello, is there any easy way to set player group?
I use this now but I have to remove the permission before I add to a new group:
public static LuckPermsApi api;
public static void init() {
api = LuckPerms.getApi();
}
public static void setGroup(Player plr, String group) {
User user = api.getUser(plr.getUniqueId());
Node node = api.getNodeFactory().newBuilder("group." + group).build();
user.setPermission(node);
}
do you want to add a player to a group? @nocturne elbow
Yes.
use this and ull be fine
lp user NAME Luck parent add GROUP NAME
@midnight gorge we’re in #luckperms-api
@nocturne elbow you forgot to save the changes
I’d recommend you check the wiki
There are plenty of API usage examples
ya i dont know wgat api is so i really dont kow
Programming interface @midnight gorge
hey, I need help - im trying to make my scoreboard show their luckperms rank (im using luckperms bungee version), but im not sure what the method is
tried looking on github, but didnt find anything that helped me
what method @quiet bough
like, im trying to show the rank on the scoreboard
not method
but
for (String group : possibleGroups) {
if (player.hasPermission("group." + group)) {
return group;
}
}
return null;
}```
I found this on the Developer API usage on github, but that doesnt help me for my scoreboard
Get a LP User object and get their primary group
this is my first time using the API, so how would I do that? xd
Check the wiki
You're welcome
Btw, make sure you include either the source or javadoc of the API in your IDE, so you can see the docs of the methods and classes
Hey AJ! Please don't tag staff members.
my bad clippy
hi, i have code:
https://pastebin.com/tMKgWN9U
event will calls when i change player's group, but it always set to player last group (SOH_PLUS)
BrainStone, help plz
@nocturne elbow your switch statements doesn't have break statements
And btw, you really should wrap that try catch block around the whole switch statement instead of around each call
okey, sorry for dumb quest...
thnx
It's highly recommended you properly learn Java before writing plugins
MC plugins are one of worst ways to get started with programming
I learn java through writing plugins ;D
Terrible idea
i know
Why does this code not set the primary group?
public static void setGroup(Player plr, String group) {
User user = api.getUser(plr.getUniqueId());
user.setPrimaryGroup(group);
api.getUserManager().saveUser(user);
}```
@nocturne elbow because by default the primary group is calculated
How can I set it? Or I definitely have to use user.setPermission(/group perm/);?
If you want to add a group to a player, then you have to add the respective node
And if you want to set it, then you have to remove all other group nodes
The wiki has plenty of usage examples
So if I want players have only one group then before I set it I have to remove other groups that he has?
Yes
Okay, I think I am done with it.
Do you change anything on this?
public static void setGroup(Player plr, String group) {
if(api.getGroupManager().getGroup(group) == null) {
return;
}
User user = api.getUser(plr.getUniqueId());
Set<String> groups = user.getAllNodes().stream().filter(Node::isGroupNode).map(Node::getGroupName).collect(Collectors.toSet());
for(String groupname : groups) {
Node node = api.getNodeFactory().makeGroupNode(groupname).build();
user.unsetPermission(node);
}
Node finalnode = api.getNodeFactory().makeGroupNode(group).build();
user.setPermission(finalnode);
api.getUserManager().saveUser(user);
}
Yeah, Combine getting and removing the group nodes into one step.
So instead of
Set<String> groups = user.getAllNodes().stream().filter(Node::isGroupNode).map(Node::getGroupName).collect(Collectors.toSet());
for(String groupname : groups) {
Node node = api.getNodeFactory().makeGroupNode(groupname).build();
user.unsetPermission(node);
}
do
user.getAllNodes().stream().filter(Node::isGroupNode).forEach(user::unsetPermission);
@nocturne elbow
Okay, thanks.
how to grant a group using the api? adding the permission node didnt work
how i can set group on players?
@chrome coral don't cross post
Essentials.instance.luckApi.getUser(player.getUniqueId()).setPermission(Essentials.instance.luckApi.getNodeFactory().newBuilder("group.regular").build());
@crystal sonnet is that correct?
Hey DerWand the mighty Intellectual! Please don't tag staff members.
Yes and no
For one, there's a node builder method for group nodes. But what you did works too
i think i saw the "group.regular" node in the editor but it doesnt show up with user info as a group
The next thing is (as mentioned in #support-1) you are not saving the changes
So check the Dev page on the wiki
@fair herald also do that 👆🏼
saveUser?
Yes
thanks
Why do I even have to tell you to read the docs is the more pressing question
how do i obtain context for a group
is it just my browser or is there no search function (like on the spigot api javadoc)? https://javadoc.io/doc/me.lucko.luckperms/luckperms-api/4.4
thats the browser search ...
thats the search in the opened page
doesnt help me
okay now tell me where userloadevent appears
i dont have that kind of a browser, okay?
hold on
ok go me.lucko.luckperms.api.event.user and there it is
@chrome coral thats google chrome lol
yes lol i dont have it
then download it
no thank u
if you use edge or IE -_-
or you were living in a cave for the last 11 years
and dont know what google chrome is
for UserLoadEvent you go me.lucko.luckperms.api.event.user and there it is
is it possible that the example there is out of date?
// get the LuckPerms event bus
EventBus eventBus = api.getEventBus();
// subscribe to an event using a lambda
eventBus.subscribe(LogPublishEvent.class, e -> e.getCancellationState().set(true));
eventBus.subscribe(UserLoadEvent.class, e -> {
System.out.println("User " + e.getUser().getName() + " was loaded!");
if (e.getUser().hasPermission("some.perm", true)) {
// Do something
}
});
its not outdated
hasPermission doesnt work for me with a string and a boolean
then use regular player's hasPermission
is this the right way to obtain group prefix?
Node prefixNode =
asLuckPermsGroup.getOwnNodes().parallelStream().filter(Node::isPrefix).findFirst().get();
return prefixNode.getTypeData(PrefixType.KEY).get().getPrefix();
@fierce dew what do you mean with “context for a group”?
nothing
is this the right way of getting group's prefix
Node prefixNode =
asLuckPermsGroup.getOwnNodes().parallelStream().filter(Node::isPrefix).findFirst().get();
return prefixNode.getTypeData(PrefixType.KEY).get().getPrefix();
??
Or if not, get the cached data and get it from there
how to get the cached data??
It’s a method
One sec
Get the metadata
how to get contexts??
And that gives you the context
One sec
Check the context class
There are several options
Contexts.GLOBAL ??
how do I add someone to a group?
ok, ty!
:paperclip: https://github.com/lucko/LuckPerms/wiki/Context
Can someone remake this, but using LuckPErms API?
for (char value = 'A'; value <= 'Z'; value++){
p.chat("/lp creategroup " + value);
p.chat("/lp group " + value + " setdisplayname " + value);
p.chat("/lp group " + value + " meta setprefix 1 &8[&a" + value + "&8]&f");
p.chat("/lp track prison append " + value);
p.chat("/lp group " + value + " parent set A");
}
for (int i = 1; i <= 20; i++) {
p.chat("/lp creategroup " + i);
p.chat("/lp track prestige append " + i);
p.chat("/lp group " + i + " meta setprefix 1 &7[&6" + i + "&7]&f");
p.chat("/lp group " + i + " parent set A");
p.chat("/lp group " + i + " permission set some.shopmultiplier.p" + i);
}```
or show me some things with luckperms api so i can learn how to use it
!wiki
:paperclip: https://github.com/lucko/LuckPerms/wiki
There’s a section regarding the API and use cases
Hello,
How can I query if a player has a specific group?
@spring helm asked right after "There’s a section regarding the API and use cases"
!wiki
:paperclip: https://github.com/lucko/LuckPerms/wiki
:>
In fact that's the VERY FIRST use case on the usage page...
https://github.com/lucko/LuckPerms/wiki/Developer-API:-Usage#checking-if-a-player-is-in-a-group
i'm sooo confused by usage
how do i check if a player has a permission in the current server context
I'll just try the suggested method
Lp user <ign> permission i
Are you able to get a permission from an OfflinePlayer using the LuckPerms API?
Yes, by uuid
I checked the wiki but didn't understand.
How do I change data such as suffix and prefix using the API?
How do I get fetch when someone gets their group removed?
what event should I use for that?
Hello, how i can ser the primary group of player ?
I have try with group getName, getFriendlyName,getDisplayName and getObjectName but this always return FAIL when call setPrimaryGroup.
Note: i am on bungee
Thanks for your help
Now what are you expecting setting the primary group to do @maiden vault ?
@rotund light there should examples for just that
@crystal sonnet I use the primary group for use the prefix of that role
Hey orblazer! Please don't tag staff members.
Btw, is it "how i can see the primary" or "how i can set the primary"?
how i can set, because i need that for an command promote player event if offline on bungee
So you want to change someone's group or add a group to someone?
That's not what setting the primary group does
The primary group is the group that LP returns to the question "which single most important group does the player have"
Setting it will only change which of the several groups a player has is that group
It will not add or set a different group @maiden vault
The wiki has a developer guide
Which also explains how to add and set groups
ok, if i want define group to player like VIP i need pass by the permission and i need manually remove other groups
Yes