IndexOutOfBoundsException when using ChestSort
mfnalex opened this issue · 6 comments
Thanks for taking the time to open a bug report!
Describe the bug
When ChestSort sorts an inventory that does not have any viewers (e.g. by clicking on a chest while having that hotkey enabled (/sort)), your ChestSort listener throws an IndexOutOfBoundsException.
To Reproduce
Steps to reproduce the behavior:
- Install ChestSort, give yourself "chestsort.use" permission, and enable the "left click container to sort" hotkey in /chestsort
- Left-click a chest
- See below error
Pastebin
https://pastebin.com/dTmgfHXT
Additional context
The problem is that you call get(0) in line 41 of your listener. However, ChestSort can also sort inventories without any viewers.
Ah, I see, thanks for letting me know.
Yeah, ItemJoin requires a player instance in order to check and compare items to verify an item needs to be set as unmovable so it requires a player instance to function.
I am working on this now.
Thanks! I could also adjust ChestSort to always return a Player object, if thats needed. IIRC it right now only returns one if the player sorts their own inventory. Don‘t ask me why, ahaha
Okay, so I have been having computer issues so I am just getting to this issue.
For compatibility reasons I would greatly appreciate it if you could adjust ChestSort to always return a Player object. This way it makes it so I can support legacy ChestSort versions without any major breakage.
Let me know if that is okay!~
Thanks! I could also adjust ChestSort to always return a Player object, if thats needed. IIRC it right now only returns one if the player sorts their own inventory. Don‘t ask me why, ahaha
@mfnalex
Hi, apologies for the ping.
Is this something you could add? In the case of ItemJoin, it is a requirement to have the Player object to prevent specific items from being sorted for that player. Achieving the player instance elsewhere has been tested and is quite unreliable so if it's possible for you to implement the Player object to always return a valid player that would be fantastic.
Yes, sure. However not right now, I don't have much time at the moment. Pull requests are of course welcome.
Marking this as resolved as I simply added a check to skip checking if the player returns null.
This simply just disables ItemJoin's capabilities so if you get the chance to implement a way to always return the player that would be great.
As for now, the error message will no longer appear.