Error on console when using Chestsort
kalebbroo opened this issue ยท 10 comments
Describe the bug
If I have items from Itemjoin in my inventory I will get an error on the console. error is in pastebin below.
To Reproduce
Steps to reproduce the behavior:
- add itemjoin item to chest.
- open and close chest so chestsort will stack/sort items.
- see error
Expected behavior
chestsort plugin sorts items and does not throw error
Pastebin
Error https://pastebin.com/hjsGq7JJ
Items.yml https://pastebin.com/a10DrsUZ
config.yml https://pastebin.com/fb2Db6j0
Please complete the following information:
- Resource Version and Build Number: 5.1.1-SNAPSHOT-b658
- Server Version Paper 1.16.5
Added. I also had it generate a new config with same result.
Latest snapshot should now fix this issue including your issue #357 .
Link; https://ci.craftationgaming.com/job/ItemJoin/660/
Remember to remove your old ItemJoin.jar file.
Further info (I am the author of ChestSort and already spoke to the user reporting this):
Used ChestSort version is latest 9.0.1
It happens everytime when the ChestSortEvent is called while an ItemJoin item is included in the inventory that is to be sorted. The error comes from a line where the ChestSortAPI isn't used.
Describe the bug
If I have items from Itemjoin in my inventory I will get an error on the console. error is in pastebin below.To Reproduce
Steps to reproduce the behavior:
- add itemjoin item to chest.
- open and close chest so chestsort will stack/sort items.
- see error
Expected behavior
chestsort plugin sorts items and does not throw errorPastebin
https://pastebin.com/hjsGq7JJPlease complete the following information:
- Resource Version and Build Number: 5.1.1-SNAPSHOT-b658
- Server Version Paper 1.16.5
Can you please provide your config.yml in a pastebin link.
Further info (I am the author of ChestSort and already spoke to the user reporting this):
Used ChestSort version is latest 9.0.1
It happens everytime when the ChestSortEvent is called while an ItemJoin item is included in the inventory that is to be sorted. The error comes from a line where the ChestSortAPI isn't used.
Issues seems to be coming from your event.getPlayer() method. Is this supposed to be returning null? If I fetch the inventory holder, the player instance event.getInventory().getViewers().get(0)
returns as a valid player.
Seems to be related to my prior post; mfnalex/ChestSort#100 (comment)
Except this only occurs when you sort the inventory, open a chest, drag around some items, and then close the chest.
ChestSortEvent#getPlayer is @nullable by design, see here: https://repo.jeff-media.de/javadocs/ChestSortAPI/de/jeff_media/ChestSortAPI/ChestSortEvent.html#getPlayer()
IIRC the getPlayer() method only returns a HumanEntity if a PlayerInventory is to be sorted. For normal chests, it always returns null. That might be a bit confusing, I might change that and/or update the API docs, but its clearly stated that getPlayer() may return null , both via API docs and via the @nullable annotation. Sorry for the confusion.
EDIT: Also sorry to the github user @nullable who is always linked whenever the annotation is mentioned, lol
ChestSortEvent#getPlayer is @nullable by design, see here: https://repo.jeff-media.de/javadocs/ChestSortAPI/de/jeff_media/ChestSortAPI/ChestSortEvent.html#getPlayer()
Ah okay, yeah it's a bit confusing since it should return a valid player instance any time a chest/inventory is sorted. Since the inventory holder itself returns the player instance.
I guess I will just implement my hacky method for now, for when it returns as null.
ChestSortEvent#getPlayer is @nullable by design, see here: https://repo.jeff-media.de/javadocs/ChestSortAPI/de/jeff_media/ChestSortAPI/ChestSortEvent.html#getPlayer()
Ah okay, yeah it's a bit confusing since it should return a valid player instance any time a chest/inventory is sorted. Since the inventory holder itself returns the player instance.
I guess I will just implement my hacky method for now, for when it returns as null.
Yeah sorry about that, I can totally understand the confusion. But you also have to keep in mind that its possible for other plugins to invoke the ChestSortEvent / call the ChestSortAPI#sortInventory method, so I can never guarantuee that a player is associated to that Event, that's why it's Nullable. However it's a good occasion to think about setting the player when a player sorts a container :)
This bug has been officially fixed in the release of ItemJoin v5.2.0.
You can grab it here; https://www.spigotmc.org/resources/itemjoin.12661/download?version=383801
Please read the changelog as the documentation has not been updated yet;
https://github.com/RockinChaos/ItemJoin/wiki/Recent-Changes