// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ // ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com package engine.workthreads; import engine.Enum; import engine.gameManager.SessionManager; import engine.gameManager.SimulationManager; import engine.objects.Bane; import engine.objects.PlayerCharacter; import engine.objects.PlayerCombatStats; import org.pmw.tinylog.Logger; import java.util.concurrent.*; public class UpdateThread implements Runnable { private volatile Long lastRun; public static final Long instancedelay = 1000L; public UpdateThread() { Logger.info(" UpdateThread thread has started!"); } private static final long INSTANCE_DELAY = 1500; // Adjust as needed public void processPlayerUpdate() { ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); try { for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { if (player != null) { Future future = executor.submit(() -> { try { player.update(true); } catch (Exception e) { Logger.error(e); } }); try { future.get(10, TimeUnit.SECONDS); // Enforce max execution time } catch (TimeoutException e) { Logger.error("Player update timed out for: " + player.getName()); future.cancel(true); // Attempt to cancel the task } catch (Exception e) { Logger.error(e); } } } } catch (Exception e) { Logger.error("UPDATE ERROR", e); } finally { executor.shutdown(); } } @Override public void run() { try { processPlayerUpdate(); } catch (Exception e) { Logger.error("Thread Execution Error", e); } } public static void startUpdateThread() { Thread updateThread; updateThread = new Thread(new UpdateThread()); updateThread.setName("updateThread"); updateThread.start(); } }