InventoryClickEvent error.

Discussion in 'Plugin Development' started by RiverShara, Jan 15, 2020.

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


    Hello, I am currently trying to get a inventory aka gui to work in minecraft and I updated to 1.14.4 and I am still relatively new to java and would like some assistance on figuring this out. So basically, I am using multiple classes to get inventories to work and the inventory opens just fine. It just gives me a InventoryClickEvent error which should boil down to the EventsClass, where I created the InventoryClickEvent. Here is the code so you can look through it:

    Note: I am trying to use this to make a healing/food inventory. If you click health, it reheals. I took out the food while I was refixing it. What happens with this error in general is not close the inventory like it's suppose to and doesn't heal like it's suppose to. I also made it show me in a ItemStack on what my health was. Keep that in mind.

        public void InvenClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            Inventory open = event.getClickedInventory();
            ItemStack item = event.getCurrentItem();
            if (open == null) {
            if(((CommandSender) open).getName().equals(ChatColor.RED + "Test Inventory")) {
                if (item.equals(null) || !item.hasItemMeta()) {
                if (item.getItemMeta().getDisplayName().equals(ChatColor.RED + "HEALTH")) {
                    CustomInventory ci = new CustomInventory();
    I currently suppressed the warnings while I was working on it. I will post the error after I give the other code.

    public class CustomInventory implements Listener {
        private Plugin plugin = Beginning.getPlugin(Beginning.class);
        public void newInventory(Player player) {
            Inventory inv = plugin.getServer().createInventory(null, 9, ChatColor.RED + "Test Inventory");
            int healthint = (int) player.getHealth();
            ItemStack empty = new ItemStack(Material.GLASS, 1);
            ItemMeta emptyMeta = empty.getItemMeta();
            ItemStack health = new ItemStack(Material.APPLE, healthint);
            ItemMeta hmeta = health.getItemMeta();
            hmeta.setDisplayName(ChatColor.RED + "HEALTH");
            inv.setItem(0, empty);
            inv.setItem(1, empty);
            inv.setItem(2, empty);
            inv.setItem(3, health);
            inv.setItem(4, empty);
            inv.setItem(5, empty);
            inv.setItem(6, empty);
            inv.setItem(7, empty);
            inv.setItem(8, empty);
    This is the CustomInventory where all the items for the inventory lies.

                if (cmd.getName().equalsIgnoreCase(cmd5)) {
                    Player player = (Player) sender;
                    CustomInventory inv = new CustomInventory();
                    return true;
            } else {
                sender.sendMessage(ChatColor.RED + "Only players can use this command!");
                return true;
    This is the Commands class, this is where my command takes place to get the inventory to run via commands.

    Sorry if this is a bit dirty, not trying to confuse or anything but here is the error:

    15.01 23:08:17 [Server] Server thread/ERROR Could not pass event InventoryClickEvent to Beginning v2.0
    15.01 23:08:17 [Server] INFO org.bukkit.event.EventException: null
    15.01 23:08:17 [Server] INFO at$1.execute( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.PlayerConnection.a( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.PacketPlayInWindowClick.a(SourceFile:33) ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.PacketPlayInWindowClick.a(SourceFile:10) ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.MinecraftServer.aX( [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext( [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick( [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at [spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO at [?:1.8.0_222]
    15.01 23:08:17 [Server] INFO Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCustom cannot be cast to org.bukkit.command.CommandSender
    15.01 23:08:17 [Server] INFO at me.logan.Beginning.Events.EventsClass.InvenClick( ~[?:?]
    15.01 23:08:17 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_222]
    15.01 23:08:17 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_222]
    15.01 23:08:17 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_222]
    15.01 23:08:17 [Server] INFO at java.lang.reflect.Method.invoke( ~[?:1.8.0_222]
    15.01 23:08:17 [Server] INFO at$1.execute( ~[spigot-1.14.4.jar:git-Spigot-56f8471-7554e08]
    15.01 23:08:17 [Server] INFO ... 17 more
    Sorry if this is a lot but this is the error. I will tell you what I think it is so maybe it can help you. When I made the changes, the main thing that was coming up was from the InventoryClickEvent. The code was this:
    if(((CommandSender) open).getName().equals(ChatColor.RED + "Test Inventory")) Before it was this: if(open.getName().equals(ChatColor.RED + "Test Inventory"))

    It told me that it wouldn't work so I changed it to a CommandSender, I also tried changing the CommandSender to a player as well but didn't work. It's all suppose to just close after I healed myself and not let me take items out either. Sorry for making this super long for just (a probably) tedious error. If anyone can help, I would appreciate it since I don't wanna be discouraged if it doesn't work. Anyways.. Thank you! If there is anything else you need me to change or say, please let me know.
  2. Offline

    timtower Moderator Moderator

    (CommandSender) open)
    Why are you casting an inventory?
  3. Offline


    @timtower He probably wants to get the name of the inventory.

    @RiverShara Use InventoryClickEvent#getView()#getTitle() to get the inventory name.
    Strahan likes this.
  4. Offline


    @KarimAKL when I do that, InventoryClickEvent doesn't seem to wanna grab that. It only wants to grab the handler list or just the class. So I am not sure what I am doing wrong.
  5. Offline


    @RiverShara I was guessing that you build against 1.14 because of the log but, is that really the case? What're you building against?
  6. Offline


    @KarimAKL sorry for the late response, I am building on 1.14 yes, that would be the api version I am currently using. I am originally starting using 1.11.2 but I wanted to update to something more substantial.
  7. Offline


    Well.. yea, you can't just cast willy-nilly and expect it to work. Suppressing the compiler's warnings is typically not smart; it knows better than you what will and won't work, so if it sees something sketchy it warns you. You're better off investigating what it's complaining about rather than just telling it to shut up.


    Just to be clear, you said you built against 1.14 but started using 1.11.2. I assume nothing in your chain is still 1.11.2 right? Not the server, not the API, not the client? As to the problem using the view you alluded to, post the code that isn't working. Are you calling it from an InventoryClickEvent for example?
Thread Status:
Not open for further replies.

Share This Page