|  |  | @ -22,127 +22,147 @@ import java.time.LocalDateTime; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.ArrayList; |  |  |  | import java.util.ArrayList; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.concurrent.ConcurrentHashMap; |  |  |  | import java.util.concurrent.ConcurrentHashMap; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import static engine.server.MBServerStatics.MINE_LATE_WINDOW; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | public class HourlyJobThread implements Runnable { |  |  |  | public class HourlyJobThread implements Runnable { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	private static int hotzoneCount = 0; |  |  |  |     private static final int hotzoneCount = 0; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public HourlyJobThread() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public void run() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Logger.info("Hourly job is now running."); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public HourlyJobThread() { |  |  |  |             ZoneManager.generateAndSetRandomHotzone(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             Zone hotzone = ZoneManager.getHotZone(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  |             if (hotzone == null) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 Logger.error("Null hotzone returned from mapmanager"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 Logger.info("new hotzone: " + hotzone.getName()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 WorldServer.setLastHZChange(System.currentTimeMillis()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public void run() { |  |  |  |         } catch (Exception e) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             Logger.error(e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
 |  |  |  |         // Open or Close mines for the current mine window.
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Logger.info("Hourly job is now running."); |  |  |  |         processMineWindow(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			try { |  |  |  |         // Deposit mine resources to Guilds
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					ZoneManager.generateAndSetRandomHotzone(); |  |  |  |         for (Mine mine : Mine.getMines()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					Zone hotzone = ZoneManager.getHotZone(); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					if (hotzone == null) { |  |  |  |             try { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						Logger.error( "Null hotzone returned from mapmanager"); |  |  |  |                 mine.depositMineResources(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					} else { |  |  |  |             } catch (Exception e) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						Logger.info( "new hotzone: " + hotzone.getName()); |  |  |  |                 Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						WorldServer.setLastHZChange(System.currentTimeMillis()); |  |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					} |  |  |  |         } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} catch (Exception e) { |  |  |  |         // Reset time-gated access to WOO slider.
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				Logger.error( e.toString()); |  |  |  |         // *** Do this after the mines open/close!
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		// Open or Close mines for the current mine window.
 |  |  |  |         if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             Guild guild; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		processMineWindow(); |  |  |  |             for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 guild = (Guild) dbObject; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		for (Mine mine : Mine.getMines()) { |  |  |  |                 if (guild != null) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     guild.wooWasModified = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 				try { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 					mine.depositMineResources(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 				} catch (Exception e) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 					Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // Mines can only be claimed once per cycle.
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // This will reset at 1am after the last mine
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // window closes.
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			// Update city population values
 |  |  |  |         if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City); |  |  |  |             for (Mine mine : Mine.getMines()) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			if (map != null) { |  |  |  |                 if (mine.wasClaimed == true) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     mine.wasClaimed = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 				for (AbstractGameObject ago : map.values()){ |  |  |  |         // Update city population values
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					City city = (City)ago; |  |  |  |         ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					if (city != null) |  |  |  |         if (map != null) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						if (city.getGuild() != null) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 							ArrayList<PlayerCharacter> guildList = Guild.GuildRoster(city.getGuild()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 							city.setPopulation(guildList.size()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 						} |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 				City.lastCityUpdate = System.currentTimeMillis(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} else { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 				Logger.error("missing city map"); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			// Log metrics to console
 |  |  |  |             for (AbstractGameObject ago : map.values()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			Logger.info( WorldServer.getUptimeString()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 			Logger.info( SimulationManager.getPopulationString()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 			Logger.info( MessageDispatcher.getNetstatString()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 			Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public static void processMineWindow() { |  |  |  |                 City city = (City) ago; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		try { |  |  |  |                 if (city != null) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     if (city.getGuild() != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         ArrayList<PlayerCharacter> guildList = Guild.GuildRoster(city.getGuild()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         city.setPopulation(guildList.size()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             City.lastCityUpdate = System.currentTimeMillis(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             Logger.error("missing city map"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			ArrayList<Mine> mines = Mine.getMines(); |  |  |  |         // Log metrics to console
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Logger.info(WorldServer.getUptimeString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Logger.info(SimulationManager.getPopulationString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Logger.info(MessageDispatcher.getNetstatString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			for (Mine mine : mines) { |  |  |  |     public static void processMineWindow() { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				try { |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					// Mines can only be claimed once a cycle.
 |  |  |  |         try { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					// The cycle resets at 01:00hrs after the
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 					// Last mine window closes.
 |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					if (mine.wasClaimed == true) { |  |  |  |             ArrayList<Mine> mines = Mine.getMines(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 						if (LocalDateTime.now().getHour() == 01) |  |  |  |             for (Mine mine : mines) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 							mine.wasClaimed = false; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 						continue; |  |  |  |                 try { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					} |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					// Open Errant Mines
 |  |  |  |                     // Open Errant Mines
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					if (mine.getOwningGuild().isErrant()) { |  |  |  |                     if (mine.getOwningGuild().isErrant()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						mine.handleStartMineWindow(); |  |  |  |                         mine.handleStartMineWindow(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						Mine.setLastChange(System.currentTimeMillis()); |  |  |  |                         Mine.setLastChange(System.currentTimeMillis()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						continue; |  |  |  |                         continue; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					} |  |  |  |                     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					// Open Mines with a current guild hour
 |  |  |  |                     // Open Mines with a current guild hour
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					if (mine.getOwningGuild().getNation().getMineTime() == |  |  |  |                     if (mine.getOwningGuild().getNation().getMineTime() == | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						LocalDateTime.now().getHour()) { |  |  |  |                             LocalDateTime.now().getHour()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						mine.handleStartMineWindow(); |  |  |  |                         mine.handleStartMineWindow(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						Mine.setLastChange(System.currentTimeMillis()); |  |  |  |                         Mine.setLastChange(System.currentTimeMillis()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						continue; |  |  |  |                         continue; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					} |  |  |  |                     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					// Close all remaining mines
 |  |  |  |                     // Close all remaining mines
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 					 if (mine.handleEndMineWindow()) |  |  |  |                     if (mine.handleEndMineWindow()) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 							Mine.setLastChange(System.currentTimeMillis()); |  |  |  |                         Mine.setLastChange(System.currentTimeMillis()); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 				} catch (Exception e) { |  |  |  |                 } catch (Exception e) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					Logger.error ("mineID: " + mine.getObjectUUID(), e.toString()); |  |  |  |                     Logger.error("mineID: " + mine.getObjectUUID(), e.toString()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  |                 } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		} catch (Exception e) { |  |  |  |         } catch (Exception e) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			Logger.error( e.toString()); |  |  |  |             Logger.error(e.toString()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  |         } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  |     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |