Solved GUI/Inventory help!

Discussion in 'Spigot Plugin Development' started by JustCedric, May 16, 2016.

  1. Hi guys,

    I'm making a plugin but I need some help. How do you register an inventory click in your own inventory when you're in a GUI.

    For example: I'm in a GUI called 'Test GUI' and I left click a diamond block in my own inventory and then want to send the player who clicked 'Well done you've clicked a diamond block'

    [​IMG]
     
    #1 JustCedric, May 16, 2016
    Last edited: May 17, 2016
  2. I am guessing you would check the inventory of the player, instead of the gui inventory
     
  3. I want it to only work when you're in a specific GUI
     
  4. You can check this with the method getClickedInventory();
     
  5. Yeah but I only want to get the message when you're in a specific GUI called 'Test GUI'
     
    #5 JustCedric, May 16, 2016
    Last edited: May 16, 2016
  6. How to check if they are in Test Gui
    Code (Text):
    if (player.getOpenInventory().getTopInventory().getTitle().equals("Test GUI")) {
        //Code for what to do if the Test GUI inventory is open
    }
     
    #6 SimPlaysGames, May 16, 2016
    Last edited: May 16, 2016
    • Agree Agree x 1
  7. Code (Text):
    if (e.getInventory().getName().equalsIgnoreCase(ChatColor.DARK_AQUA + "Test GUI")) {
    }
    This is the code I use.
     
    • Agree Agree x 1
  8. That would normally work fine, but he wants to check of the top section is the one not being clicked. So, @SimPlaysGames is correct.
     
  9. still doesn't work, this is my code rn.
    Code (Text):
                if (p.getOpenInventory().getTopInventory().getTitle().equals(ChatColor.DARK_AQUA + "Totale waarde: " + ChatColor.AQUA + "€ " + instance.playerConfig.getInt(UUID + ".money"))) {
                    if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Diamond Block")) {
                        int amount = e.getCurrentItem().getAmount();
                        System.out.println(p.getName() + " clicked on " + amount + " diamond block(s)!");
                    }
                }
    and get this error when I click on a diamond block in my own inventory.
    Code (Text):
    [10:36:22 ERROR]: Could not pass event InventoryClickEvent to MinecraftRP v1.0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_80]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_80]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at java.lang.Thread.run(Unknown Source) [?:1.7.0_80]
    Caused by: java.lang.NullPointerException
            at nl.locano.rp.atm.ATM.onInventoryClick(ATM.java:150) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1
    Line 150:
    Code (Text):
                if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Block of Diamond")) {
     
    #9 JustCedric, May 16, 2016
    Last edited: May 16, 2016

  10. Try this instead

    Code (Text):
                if (p.getOpenInventory().getTopInventory().getTitle().equals(ChatColor.DARK_AQUA + "Totale waarde: " + ChatColor.AQUA + "€ " + instance.playerConfig.getInt(UUID + ".money"))) {
                    if (e.getCurrentItem.hasItemMeta && e.getCurrentItem().getItemMeta().getDisplayName().contains("Diamond Block")) {
                        int amount = e.getCurrentItem().getAmount();
                        System.out.println(p.getName() + " clicked on " + amount + " diamond block(s)!");
                    }
                }
     
  11. Still get this error..
    Code (Text):
    [11:46:07 ERROR]: Could not pass event InventoryClickEvent to MinecraftRP v1.0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_80]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_80]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            at java.lang.Thread.run(Unknown Source) [?:1.7.0_80]
    Caused by: java.lang.NullPointerException
            at nl.locano.rp.atm.ATM.onInventoryClick(ATM.java:150) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_80]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_80]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_80]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_80]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261]
            ... 15 more
     
  12. Which line is line 150?
     
  13. ATM.java:150

    show us that line please.
     
  14. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Block of Diamond")) {
     
  15. Check if e.getCurrentItem() is null

    Verstuurd vanaf mijn A0001 met Tapatalk
     
  16. Already did that

    Code (Text):
                if (e.getCurrentItem() == null) return;
     
  17. Did you do this?

    Code (Text):
                    if (e.getCurrentItem.hasItemMeta && e.getCurrentItem().getItemMeta().getDisplayName().contains("Diamond Block")) {
     
  18. yup
    [​IMG]
     
  19. See if you can print a string of the object and see if it actually prints anything. Then you'll know for sure if it's null or not. If it isn't null, then maybe the itemMeta is (not likely), but it doesn't hurt to try.
     
  20. I get this rn if I click on the diamond block in GUI

    [12:45:46 ERROR]: Could not pass event InventoryClickEvent to MinecraftRP v1.0.1 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_80] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_80] at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] at java.lang.Thread.run(Unknown Source) [?:1.7.0_80] Caused by: java.lang.NullPointerException at nl.locano.rp.atm.ATM.onInventoryClick(ATM.java:152) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_80] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_80] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_80] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_80] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-6c9b0a1-de5c261] ... 15 more [12:45:46 INFO]: No Item Meta