So here is the thing: I have made a thread for each generator an outpost has. We have a total of 6 outposts , 5 generators each. 3 teams, engineers can only repair generators and prevent their overload. In order to make the whole generator logic I use threads. If the thread gets interrupted it means that the generator got prevented from being destroyed , if the thread is finished normally , the generator got destroyed and if the generator is destroyed an engineer can repair them. Is there any way of avoiding threads because in spite of high cpu usage there are also other thread issues.
The same thing happens with the shield regeneration of each player. I'll just post the code for this one:
public static void startRegenerate(final Player p){
if(already_regenerating_arraylist.contains(p.getId())){
return;
}
final int previous_shield_lvl = p.getShieldLevel();
final int previous_hp_lvl = (int) p.getHealth();
Thread reg = new Thread(){
@Override
public void run(){
already_regenerating_arraylist.add(p.getUniqueId());
try {
sleep(3000);
} catch (InterruptedException e1) {
}
for(;;){
if(p.getShieldLevel() >= 20){
p.setShieldLevel(20);
already_regenerating_arraylist.remove(p.getUniqueId());
break;
}
if(p.getHealth() < previous_hp_lvl || p.getShieldLevel() < previous_shield_lvl){
already_regenerating_arraylist.remove(p.getUniqueId());
break;
}
p.setFoodLevel(p.getFoodLevel() + 6);
try {
sleep(1000);
} catch (InterruptedException e) {
}
}
}
};
reg.start();
}
After having more than 50 players stuff stop working (lag , etc...)