Companion to #92. With executing now reset in SimpleBehaviorController.clear(), the immediate crash is gone, but Selector.RANDOM_SELECTION still throws IllegalArgumentException: bound must be positive if getBehaviors() is empty when getNextBehavior runs:
https://github.com/CitizensDev/CitizensAPI/blob/master/src/main/java/net/citizensnpcs/api/ai/tree/Selector.java#L109-L110
private static final Function<List<Behavior>, Behavior> RANDOM_SELECTION = behaviors -> behaviors
.get(RANDOM.nextInt(behaviors.size()));
Random.nextInt(0) blows up. Selector.run() already handles a null return cleanly:
if ((executing = getNextBehavior()) == null)
return BehaviorStatus.FAILURE;
So an isEmpty() short-circuit would defang any future bug of this shape:
private static final Function<List<Behavior>, Behavior> RANDOM_SELECTION = behaviors -> behaviors.isEmpty()
? null
: behaviors.get(RANDOM.nextInt(behaviors.size()));
Same idea for any other selectionFunction that indexes by Random.nextInt(size()).
Companion to #92. With
executingnow reset inSimpleBehaviorController.clear(), the immediate crash is gone, butSelector.RANDOM_SELECTIONstill throwsIllegalArgumentException: bound must be positiveifgetBehaviors()is empty whengetNextBehaviorruns:https://github.com/CitizensDev/CitizensAPI/blob/master/src/main/java/net/citizensnpcs/api/ai/tree/Selector.java#L109-L110
Random.nextInt(0)blows up.Selector.run()already handles a null return cleanly:So an
isEmpty()short-circuit would defang any future bug of this shape:Same idea for any other
selectionFunctionthat indexes byRandom.nextInt(size()).