Solved Inventory Click [Need Help]

Discussion in 'Plugin Development' started by Josh014, Nov 28, 2013.

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

    Josh014

    Hey,
    So I have a custom inventory everything works in it but I keep getting an error in the console what says there is a problem with the:
    Code:java
    1. if(ItemName.contains(PlayerTab)){


    I use this to try to get rid of the error:
    Code:java
    1. if(event.getCurrentItem().getItemMeta() == null) return;


    But I still keep getting an error in the console. How can I remove this error?

    My code:
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event){
    3. Player player = (Player) event.getWhoClicked();
    4. PlayerInventory pi = player.getInventory();
    5. Inventory inv = event.getInventory();
    6. String ItemName = event.getCurrentItem().getItemMeta().getDisplayName();
    7.  
    8. String PlayerTab = ChatColor.AQUA + "Player Information";
    9. String ShopTab = ChatColor.GREEN + "Shop";
    10.  
    11. if(event.getInventory().getType() == InventoryType.CHEST){
    12. event.setCancelled(true);
    13.  
    14. if(event.getCurrentItem().getItemMeta() == null) return;
    15.  
    16. //Start Inv
    17. if(ItemName.contains(PlayerTab)){
    18. player.openInventory(PlayerInfo);
    19. player.closeInventory();
    20. }
    21. if(ItemName.contains(ShopTab)){
    22. player.openInventory(Shop);
    23. player.closeInventory();
    24. }
    25.  
    26. }
    27. }


    Thank you,
     
  2. Offline

    inventorman101

    Josh014
    Paste the StackTrace of you error so we can help you :)
     
  3. Offline

    Josh014

    inventorman101
    Yea sorry forgot that ;3
    Code:
    19:52:07 [SEVERE] Could not pass event InventoryClickEvent to WiPlugin v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java
    :1383)
            at net.minecraft.server.v1_6_R3.Packet102WindowClick.handle(SourceFile:3
    1)
            at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java
    :116)
            at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5
    92)
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:2
    27)
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:4
    88)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :421)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    Caused by: java.lang.NullPointerException
            at me.Josh014.iPlugin.Shop.onInventoryClick(Shop.java:183)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
            ... 14 more
    >
    inventorman101
    Nvm I solved it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  4. Offline

    GreatMinerZ

Thread Status:
Not open for further replies.

Share This Page