From c89b60221e272a18b682f8d753dd2fabe3ddc8ca Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 19 Jan 2023 11:21:08 -0500 Subject: [PATCH] Extracted open/close logic to method. Run at startup. --- src/engine/server/world/WorldServer.java | 5 +- src/engine/workthreads/HourlyJobThread.java | 78 +++++++++++---------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 6d3009d2..7a259e66 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -389,9 +389,12 @@ public class WorldServer { } Logger.info("Loading Mine data."); - //DbManager.MineQueries.syncMineWindowsWithToday(); Mine.loadAllMines(); + // Open/Close mines for the current window + Logger.info("Processing mine window."); + HourlyJobThread.processMineWindow(); + Logger.info("Loading Shrine data."); DbManager.ShrineQueries.LOAD_ALL_SHRINES(); diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 0928c284..2a864421 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -52,44 +52,11 @@ public class HourlyJobThread implements Runnable { Logger.error( e.toString()); } - //updateMines. - try { - - ArrayList mines = Mine.getMines(); - - for (Mine mine : mines) { - try { - - // Open Errant Mines - - if (mine.getOwningGuild() == null) { - mine.handleStartMineWindow(); - Mine.setLastChange(System.currentTimeMillis()); - continue; - } - - // Open Mines with a current guild hour - - if (mine.getOwningGuild().getMineTime() == - LocalDateTime.now().getHour()) { - mine.handleStartMineWindow(); - Mine.setLastChange(System.currentTimeMillis()); - continue; - } + // Open or Close mines for the current mine window. - // Close all other mines - if (mine.handleEndMineWindow()) - Mine.setLastChange(System.currentTimeMillis()); + processMineWindow(); - } catch (Exception e) { - Logger.error ("mineID: " + mine.getObjectUUID(), e.toString()); - } - } - } catch (Exception e) { - Logger.error( e.toString()); - } - - for (Mine mine : Mine.getMines()) { + for (Mine mine : Mine.getMines()) { try { mine.depositMineResources(); @@ -126,4 +93,43 @@ public class HourlyJobThread implements Runnable { Logger.info( MessageDispatcher.getNetstatString()); Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); } + + public static void processMineWindow() { + + try { + + ArrayList mines = Mine.getMines(); + + for (Mine mine : mines) { + try { + + // Open Errant Mines + + if (mine.getOwningGuild() == null) { + mine.handleStartMineWindow(); + Mine.setLastChange(System.currentTimeMillis()); + continue; + } + + // Open Mines with a current guild hour + + if (mine.getOwningGuild().getMineTime() == + LocalDateTime.now().getHour()) { + mine.handleStartMineWindow(); + Mine.setLastChange(System.currentTimeMillis()); + continue; + } + + // Close all other mines + if (mine.handleEndMineWindow()) + Mine.setLastChange(System.currentTimeMillis()); + + } catch (Exception e) { + Logger.error ("mineID: " + mine.getObjectUUID(), e.toString()); + } + } + } catch (Exception e) { + Logger.error( e.toString()); + } + } }