1
我正在爲我的服務器開發一個基本插件,但我無法獲得第5個命令。Minecraft Bukkit:命令不起作用
這裏是Main.java的代碼:
package me.knightgeek.geekessentials;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
public void onEnable() { //On plugin startup
Bukkit.getServer().getLogger().info("Geek Essentials has been Enabled");
}
public void onDisable() { //On plugin close
Bukkit.getServer().getLogger().info("Geek Essentials has been Disabled");
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("heal")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "The console cannot run this command!");
return true;
}
Player player = (Player) sender;
if (args.length == 0) {
player.setHealth(20);
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have been healed.");
return true;
}
@SuppressWarnings("deprecation")
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null) {
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "This player has not been found.");
return true;
}
target.setHealth(20);
target.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have been healed by " + ChatColor.WHITE + player.getName());
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have succesfully healed " + ChatColor.WHITE + target.getName());
return true;
}
if (cmd.getName().equalsIgnoreCase("feed")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "The console cannot run this command!");
return true;
}
Player player = (Player) sender;
if (args.length == 0) {
player.setFoodLevel(20);
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have been fed.");
return true;
}
@SuppressWarnings("deprecation")
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null) {
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "This player has not been found.");
return true;
}
target.setFoodLevel(20);
target.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have been fed by " + ChatColor.WHITE + player.getName());
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have succesfully fed by " + ChatColor.WHITE + target.getName());
return true;
}
if (cmd.getName().equalsIgnoreCase("survival")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "The console cannot run this command!");
return true;
}
Player player = (Player) sender;
if (args.length == 0) {
player.setGameMode(GameMode.SURVIVAL);
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "Your gamemode is set to survival.");
return true;
}
@SuppressWarnings("deprecation")
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null) {
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "This player has not been found.");
return true;
}
target.setGameMode(GameMode.SURVIVAL);
target.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "Your gamemode is set to survival by " + player.getName());
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have succesfully set " + target.getName() + "'s gamemode to survival.");
return true;
}
if (cmd.getName().equalsIgnoreCase("creative")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "The console cannot run this command!");
return true;
}
Player player = (Player) sender;
if (args.length == 0) {
player.setGameMode(GameMode.CREATIVE);
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "Your gamemode is set to creative.");
return true;
}
@SuppressWarnings("deprecation")
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null) {
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "This player has not been found.");
return true;
}
target.setGameMode(GameMode.CREATIVE);
target.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "Your gamemode is set to creative by " + ChatColor.WHITE + player.getName());
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have succesfully set " + ChatColor.WHITE + target.getName() + ChatColor.GREEN + "'s gamemode to creative.");
return true;
}
if (cmd.getName().equalsIgnoreCase("adventure")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "The console cannot run this command!");
return true;
}
Player player = (Player) sender;
if (args.length == 0) {
player.setGameMode(GameMode.ADVENTURE);
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "Your gamemode is set to adventure.");
return true;
}
@SuppressWarnings("deprecation")
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null) {
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.RED + "This player has not been found.");
return true;
}
target.setGameMode(GameMode.ADVENTURE);
target.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "Your gamemode is set to adventure by " + ChatColor.WHITE + player.getName());
player.sendMessage(ChatColor.GOLD + "[Geek Essentials] " + ChatColor.GREEN + "You have succesfully set " + ChatColor.WHITE + target.getName() + ChatColor.GREEN + "'s gamemode to adventure");
return true;
}
return true;
}
}
這裏是plugin.yml:
name: GeekEssentials
main: me.knightgeek.geekessentials.Main
author: KnightGeek
description: The essentials plugin for GeekCraft.
version: 1.0
commands:
heal:
usage: /<command>
description: Heals a player.
feed:
usage: /<command>
description: Feeds a player.
survival:
usage: /<command>
description: Sets your gamemode to survival.
creative:
usage: /<command>
description: Sets your gamemode to creative.
adventure:
usage: /<command>
description: Sets your gamemode to adventure.
這裏的問題是,它給了我未知的命令文本。當使用/冒險命令時,它給了我這個。所有其他命令都可以正常工作。我已經重寫了這個命令的代碼,但仍然沒有找到解決的辦法。
也許有人知道我在做什麼錯在這裏? P.S .:縮進是錯誤的,我知道。這是因爲我不得不重新縮進所有東西,而我並沒有打算這麼做。在Eclipse中它縮進就像它應該。
找到解決方案: 我把它保存爲一個禁用的插件,我也做了。所以我無法使用它。 **我真笨!** –