Custom no-permission

Discussion in 'Plugin Development' started by hutattedonmyarm, Nov 11, 2012.

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

    hutattedonmyarm

    In the onCommand() I check if the user has permissions, and if not I react by sending the user a message and also sending the admins a message. Not long ago, I wrote the needed permissions in the plugin.yml to the commands, like:
    Code:
    tp:
        description: Teleports you/player1 to player2
        usage: /tp [player1] <player2>
        permission: MitaBase.tp
    
    Since then, Bukkit seems to checkthe permissions itself. That's fine, but I don't know anymore when a user enters a command they don't have access to.

    Is there a way to have both, the entry in the plugin.yml and your own permission checking?
     
  2. Offline

    GodzOfMadness

    Here is a way:

    Code:
            if((player == null || player.hasPermission("permission.node") && cmd.getName().equalsIgnoreCase("cmd")//
              || player.hasPermission("permission.node2") && cmd.getName().equalsIgnoreCase("cmd2"))){
                //Do commands in here
            }else{
                player.sendMessage((new StringBuilder()).append(ChatColor.RED).append(ChatColor.GREEN + "[PluginName]" + ChatColor.RED + " Permission denied.").toString());
                return false;
            }
     
  3. Offline

    CeramicTitan

    how about posting the code?
     
  4. Offline

    hutattedonmyarm

    That's (basically) what I'm doing.
    Code:
    if(p != null && p.hasPermission("permission.node")) {
      some code
    } else if (p == null) {
      playerOnly(sender);
    } else {
      noPermission(sender, cmd, args);
    }
    
    And here my noPermission():
    Code:
    sender.sendMessage(ChatColor.RED + "You don't have permission to do that. This incident will be logged!");
    String argString = "";
    for(int i = 0; i < args.length; i++) {
        argString += args[i] + " ";
    }
    console.sendMessage(pluginPrefix + sender.getName() + " was denied access to command /" + cmd.getLabel() + " " + argString);
            Bukkit.getServer().broadcast(sender.getName() + " was denied access to command /" + cmd.getLabel() + " " + argString, "MitaBase.watchPerms");
    This method does not get called. Instead, Bukkit standard-message is sent to the 'evil' user.
     
  5. Offline

    GodzOfMadness

    what is the instance of "console" on (console.sendMessage(pluginPrefix + sender.getName() + " was denied access to command /" + cmd.getLabel() + " " + argString);)
     
  6. Offline

    hutattedonmyarm

    Code:
    private ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
    Sending messages to console works fine ;)
     
  7. Offline

    GodzOfMadness

    well you did say "Bukkit standard-message is sent to the 'evil' user."'

    Edit: or do you meen this works fine but
    the permission node in the plugin.yml is still sent to them?
     
  8. Offline

    hutattedonmyarm

    The whole method noPermission() works, but since I added the nodes to the commands in the plugin.yml it doesn't get called anymore. I guess that Bukkit is using their own permission-cheking because I added it, and when a user doens't have the permission, it doesn't even call the onCommand.
     
  9. Offline

    GodzOfMadness

    your setting something wrong then
    try to use my piece of code it works just fine
    and if it isnt calling the onCommand() then its either your method is mixed up or your CurlyBraces are in the wrong places
     
  10. Offline

    hutattedonmyarm

    Okay, I found it... it was PermissionsEx
     
Thread Status:
Not open for further replies.

Share This Page