Permissions and Command block

Discussion in 'Plugin Development' started by Kernelith, Oct 30, 2014.

Thread Status:
Not open for further replies.
  1. Hello everyone !

    It has been several weeks, in truth few days (recovery of a draft plugin) that I have a problem with some commands that I have implemented and command blocks.
    Let me explain:
    With a friend, we have developed a plugin that add some feature like a justice management etc...
    The person who asked us to do that specify that justice commands cannot be ran by normal users but only by moderators.

    We use the plugin PermissionsBukkit with a good configuration to manage all groups of users.
    And in our plugin.yml we have created a specific permission like this:

        default: false

    So when I instantiate the command I do something like this:
    1. new JailCommand(Permissions.JUDGE_PERM);

    where Permissions.JUDGE_PERM is a String pass to the function setPermission of a PluginCommand.

    This works fine for players when they don't have the permission they cannot run the command and vice versa.

    My BIG problem is when I put this command (for some reason) in a command block and when we try to execute it, it doen't work. :-(
    I think that it's because the command block hasn't the permission so he cannot execute it.
    I've searched many way to skip this checking but with no success.

    It's possible that what I think is the problem is not, but I have no other ideas which can explain why it doesn't work in command blocks.

    I'm not sure if I am clear in my explanation. If you want more details tell me.

    I hope that you can help me, thanks!

    PS: Sorry if there are mistakes in my english. :)
  2. Offline


    1. if (p.!hasPermission("Permission")) {
    2. //if player has permission
    3. }
    4. Else {
    5. //if player does not have permission
    6. }
  3. Offline


    Instead of simply checking for a permission, you may also need to check if the sender is an instance of a BlockCommandSender (for command blocks) or ConsoleCommandSender (for sending via console)
  4. Offline


    Command Blocks Run As Op's, if you check for a permission the CommandBlock will have it.
  5. Offline


    That depends on the plugin. Not familiar with PermissionsBukkit (what he said he used), but I know that GroupManager can optionally give Op all perms.
  6. Offline


    A commandBlock being a minecraft block should mean all permission plugins should support it. If not there will be a config letting you do so.
  7. SleepyDog I haven't any test like this it seems to be check automatically. Because if I can do the test by a simple test to know if my commandSender is a BlockCommandSender everything could work. But no unfortunately :(

    I have a class that implement the commandExecutor, see below :

    1. public abstract class UTMCommand implements CommandExecutor
    2. {
    3. [...]
    5. public UTMCommand(String name, String permission)
    6. {
    7. try
    8. {
    9. PluginCommand command = UTMPlugin.getInstance().getCommand(name);
    11. command.setExecutor(this);
    12. command.setPermissionMessage(PermissionMessage);
    13. command.setPermission(permission);
    14. }
    15. catch (Exception ex)
    16. {
    17. }
    18. }
    20. public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    21. {
    22. try
    23. {
    24. if (sender instanceof BlockCommandSender)
    25. Utils.logInfo("Command block");// print the message in the console of the server
    26. if (sender instanceof Player)
    27. onPlayerCommand((Player) sender, args);
    28. else
    29. onConsoleCommand(sender, args);
    30. }
    31. catch (UTMException ex)
    32. {
    33. }
    35. return true;
    36. }
    38. [...]
    39. }

    as you can see when I instantiate I put permission and permission message, nothing wrong I think.
    And in the onCommand function I make a distinction between player and console sender. For the test I've added a log printed in the console of the server to know if the command has been sent from a command block.

    All my command inherit from this class. To test I've this screenshot where I define two commands:
    /jail that require a permission and /m dans send a private message to a player that doesn't require permission.
    When I put redstone I have this result :
    View attachment 22353

    EDIT: not present on the screen sorry it disappear before I take it ! The second command is /jail kernelith

    You can see in the console that I have just one print of CommandBlock so it pass only one time in my onCommand function, the time when I doesn't need permissions. Excuse me for the "Je passe", it's just for me !
    (Before the test of BlockCommandSender)

    I don't know if command block have all permissions, but in this case it seems to not, no ?
  8. No one have an idea to solve this problem ?

    Or is what I'm doing wrong ?
Thread Status:
Not open for further replies.

Share This Page