0

I am trying my hand at Bukkit plugins and im having some difficulty on my first. My console for the server is incapable of running the command, if i could get your review, an explanation to whats going on would be helpfull.

Class Code: This is just the relevant code chunk.

//Overrides bukkits onCommand with modified code
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (args.length > 1) {//No more then 1 argument
        sender.sendMessage("[ConsoleFilter] Too many arguments!"); //Sends player a message
        return false;
    } 
    if (args.length < 1) {//No less then 1 argument
        sender.sendMessage("[ConsoleFilter] Not enough arguments!"); //Sends player a message
        return false;
    }
    if (cmd.getName().equalsIgnoreCase("CF")) { //Checks for /CF
        if (args[0].equalsIgnoreCase("Reload")){ //Checks for /CF Reload
            Player player = null; //Sets player
            if (sender instanceof Player){ //if sender is a player entity
                player = (Player) sender; //player = sender
                //plugin.yml will actually validate permissions, however additional provisions allows for 
                //further security and further extendability.
                if (player.isOp() || player.hasPermission("ConsoleFilter.Reload")){ //Is the player an Op or have specified Permission
                    this.reloadConfig(); //Reloads config file back into memory
                    player.sendMessage(ChatColor.DARK_GREEN + "Config Reloaded!"); //Sends player a message
                    getLogger().info("[ConsoleFilter] Config Reloaded");
                    return true; //Close True
                }
            }
            else{
                this.reloadConfig(); //Reloads config file back into memory
                getLogger().info("[ConsoleFilter] Config Reloaded");
                return true; //Close True
            }
        }
    }
    return false; 
}

Server output: [Server] INFO You don't have ConsoleFilter Permissions node- ConsoleFilter.Reload

Plugin.yml: This file parses properly any spacing errors is due to posting.

name: ConsoleFilter
main: com.dirtyredz.ConsoleFilter.ConsoleFilter
version: 0.0.1
commands:
   CF:
      description: This is a demo reload command.
      usage: /CF Reload
      permission: ConsoleFilter.Reload
      permission-message: You don't have ConsoleFilter Permissions node- ConsoleFilter.Reload
permissions:
   ConsoleFilter.*:
      description: Complete access to consolefilter commands
   children:
         ConsoleFilter.reload: false
   ConsoleFilter.reload:
      description: Test reload
      default: false
DirtyRedz
  • 566
  • 5
  • 14
  • 1
    It seems pretty clear from the error message that your plugin needs a permission that it doesn't have. And on the face of it, your "plugin.yml" file is explicitly setting that permission to "false". Isn't it obvious what you should do? Hint: **read** the errors messages ... – Stephen C Apr 06 '14 at 01:01
  • My plugin doesnt need a permission, my plugin creates permissions via the "plugin.yml". Ontop of that the "Console" is not a player entity and is ABOVE anything on the server it doesnt need permissions. The problem here is my code is not treating the console like a console its treating it as a player. – DirtyRedz Apr 06 '14 at 04:15
  • I'm not a Bukkit expert, but the evidence suggests to me that your assumptions are incorrect. The minecraft forums are a better place to ask questions like this. That's where the Minecraft experts hang out. – Stephen C Apr 06 '14 at 04:22

1 Answers1

0

So figured this one out on my own. The issue was not that the plugin.yml was set to false, infact you want to keep it that way so that users by defualt do not have access to the command. My problem was that i left the Permission-Node under the command block in the plugin.yml. I was attempting to utilize the native Bukkit api (command block permisions) and the Updated Bukkit api (permissions block permissions). the Command Block permissions were taking precedence and overwriting any code i had in place. By removing:

permission: ConsoleFilter.Reload
permission-message: You don't have ConsoleFilter Permissions node- ConsoleFilter.Reload

from the plugin.yml I allowed my code to do its work.

Also a few code changes may have contributed to the end result:

//Overrides bukkits onCommand with modified code
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (args.length > 1) {//No more then 1 argument
        sender.sendMessage("[ConsoleFilter] Too many arguments!"); //Sends player a message
        return false;
    } 
    if (args.length < 1) {//No less then 1 argument
        sender.sendMessage("[ConsoleFilter] Not enough arguments!"); //Sends player a message
        return false;
    }
    //plugin.yml will actually validate permissions, however additional provisions allows for 
    //further security and further extendability.
    if (sender instanceof Player){ //if sender is a player entity
        Player player = (Player) sender; //Sets player to sender
        if (player.isOp() || player.hasPermission("ConsoleFilter.Reload")){//Is the player an Op or have specified Permission
            if (cmd.getName().equalsIgnoreCase("CF")) { //Checks for /CF
                if (args[0].equalsIgnoreCase("Reload")){ //Checks for /CF Reload
                    this.reloadConfig(); //Reloads config file back into memory
                    player.sendMessage(ChatColor.DARK_GREEN + "Config Reloaded!"); //Sends player a message
                    getLogger().info("[ConsoleFilter] Config Reloaded");
                    return true; //Close True
                }
            }
        }else{
            player.sendMessage("You do not have the appropriate Permissions. (ConsoleFilter.Reload)");;
        }
    }else{
        this.reloadConfig(); //Reloads config file back into memory
        getLogger().info("[ConsoleFilter] Config Reloaded");
        return true; //Close True
    }
    return false;
}
DirtyRedz
  • 566
  • 5
  • 14