Checking if player has permission to use a command from another plugin

Discussion in 'Plugin Development' started by FoxinatorDev, Jun 25, 2020.

Thread Status:
Not open for further replies.
  1. Offline


    I'm trying to check if the player has permission to use a command that is from another plugin. I've already tried using Bukkit.getPluginCommand() but only get a NullPointerException if it's not from my plugin.
  2. Offline


    If you know what the permission for the command why not use Player.hasPermission("permission")
    Like if /testCMD needs the permission CMD, use Player.hasPermission("CMD")

    If you dont, you can try adding the other plugin to your library and having it as a dependency so it loads beforehand, and accessing its classes, (As each person has a different way of coding you'll have to find out what todo from there on)
  3. Offline


    @Legendary_zotar The thing is, there's no way to get the permission if the plugin is using something like this:
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. if (!sender.hasPermission("some.permission")) {
    4. sender.sendMessage("You do not have permission for this.");
    5. return true;
    6. }
    7. // Code
    8. return true;
    9. }
  4. Offline


    I think he means if the OP is targeting a specific plugin, then one can just look at the plugin and/or its documentation to get the required permission then check that permission directly. Like if plugin MyFirstPlugin wanted to be sure someone had Essentials fly, they could check "".

    Though OP never said it was a specific plugin in mind, so hard coding may not be a valid alternative.
Thread Status:
Not open for further replies.

Share This Page