GUI problems

Discussion in 'Plugin Development' started by diamondcodes, Sep 19, 2014.

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

    diamondcodes

    So I am making a kits plugin and I am getting 2 errors.

    The first error is when I click on a empty slot in my inventory or the GUI (Or take a block from the creative menu and put it in my inventory(Have not tried with chests/furnaces)):
    Code:
    [00:22:33] [Server thread/ERROR]: Could not pass event InventoryClickEvent to kits v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1361) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInWindowClick.a(SourceFile:32) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInWindowClick.handle(SourceFile:10) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
    Caused by: java.lang.NullPointerException
        at me.nite.kits.Listeners.ClickInv.onClick(ClickInv.java:67) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        ... 13 more
    
    Second error is when I throw a item out of my Inventory (either in the GUI or just in my Inventory before I click the paper), also when I click anywhere outside of the my the Inventory/GUI when after clicking the paper

    Code:
    [00:26:58] [Server thread/ERROR]: Could not pass event InventoryCreativeEvent to kits v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1483) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInSetCreativeSlot.a(SourceFile:23) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInSetCreativeSlot.handle(SourceFile:9) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
    Caused by: java.lang.NullPointerException
        at me.nite.kits.Listeners.ClickInv.onClick(ClickInv.java:64) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit-1.7.2-R0.4-20140212.071124-2.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3022jnks]
        ... 13 more
    
    Here is my Listener class where I believe all the errors are happening:

    Code:java
    1. package me.dc.kits.Listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.inventory.InventoryClickEvent;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.inventory.Inventory;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15.  
    16. import java.util.Arrays;
    17.  
    18. public class ClickInv implements Listener {
    19.  
    20. Inventory inv = Bukkit.createInventory(null, 27, ChatColor.GOLD + "" + ChatColor.BOLD + "Select your kit!");
    21.  
    22. @EventHandler
    23. public void onPlayerInteract(PlayerInteractEvent e) {
    24. Player player = e.getPlayer();
    25.  
    26. ItemStack kit1 = new ItemStack(Material.COAL);
    27. ItemMeta kit1meta = kit1.getItemMeta();
    28. kit1meta.setDisplayName(ChatColor.RED + "Kit: 1");
    29. kit1meta.setLore(Arrays.asList(ChatColor.AQUA + "Price coming soon!"));
    30.  
    31. kit1.setItemMeta(kit1meta);
    32.  
    33. ItemStack kit2 = new ItemStack(Material.COAL);
    34. ItemMeta kit2meta = kit2.getItemMeta();
    35. kit2meta.setDisplayName(ChatColor.RED + "Kit: 2");
    36. kit2meta.setLore(Arrays.asList(ChatColor.AQUA + "Price coming soon!"));
    37.  
    38. kit2.setItemMeta(kit2meta);
    39.  
    40. inv.setItem(0, kit1);
    41. inv.setItem(1, kit2);
    42.  
    43. if (player.getInventory().getItemInHand().getType() != Material.PAPER) return;
    44.  
    45. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.PAPER) {
    46.  
    47. player.openInventory(inv);
    48. }
    49. }
    50.  
    51. @EventHandler
    52. public void onClick(InventoryClickEvent event) {
    53.  
    54. if (!event.getCurrentItem().hasItemMeta())
    55. event.setCancelled(false);
    56. ItemMeta meta = event.getCurrentItem().getItemMeta();
    57. if (!meta.hasDisplayName())
    58. event.setCancelled(false);
    59.  
    60. if (event.getCurrentItem().hasItemMeta()) {
    61. if (event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "Kit: 1")) {
    62. event.setCancelled(true);
    63. event.getWhoClicked().closeInventory();
    64. }
    65.  
    66. }
    67. }
    68. }
    69.  
     
  2. Offline

    xTrollxDudex

    Possibly because the current item is null?
     
  3. Offline

    thomasb454

    This isn't going to directly answer your question and you may wish to continue with what you're doing, however I really suggest that you use "AMPMenus" click me for the GitHub and me for the Bukkit post.

    Enjoy
     
  4. Offline

    megamichiel

    before checking what the item is, add this:
    Code:
    if(event.getCurrentItem().getType() != null) {
    The console gives nullPointerExceptions that are probably caused by if the item isnt null
     
  5. Offline

    fireblast709

    megamichiel The type will never be null. However, getCurrentItem() might be.
     
  6. Offline

    megamichiel

    fireblast709 Ye, I wasn't sure though if it was getType() that would be null or getCurrentItem()
     
Thread Status:
Not open for further replies.

Share This Page