英文:
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("ban")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.DARK_RED + "Incorrect usage! /ban <player>");
return false;
}
}
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Player " + player + " not found.");
return false;
}
return true;
}
答案1
得分: 0
已解决,我在主类中注册它时出现了错误。
英文:
Solved, I had it registered in my main class incorrectly.
专注分享java语言的经验与见解,让所有开发者获益!
评论