How LuckPerms "predicts" permissions

This is not an issue, only something I was investigating for fun I've been curious about how LuckPerms manages to "predict" permissions the server has available. I made a very small single-file plugin to see this feature in action with just a single Permissible.hasPermission(String) function at the start of a command. Apparently before trying to execute the command, luckperms is not yet aware of this permission, however after trying it once and opening the editor, it does show as a possible permission to choose. This suggest that they might be caching permissions when Permissible.hasPermission(String) or similar functions are executed, however in their repo there isn't a clear reference to a cache on hasPermission, only on addPermission. I've been reading their repo for a while now, and learned a lot of how the plugin works but so far, no reference as how they resolve those permissions, closest I could find is AsyncPermissionRegistry but there's nothing suggesting a possible cache. This post is mostly for curiosity, if anyone had the same question and managed to find an answer before me. This is the example plugin I made to test this:
class CrappyPlugin : JavaPlugin() {

lateinit var self: CrappyPlugin

override fun onLoad() {
this.self = this
}

override fun onEnable() {
this.server.commandMap.register("example", object : Command("canexecute"), PluginIdentifiableCommand {
override fun execute(
sender: CommandSender,
label: String,
args: Array<out String>?
): Boolean {
if (sender.hasPermission("example.canexecute.test")) {
sender.sendMessage("Yes, you can execute")
return true
}
sender.sendMessage("No, you can't execute")
return false
}

override fun getPlugin() = self

})
}

}
class CrappyPlugin : JavaPlugin() {

lateinit var self: CrappyPlugin

override fun onLoad() {
this.self = this
}

override fun onEnable() {
this.server.commandMap.register("example", object : Command("canexecute"), PluginIdentifiableCommand {
override fun execute(
sender: CommandSender,
label: String,
args: Array<out String>?
): Boolean {
if (sender.hasPermission("example.canexecute.test")) {
sender.sendMessage("Yes, you can execute")
return true
}
sender.sendMessage("No, you can't execute")
return false
}

override fun getPlugin() = self

})
}

}
No description
27 Replies
Admincraft Meta
Thanks for asking your question!
Make sure to provide as much helpful information as possible such as logs/what you tried and what your exact issue is
Make sure to mark solved when issue is solved!!!
/close !close !solved !answered
Requested by duoslingo#0
Arthurmeade12
Arthurmeade127d ago
Don't plugins declare their permissions in plugin.yml
duolingo se acerca
No, try the code above as is without declaring anything in plugin.yml and Luckperms will be able to detect the permission regardless I mean, declare the main class, plugin name, etc. But no permissions
Arthurmeade12
Arthurmeade127d ago
Haha I trust you I don't know java Even though I probably should bc it's useful
Mortis
Mortis7d ago
I might be wrong but pretty sure its basically grabbing it from tab completion then checking the commands permission from plugin.yml? thats probs at least partially how its done
duolingo se acerca
Try the code above without any permission in plugin.yml
Mortis
Mortis7d ago
i know just stating partially thats how they likely do it
duolingo se acerca
I feel is most likely cached I opened an editor before and after joining the server Before joining, the permission wasn't displayed in the editor
Mortis
Mortis7d ago
also it could just be the plugin listening into permission checks and caching it
duolingo se acerca
After joining and running the command that required said permission, it was displayed on the editor (had to open a new one)
Mortis
Mortis7d ago
lp verbose does exist after all
duolingo se acerca
Haven't try that before, but I don't think is likely that it mentiones the classes that are being called Or does it? I'll try
duolingo se acerca
Doesn't give that much insight on how lp does it
No description
duolingo se acerca
I also took the chance to confirm, I opened one editor after joining the server but before executing that command. The editor is definitely only able to recognize it after the permission has been consulted
Mortis
Mortis7d ago
because web editor is a web socket connection and you create a connection to the web editor and your server and upload permission to the web editor
duolingo se acerca
Yh, but the point is where does it gets the permissions from in terms of code It's not on the plugin.yml, I haven't manually added them with Permissible.addPermission() it is registering the permission somewhere once its consulted
Mortis
Mortis7d ago
tab completion?
duolingo se acerca
I tried that and it lead me to AsyncPermissionRegistry I also tried looking into their hasPermission implementation and it lead me to PermissionCalculator But nothing that could potentially store the permission to send it to the editor
Mortis
Mortis7d ago
is that what you really want? just wondering whats your goal here
duolingo se acerca
Just to know what they did to store it I made something similar with a regular map And that left me wondering how they handled it
Mortis
Mortis7d ago
Mortis
Mortis7d ago
GitHub
LuckPerms/common/src/main/java/me/lucko/luckperms/common/model/Perm...
A permissions plugin for Minecraft servers. Contribute to LuckPerms/LuckPerms development by creating an account on GitHub.
duolingo se acerca
Just checking that one
Mortis
Mortis7d ago
GitHub
LuckPerms/common/src/main/java/me/lucko/luckperms/common/commands/m...
A permissions plugin for Minecraft servers. Contribute to LuckPerms/LuckPerms development by creating an account on GitHub.
Mortis
Mortis7d ago
honestly think that should be enough idea to get how this works
duolingo se acerca
Mostly, the issue is that when I look into those files I ran into a class that doesn't hold anything Well, I'm also just checking via github on the browser Maybe I should clone the repo and use the ide But idk, it is kinda fun investigating this way

Did you find this page helpful?