DailyTaskManager reset when passed schedule.
Thanks to nasseka.
This commit is contained in:
		| @@ -18,7 +18,9 @@ package org.l2jmobius.gameserver.instancemanager; | ||||
|  | ||||
| import java.sql.Connection; | ||||
| import java.sql.PreparedStatement; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Calendar; | ||||
| import java.util.Date; | ||||
| import java.util.logging.Level; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| @@ -47,6 +49,7 @@ public class DailyTaskManager | ||||
| { | ||||
| 	private static final Logger LOGGER = Logger.getLogger(DailyTaskManager.class.getName()); | ||||
| 	 | ||||
| 	private static final SimpleDateFormat SDF = new SimpleDateFormat("dd/MM HH:mm"); | ||||
| 	private static final int[] RESET_SKILLS = | ||||
| 	{ | ||||
| 		2510, // Wondrous Cubic | ||||
| @@ -55,9 +58,8 @@ public class DailyTaskManager | ||||
| 	 | ||||
| 	protected DailyTaskManager() | ||||
| 	{ | ||||
| 		final long currentTime = Chronos.currentTimeMillis(); | ||||
| 		 | ||||
| 		// Schedule reset everyday at 6:30. | ||||
| 		final long currentTime = Chronos.currentTimeMillis(); | ||||
| 		final Calendar calendar = Calendar.getInstance(); | ||||
| 		calendar.set(Calendar.HOUR_OF_DAY, 6); | ||||
| 		calendar.set(Calendar.MINUTE, 30); | ||||
| @@ -66,7 +68,21 @@ public class DailyTaskManager | ||||
| 		{ | ||||
| 			calendar.add(Calendar.DAY_OF_YEAR, 1); | ||||
| 		} | ||||
| 		final long startDelay = Math.max(0, calendar.getTimeInMillis() - currentTime); | ||||
| 		 | ||||
| 		// Check if 24 hours have passed since the last daily reset. | ||||
| 		final long calendarTime = calendar.getTimeInMillis(); | ||||
| 		if (GlobalVariablesManager.getInstance().getLong(GlobalVariablesManager.DAILY_TASK_RESET, 0) < calendarTime) | ||||
| 		{ | ||||
| 			LOGGER.info(getClass().getSimpleName() + ": Next schedule at " + SDF.format(new Date(calendarTime)) + "."); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			LOGGER.info(getClass().getSimpleName() + ": Daily task will run now."); | ||||
| 			onReset(); | ||||
| 		} | ||||
| 		 | ||||
| 		// Daily reset task. | ||||
| 		final long startDelay = Math.max(0, calendarTime - currentTime); | ||||
| 		ThreadPool.scheduleAtFixedRate(this::onReset, startDelay, 86400000); // 86400000 = 1 day | ||||
| 		 | ||||
| 		// Global save task. | ||||
| @@ -75,16 +91,21 @@ public class DailyTaskManager | ||||
| 	 | ||||
| 	private void onReset() | ||||
| 	{ | ||||
| 		// Store last reset time. | ||||
| 		GlobalVariablesManager.getInstance().set(GlobalVariablesManager.DAILY_TASK_RESET, Chronos.currentTimeMillis()); | ||||
| 		 | ||||
| 		// Wednesday weekly tasks. | ||||
| 		if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) | ||||
| 		{ | ||||
| 			clanLeaderApply(); | ||||
| 			resetVitalityWeekly(); | ||||
| 		} | ||||
| 		else | ||||
| 		else // All days, except Wednesday. | ||||
| 		{ | ||||
| 			resetVitalityDaily(); | ||||
| 		} | ||||
| 		 | ||||
| 		// Daily tasks. | ||||
| 		resetClanBonus(); | ||||
| 		resetDailySkills(); | ||||
| 		resetWorldChatPoints(); | ||||
|   | ||||
| @@ -41,6 +41,9 @@ public class GlobalVariablesManager extends AbstractVariables | ||||
| 	private static final String DELETE_QUERY = "DELETE FROM global_variables"; | ||||
| 	private static final String INSERT_QUERY = "INSERT INTO global_variables (var, value) VALUES (?, ?)"; | ||||
| 	 | ||||
| 	// Public variable names | ||||
| 	public static final String DAILY_TASK_RESET = "DAILY_TASK_RESET"; | ||||
| 	 | ||||
| 	protected GlobalVariablesManager() | ||||
| 	{ | ||||
| 		restoreMe(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 MobiusDevelopment
					MobiusDevelopment