RockinChaos / ItemJoin

Get custom items on join.
https://www.craftationgaming.com/
GNU Lesser General Public License v3.0
138 stars 36 forks source link

IndexOutOfBoundsException when using ChestSort #503

Closed mfnalex closed 1 year ago

mfnalex commented 1 year ago

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:

  1. Install ChestSort, give yourself "chestsort.use" permission, and enable the "left click container to sort" hotkey in /chestsort
  2. Left-click a chest
  3. 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.

https://github.com/RockinChaos/ItemJoin/blob/6680362f0cb1f51cb72eb6990417a078a2968afe/src/me/RockinChaos/itemjoin/listeners/plugins/ChestSortAPI.java#L41

RockinChaos commented 1 year ago

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.

mfnalex commented 1 year ago

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

RockinChaos commented 1 year ago

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!~

RockinChaos commented 1 year ago

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.

mfnalex commented 1 year ago

Yes, sure. However not right now, I don't have much time at the moment. Pull requests are of course welcome.

RockinChaos commented 1 year ago

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.