bergerhealer / BKCommonLib

An extensive library used in bergerhealer's plugins
Other
181 stars 45 forks source link

Index out of bounds #142

Closed Stogalosu closed 1 year ago

Stogalosu commented 2 years ago
BkCommonLib version: 1.18.2-v2
Spigot version: 1.18.1-R0.1

Problem or bug: When creating a new method in a class that extends MapWidgetTabView and calling setSelectedIndex() inside of it, I receive error Index out of bounds, but when calling it inside an already defined method like onAttached() or onRightClick(), it works just fine

Code.txt Error.txt

bergerkiller commented 2 years ago

Youre trying to use bukkit event handlers inside a map widget, something that isn't really supported. Are you sure the event is fired for a valid widget instance, and not one that has been detached / removed? Check by comparing

System.out.println(System.identityHashCode(this));

in onAttached vs your event handler.

Your error points towards an onTick but your code sample has none.

-

Instead of handling bukkit events in widgets, handle them in your own plugin event listener. You can use the static MapDisplay methods to get the instance of your display. To propagate events to the focused widgets, theres a sendStatusChange method, and a similar onStatusChanged method you can override in your widget.

bergerkiller commented 2 years ago

If events are firing for a detached/invalid listener, then most likely getTabCount() is 0, explaining the error.

And if you really want a listener in there, register it in onAttached() and use this method to unregister the listener in onDetached():

https://github.com/bergerhealer/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/utils/CommonUtil.java#L1012

bbayu123 commented 1 year ago

Closing issue, invalid issue - not a BKCommonLib problem in the first place.