Abnormal Plugin Type

Discussion in 'Plugin Development' started by pigeontroll, Mar 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    pigeontroll

    I have an issue with my plugin. It's basically a KitPVP plugin and you do /kit to open up a GUI. When I start it, it gives me a command exception error.

    Code:
    [19:38:29 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'kit'
    in plugin CookieKit v1.0.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
    Caused by: java.lang.NullPointerException
            at me.pigeontroll.cookiekit.CookieKit.onCommand(CookieKit.java:60) ~[?:?
    ]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
            ... 13 more
    >
    Here's the code:
    Code:java
    1. public class CookieKit extends JavaPlugin implements Listener {
    2.  
    3. private Inventory inv;
    4. private ItemStack stick;
    5. private CookieKit ck;
    6.  
    7.  
    8. public void onEnable() {
    9. inv = Bukkit.getServer().createInventory(null, 9, "CookieKits");
    10.  
    11. stick = createItem(DyeColor.CYAN, ChatColor.GOLD+"Stick");
    12.  
    13. inv.setItem(1, stick);
    14.  
    15. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    16. }
    17.  
    18. private ItemStack createItem(DyeColor dc, String name) {
    19. ItemStack i = new Wool(dc).toItemStack(1);
    20. ItemMeta im = i.getItemMeta();
    21. im.setDisplayName(name);
    22. im.setLore(Arrays.asList("Click here to get the ", name +" kit."));
    23. i.setItemMeta(im);
    24. return i;
    25. }
    26.  
    27. public void show(CommandSender p) {
    28. ((Player) p).openInventory(inv);
    29. }
    30.  
    31. public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
    32. if (cmd.getName().equalsIgnoreCase("kit")) {
    33. if (!(sender instanceof Player)) {
    34. sender.sendMessage(ChatColor.RED+"A player is expected.");
    35. return true;
    36. }
    37. ck.show(sender);
    38. return true;
    39. }
    40. return true;
    41.  
    42. }
    43. @EventHandler
    44. public void onInventoryClick(InventoryClickEvent e) {
    45. Inventory pi = e.getInventory();
    46. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
    47. if (e.getCurrentItem().getItemMeta() == null) return;
    48. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(ChatColor.stripColor("stick"))) {
    49. e.setCancelled(true);
    50. e.getWhoClicked().closeInventory();
    51.  
    52. ItemStack stick = new ItemStack(Material.STICK, 1);
    53. stick.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 4);
    54. ItemMeta stickmeta = stick.getItemMeta();
    55. stickmeta.setDisplayName(ChatColor.RED+""+ChatColor.BOLD+"Sharp Stick");
    56. List<String> sticklore = new ArrayList<String>();
    57. sticklore.add(ChatColor.GREEN + "Teach your enemies a");
    58. sticklore.add(ChatColor.GREEN + "lesson with this sharp stick!");
    59. stickmeta.setLore(sticklore);
    60. stick.setItemMeta(stickmeta);
    61. pi.setItem(3, stick);
    62. pi.setItem(8, new ItemStack(Material.COOKED_BEEF, 8));
    63.  
    64. }
    65. }
    66.  
    67. }
    68.  

    Thanks in advance!
     
  2. Offline

    ImPhantom

    Do you not have an onEnable and onDisable method in your main class?
     
  3. Offline

    __Sour

    pigeontroll
    You didn't make a onEnable and onDisable meathod without this your plugin wont work.
     
  4. Offline

    Rocoty

    __Sour That is not true. The plugin works completely fine without overriding any of those methods (because even though you don't expliitly override them, they are still there, but hidden and empty.)
     
    mine-care likes this.
  5. Offline

    pigeontroll

    Rocoty __Sour ImPhantom I think it should still work, as Rocoty said. But if so, is that why it gives an Abnormal Plugin Type?
     
  6. Offline

    Axe2760

    __Sour Not true at all.

    pigeontroll i believe the problem is what your constructor being there. instead of putting the code in the constructor, override onEnable() and put that code there. (Remove the constructor you defined!) In the stacktrace the error was in instantiating the class, probably because it's done with reflection and the Constructor object has to be exact to the normal. So again... just remove the constructor you defined, and put the code in the onEnable(), it should solve your problems.
     
  7. Offline

    pigeontroll

    I'm sorry, I'm new to Java, so what should I do? Like:
    Code:java
    1. @Override
    2. public void onEnable() {
    3. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    4. }

    And then remove the one inside the "public CookieKit() {}"? Axe2760
     
  8. Offline

    Axe2760

    pigeontroll
    Yep you would, no worries :D you could put the other code inside too:
    Code:
    public void onEnable(){
            inv = Bukkit.getServer().createInventory(null, 9, "CookieKits");
     
            stick = createItem(DyeColor.CYAN, ChatColor.GOLD+""+ChatColor.BOLD+"Stick");
            gun = createItem(DyeColor.CYAN, ChatColor.GOLD+""+ChatColor.BOLD+"Gun");
            cookie = createItem(DyeColor.CYAN, ChatColor.GOLD+""+ChatColor.BOLD+"Cookie");
            gatling = createItem(DyeColor.CYAN, ChatColor.GOLD+""+ChatColor.BOLD+"Gatling");
     
            inv.setItem(0, stick);
            inv.setItem(1, gun);
            inv.setItem(2, cookie);
            inv.setItem(3, gatling);
     
            Bukkit.getServer().getPluginManager().registerEvents(this, p);
    }
    
     
  9. Offline

    pigeontroll

    Axe2760
    Thanks man! It works! But now when I try the actual plugin and execute /kit, it doesn't work anymore. Perhaps you can help? I have updated the post.
     
  10. Offline

    Axe2760

    pigeontroll awesome sauce! :D about the command...

    Is there an error? Or does it just not work? If it fires but it doesn't work, the cookie kit class may be helpful :p
     
  11. Offline

    Wolfey

    Actually, the plugin WILL load without the onEnable().
     
  12. Offline

    Axe2760


    Yes...it will? :p Thus why I told sour "Not true at all." :confused:
     
  13. Offline

    Wolfey

    Oh, my bad, tagged the wrong person!
     
  14. Offline

    xTrollxDudex

    pigeontroll
    No one here is correct.

    Your actual problem is you are using an unassigned field (auto null pointer). In fact, don't eve use ck.show(sender) just use show(sender). It gets much more complex if you use an instance field of your own class.
     
Thread Status:
Not open for further replies.

Share This Page