Tradeshop / TradeShop

Unique, new, powerful Minecraft TradeShop plugin!
https://tradeshop.github.io
Apache License 2.0
25 stars 11 forks source link

1.14.1 Could Not Pass InventoryClickEvent #57

Closed smashedbotatos closed 5 years ago

smashedbotatos commented 5 years ago

General Troubleshooting

Hey there! Before you report a bug or suggest a new feature, please make sure to follow these steps first!

Template

Issue Type

Description

Knowing 1.14.1 isn't supported yet, I thought I would try it anyway. Hopefully this error will help you update to 1.14.1.

[19:01:04] [Server thread/ERROR]: Could not pass event InventoryClickEvent to TradeShop v2.0.0 org.bukkit.event.EventException: null at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:520) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:505) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:2158) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.PacketPlayInWindowClick.a(SourceFile:33) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.PacketPlayInWindowClick.a(SourceFile:10) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:13) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(SourceFile:135) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(SourceFile:114) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.MinecraftServer.aW(MinecraftServer.java:895) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:888) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(SourceFile:123) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:872) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:805) [minecraft_server.jar:git-Spigot-8043ebc-02b466c] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212] Caused by: java.lang.NoSuchMethodError: org.bukkit.inventory.Inventory.getName()Ljava/lang/String; at org.shanerx.tradeshop.listeners.CustomInventoryListener.onInventoryClick(CustomInventoryListener.java:40) ~[?:?] at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_212] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_212] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[minecraft_server.jar:git-Spigot-8043ebc-02b466c] ... 17 more

Credits & Disclaimer

This file contains parts that were taken from the JDA project. We do not wish to take credit for those parts. Everything is licensed under the Apache License v2.0.

SparklingComet commented 5 years ago

Thank you for the report. The cause seems to be the fact that certain portions of the Bukkit API were removed. Knowing this will most certainly be helpful when we start working on supporting 1.14.x.

Caused by: java.lang.NoSuchMethodError: 
org.bukkit.inventory.Inventory.getName()Ljava/lang/String;

at org.shanerx.tradeshop.listeners.CustomInventoryListener.onInventoryClick(CustomInventoryListener.java:40) ~[?:?]
KillerOfPie commented 5 years ago

Yea I was looking at that trying to think of new way to check the name of the inventory.

smashedbotatos commented 5 years ago

I switched your class around a little, just to test the new method and it works in 1.14.1

@EventHandler
    public void onInventoryClick(InventoryClickEvent event) {

        Inventory inventory = event.getInventory();

        if (ChatColor.stripColor(event.getView().getTitle()).endsWith("Shop                                 ")) {
            event.setCancelled(true);
        }
    }

I wasn't sure how to change the other method used, so i just commented out the else if statement. It was working perfectly with 1.14.1 other than the hopper bug. In CommandRunner class line 566.

else if (plugin.getListManager().isInventory(b.getType()) &&
                    ((InventoryHolder) b.getState()).getInventory().getName().contains("$ ^Sign:l_")) {

                ShopChest shopChest = new ShopChest(b.getLocation());
                return Shop.loadShop(shopChest.getShopSign());
            }

You can't get the name from an InventoryHolder any more. Here is a thread I found about getting the name of a chest inventory outside of an event using 1.14 api. Getting the inventory title.

EDIT - Maybe using this? https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Nameable.html#getCustomName--

Hopefully that helps :) Thank you for your update and hard work. I have been waiting for a long time!

KillerOfPie commented 5 years ago

Already knew about nameable, and i think we used it when we originally started setting names. However that post for the 1.14 chest is useful and ill probably switch everything over to BlockState#getName when i get home in an hour or two

KillerOfPie commented 5 years ago

Fixed in #60 @smashedbotatos I would appreciate it if you could test the PR for me, if you need a jar msg me on discord, KillerOfPie#9816.