Are you compiling a JAR? Most likely, you're hitting a Janino issue there.
But mainly, you're doing that in a totally-inefficient way, from the look of that.
The isWithinRange() is redundant; if it's in the
area variable, it's already in range, if the logic's written correctly. So, for example, if you're trying to do something semi-randomized to one ship in that area (like heal them):
boolean hasHealed = false;
int tooManyRepeats = 0;
//Get this list only one time, ever; expensive square-root invocation in getting distances between Vector2fs!
List<ShipAPI> targets = AIUtils.getNearbyAllies(beamtarget, area);
while(!has Healed && tooManyRepeats < 1000){
for(ShipAPI target : AIUtils.getNearbyAllies(beamtarget, area)){
//Keep adding to this each pass so that we're limited to 1000 invocations of getRandomInRange()
//This means the while operation can fail but can't lock up the game-sim (usually the right answer for real-time code)
tooManyRepeats += 1;
//Only does this logic 1 in 100 passes
if(MathUtils.getRandomInRange(1f,100f) > 99f){
--> do healing logic here
//Use this as a break to leave the while loop
hasHealed = true;
}
}
}
Lastly, the
right way to get a number from 0 --> end of a List's size:
myList.get(MathUtils.getRandomNumberInRange(0,myList.size()-1));
MathUtils.getRandomNumberInRange() is capable of getting numbers in float and integer values automatically.