2017-03-04 117 views
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中它縮進就像它應該。

+0

找到解決方案: 我把它保存爲一個禁用的插件,我也做了。所以我無法使用它。 **我真笨!** –

回答

0

歐普對他的解決方案進行了評論,並給出了答案,因爲它可能有助於未來的用戶。


這種情況是由於您的插件沒有被導出爲您期望的插件導致的。

您正在將其導出爲不同的jar文件,它不在您的服務器文件夾中,因此您無法測試添加到該插件的任何新代碼。

解決這一很簡單:

當出口從Eclipse的插件,確保你把它保存在正確的jar文件,作爲服務器將只讀取plugins目錄裏面的插件。