我的封禁命令参数要求似乎无法正常工作(Bukkit)

huangapple 未分类评论43阅读模式
英文:

My ban command argument requirements don't seem to be working (Bukkit)

问题

以下是你的代码部分的翻译:

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if (cmd.getName().equals("ban")) {

        if (args.length == 0) {
            sender.sendMessage(ChatColor.DARK_RED + "用法不正确!/ban <玩家名>");
            return false;
        }

    }

    Player player = Bukkit.getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(ChatColor.RED + "未找到玩家 " + args[0] + "。");
        return false;
    }

    return true;
}
英文:

I am trying to create a GUI that contains various punishments and I'm having an issue with my messages going through to the player when they should be going through. For example, if I run /ban in game with no argument afterwards, I want it to say "Incorrect usage! /ban <player>" and apparently my code is incorrect. Similarly, if the user submits a player that is null, I want a message to be sent that says "Player (player) not found." Whenever I run the command, with or without arguments, it just displays the "usage:" in my plugin.yml.

 public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if (cmd.getName().equals(&quot;ban&quot;)) {

        if (args.length == 0) {
            sender.sendMessage(ChatColor.DARK_RED + &quot;Incorrect usage! /ban &lt;player&gt;&quot;);
            return false;
        }

    }

    Player player = Bukkit.getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(ChatColor.RED + &quot;Player &quot; + player + &quot; not found.&quot;);
        return false;
    }

    return true;
}

答案1

得分: 0

已解决,我在主类中注册它时出现了错误。

英文:

Solved, I had it registered in my main class incorrectly.

huangapple
  • 本文由 发表于 2020年7月25日 09:46:48
  • 转载请务必保留本文链接:https://java.coder-hub.com/63083447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定