NewbieOrange / clicksort

Minecraft Bukkit plugin to sort inventories with a simple mouse click
https://dev.bukkit.org/projects/clicksort
Other
13 stars 5 forks source link

Fix parsing of item type to string #2

Closed minoneer closed 3 years ago

minoneer commented 3 years ago

This is no longer needed since all item variants have their own Material since 1.13. It also causes a class cast exception because spawn eggs now use the default ItemMeta instead of SpawnEgg.

minoneer commented 3 years ago

For reference:

[13:23:03 WARN]: [ClickSort] Task #5102093 for ClickSort v1.4.2 generated an exception
java.lang.ClassCastException: class org.bukkit.material.MaterialData cannot be cast to class org.bukkit.material.SpawnEgg (org.bukkit.
material.MaterialData and org.bukkit.material.SpawnEgg are in unnamed module of loader 'app')
        at cn.citycraft.PluginHelper.utils.LocalUtil.getItemType(LocalUtil.java:54) ~[?:?]
        at cn.citycraft.PluginHelper.utils.LocalUtil.getItemName(LocalUtil.java:34) ~[?:?]
        at me.desht.dhutils.ItemNames.lookup(ItemNames.java:37) ~[?:?]
        at me.desht.clicksort.SortingMethod.makeSortPrefix(SortingMethod.java:60) ~[?:?]
        at me.desht.clicksort.SortKey.<init>(SortKey.java:22) ~[?:?]
        at me.desht.clicksort.ClickSortPlugin.sortAndMerge(ClickSortPlugin.java:426) ~[?:?]
        at me.desht.clicksort.ClickSortPlugin.sortInventory(ClickSortPlugin.java:372) ~[?:?]
        at me.desht.clicksort.ClickSortPlugin.access$000(ClickSortPlugin.java:44) ~[?:?]
        at me.desht.clicksort.ClickSortPlugin$1.run(ClickSortPlugin.java:229) ~[?:?]
        at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:99) ~[patched_1.16.4.jar:git-Paper-325]
        at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:468) ~[patched_1.16.4.jar:
git-Paper-325]
        at net.minecraft.server.v1_16_R3.MinecraftServer.b(MinecraftServer.java:1294) ~[patched_1.16.4.jar:git-Paper-325]
        at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:377) ~[patched_1.16.4.jar:git-Paper-325]
        at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1209) ~[patched_1.16.4.jar:git-Paper-325]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:997) ~[patched_1.16.4.jar:git-Paper-325]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:178) ~[patched_1.16.4.jar:git-Paper-325]
        at java.lang.Thread.run(Thread.java:834) [?:?]
NewbieOrange commented 3 years ago

Thanks for your contribution!

Is there any reason to remove the previous line appending durability to the result?

 dura = (i.getMaxStackSize() != 1 && dur != 0) ? Integer.toString(dur) : "";

The line was intended to keep a stable order for items with same material but different durability.

Edit: which means that two swords damaged differently will always have the same order after sorting.

NewbieOrange commented 3 years ago

It would be nice if you could replace the durability part with the new Damageable interface, so the sorting result will be stable.

minoneer commented 3 years ago

Damageable is only implemented by tools, which were explicitly excluded from being sorted by their damage (see the getMaxStackSize() != 1). Therefore it should be stable by just removing it completely.

NewbieOrange commented 3 years ago

Merged. Thanks again for your contribution!