0

当我执行命令时,这段代码一直出错,我已经修复了一些变量错误,但仍然没有修复它。

谁能帮我吗?这是一个空指针,但我没有看到任何给出空值的东西。谢谢!

@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, 
    String label, String[]args){
    if(cmd.getName().equalsIgnoreCase("shop")){
        if(sender instanceof Player){
           Player p=(Player)sender;
           //all itemstack were made at the top given static
           ItemMeta lore=hasMoney.getItemMeta();//the amount of money they have set to a lore
           ArrayList<String> loreText=new ArrayList<String>();
           lore.setDisplayName(ChatColor.GOLD+""+ChatColor.BOLD+"Gears");
           loreText.add(ChatColor.GREEN+"You have:");

           loreText.add(ChatColor.GOLD
                        +econ.format(econ.getBalance(p.getName()))
                        +ChatColor.GREEN+"Gears");

           lore.setLore(loreText);
           hasMoney.setItemMeta(lore);

           switch(getConfig().getInt(p.getName() + ".helm", 0)){
           case 0:
               ItemMeta lorehelm=helm.getItemMeta();//current helmet they have
               helm.setType(Material.LEATHER_HELMET);
               ArrayList<String> loreTextHelm=new ArrayList<String>();

               lorehelm.setDisplayName(ChatColor.GOLD+""
                                                   +ChatColor.BOLD+"Helmet");

               loreTextHelm.add(ChatColor.GREEN+"You have:");
               loreTextHelm.add(ChatColor.GOLD+"Basic Helmet");
               lorehelm.setLore(loreTextHelm);
               helm.setItemMeta(lorehelm); 

               ItemMeta lorehelmn=nextHelm.getItemMeta();//this is next helmet to purchase
               nextHelm.setType(Material.GOLD_HELMET);
               ArrayList<String> loreTextHelmn=new ArrayList<String>();

               lorehelm.setDisplayName(ChatColor.GOLD+""+
                                                    ChatColor.BOLD+"Helmet");

               loreTextHelmn.add(ChatColor.GREEN+"Lvl 1 Helmet");
               loreTextHelmn.add(ChatColor.GOLD+"50 Gears");
               lorehelmn.setLore(loreTextHelmn);
               nextHelm.setItemMeta(lorehelmn); 

           case 1:
               ItemMeta lorehelm1=helm.getItemMeta();
               helm.setType(Material.GOLD_HELMET);

               helm.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);

               ArrayList<String> loreTextHelm1=new ArrayList<String>();

         lorehelm1.setDisplayName(ChatColor.GOLD+""+ChatColor.BOLD+"Helmet");

               loreTextHelm1.add(ChatColor.GOLD+"You have: ");
               loreTextHelm1.add(ChatColor.GOLD+"Lvl 1 Helmet");
               lorehelm1.setLore(loreTextHelm1);
               helm.setItemMeta(lorehelm1);         
        }
        myInventory.setItem(0, helm);
        myInventory.setItem(9, nextHelm);
        myInventory.setItem(23, hasMoney);

        p.openInventory(myInventory); 
        return true;}else if(sender instanceof ConsoleCommandSender){sender.sendMessage("You can't do that from here!");return true;}
        else{return false;}


    }//ive ended the oncommand later down 

这是错误:

org.bukkit.command.CommandException: Unhandled exception executing command 'shop' in plugin Gearbox_PvP v0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_71]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_71]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_71]
**Caused by: java.lang.NullPointerException
    at me.CoderBlazer.Main.onCommand(Main.java:129) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.8.jar:git-Spigot-db6de12-039621d]
    ... 15 more**

这是物品堆

static ItemStack hasMoney = new ItemStack(Material.YELLOW_FLOWER, 1);
 static ItemStack helm=new ItemStack(Material.LEATHER_HELMET, 1);
 static ItemStack nextHelm=new ItemStack(Material.GOLD_HELMET, 1);
4

1 回答 1

0

阅读后您可以找到错误出错的行,我追查到它与保险库有关。后来我发现我没有像 Essentials 这样的生态插件上钩!无论如何,感谢您的帮助,现在如果我有问题,我知道如何解决自己的问题。

于 2016-02-23T09:13:06.310 回答