optimized bane thread

This commit is contained in:
2025-01-18 03:15:48 -06:00
parent 4b86fbb12c
commit e86749febd
+16 -7
View File
@@ -27,8 +27,8 @@ import java.util.ArrayList;
public class BaneThread implements Runnable { public class BaneThread implements Runnable {
public Long lastRun; private volatile Long lastRun;
public static int instancedelay = 10000; public static final Long instancedelay = 1000L;
public BaneThread() { public BaneThread() {
Logger.info(" BaneThread thread has started!"); Logger.info(" BaneThread thread has started!");
} }
@@ -37,14 +37,16 @@ public class BaneThread implements Runnable {
public void processBanesWindow() { public void processBanesWindow() {
try { try {
for(int baneId : Bane.banes.keySet()){ synchronized (Bane.banes) {
Bane bane = Bane.banes.get(baneId); for (int baneId : Bane.banes.keySet()) {
if(bane.getSiegePhase().equals(Enum.SiegePhase.WAR)){ Bane bane = Bane.banes.get(baneId);
bane.applyZergBuffs(); if (bane != null && bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) {
bane.applyZergBuffs();
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
Logger.error("BANE ERROR"); Logger.error("BANE ERROR",e);
} }
@@ -56,6 +58,13 @@ public class BaneThread implements Runnable {
if (System.currentTimeMillis() >= lastRun + instancedelay) { // Correct condition if (System.currentTimeMillis() >= lastRun + instancedelay) { // Correct condition
this.processBanesWindow(); this.processBanesWindow();
lastRun = System.currentTimeMillis(); // Update lastRun after processing lastRun = System.currentTimeMillis(); // Update lastRun after processing
}else {
try {
Thread.sleep(100); // Pause for 10ms to reduce CPU usage
} catch (InterruptedException e) {
Logger.error("Thread interrupted", e);
Thread.currentThread().interrupt();
}
} }
} }
} }