Minecraft,FTB,MCPC +,Multicraft,Plugin:没有权限,控制台无法运行命令

时间:2014-04-06 00:49:46

标签: java plugins minecraft bukkit

我正在尝试Bukkit插件,我第一次遇到一些困难。 我的服务器控制台无法运行命令,如果我可以得到你的评论,对正在进行的解释将有所帮助。

类代码:这只是相关的代码块。

//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; 
}

服务器输出: [服务器]信息您没有ConsoleFilter权限节点 - ConsoleFilter.Reload

Plugin.yml:此文件正确解析任何间距错误是由于发布。

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

1 个答案:

答案 0 :(得分:0)

所以我自己想出了这个。 问题不在于plugin.yml设置为false,实际上你想保持这种方式,以便defualt的用户无权访问该命令。我的问题是我在plugin.yml中的命令块下面留下了Permission-Node。 我试图利用本机Bukkit api(命令块permisions)和更新的Bukkit api(权限块权限)。 命令块权限优先,并覆盖我已有的任何代码。删除:

permission: ConsoleFilter.Reload
permission-message: You don't have ConsoleFilter Permissions node- ConsoleFilter.Reload
来自plugin.yml的

我允许我的代码完成它的工作。

此外,一些代码更改可能会对最终结果产生影响:

//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;
}