2017-06-15 89 views
-1

當我運行它時,My Bukkit插件命令始終引發異常。My Bukkit插件命令引發異常

當我輸入我的命令:/config set(它應該保存信息到文件/配置),我得到這個錯誤在聊天:當attemping執行此命令時

內部錯誤。

爲什麼會發生這種情況?

控制檯登錄:

[13:23:24 INFO]: whispereq issued server command: /config set 
[13:23:24 ERROR]: null 
org.bukkit.command.CommandException: Unhandled exception executing command 'config' in plugin registyPlayer v1.0 
     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 
     at whispereq.saver.onCommand(saver.java:14) ~[?:?] 
     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] 
     ... 13 more 

saver類我的代碼:

package whispereq; 
import org.bukkit.Bukkit; 
import org.bukkit.GameMode; 
import org.bukkit.command.Command; 
import org.bukkit.command.CommandExecutor; 
import org.bukkit.command.CommandSender; 
import org.bukkit.entity.Player; 

public class saver implements CommandExecutor { 
    @Override 
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { 
     if (cmd.getName().equalsIgnoreCase("config")) { 
      if (sender instanceof Player) { 
       if (args.length == 1) { 
        if (args[1].equalsIgnoreCase("set")) { 
         sender.sendMessage("§6Registering player§c " + args[0] + "§6 to Server...."); 
         Player p = (Player) sender; 
         String nick = p.getName().toLowerCase(); 
         String uid = p.getUniqueId().toString(); 
         boolean op = p.isOp(); 
         GameMode gm = p.getGameMode(); 
         GameMode dgm = Bukkit.getDefaultGameMode(); 
         float exp = p.getExp(); 
         float explvl = p.getExpToLevel(); 
         Main.getInst().getConfig().set("players." + nick + ".uuid", uid); 
         Main.getInst().getConfig().set("players." + nick + ".isOpped", op); 
         Main.getInst().getConfig().set("players." + nick + ".CurrentGameMode", gm); 
         Main.getInst().getConfig().set("players." + nick + ".DefaultGameMode", dgm); 
         Main.getInst().getConfig().set("players." + nick + ".Exp", exp); 
         Main.getInst().getConfig().set("players." + nick + ".ExpLevel", explvl); 
         Main.getInst().saveConfig(); 
         sender.sendMessage("§6Finished!, yours Current in-game Status was SUccesfully registered to the config.yml File in Plugin's Directory. use §c/registy getMe§6 to view your Property."); 
         return true; 
        } else if (args[1].equalsIgnoreCase("get")) { 
         Player p = (Player) sender; 
         String nick = p.getName().toLowerCase(); 
         if (Main.getInst().getConfig().get("players." + nick) != null) { 
          p.sendMessage("§8_____________________________________________________"); 
          p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".uuid")); 
          p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".isOpped")); 
          p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".CurrentGameMode")); 
          p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".DefaultGameMode")); 
          p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".Exp")); 
          p.sendMessage(Main.getInst().getConfig().getString("players." + nick + "ExpLevel")); 
          p.sendMessage("§8_____________________________________________________"); 
         } 
        } 
       } 
      } 
     } 
     return false; 
    } 
} 

Main類:

package whispereq; 

import org.bukkit.plugin.java.JavaPlugin; 

public class Main extends JavaPlugin { 
    public static Main instance; 

    public void onEnable() { 
     instance = this; 
     System.out.println("Loading RegistyPlayer .."); 
     getCommand("config").setExecutor(new saver()); 
     saveDefaultConfig(); 
    } 

    public static Main getInst() { 
     return instance; 
    } 
} 

配置文件(空):

#-----------------------------------------------------------# 

plugin.yml:

name: registyPlayer 
version: 1.0 
main: whispereq.Main 
commands: 
    config: 

Craftbukkit:1.7.2 R03

Bukkit API:1.7.2 R03

服務器Craftbukkit:1.7.2 R03

回答

1

陣列始終啓動因此,要訪問玩家是否指定「獲得」或「設置」,您應該替換

args[1].equalsIgnoreCase("set") 
args[1].equalsIgnoreCase("get") 

args[0].equalsIgnoreCase("set") 
args[0].equalsIgnoreCase("get") 

而且,不知道你是用線做什麼

sender.sendMessage("§6Registering player§c " + args[0] + "§6 to Server...."); 

ARGS [0]指的是 「GET」 或 「設置」。大概你應該用「nick」來代替它,然後插入該行

String nick = p.getName().toLowerCase(); 
+0

謝謝你的幫助! – whispereq