Compare commits
No commits in common. "5d51ae33b07c8ec58c43449cc4d82074b338ad6c" and "c9ef0d2d9a8a06ca5d1d0fed0fabb9460a127017" have entirely different histories.
5d51ae33b0
...
c9ef0d2d9a
3 changed files with 8 additions and 67 deletions
|
@ -42,8 +42,6 @@ public final class BuildConfiguration {
|
|||
// Verbose logging
|
||||
public static final boolean provideVerboseLoggingForSpellingHelpers = false;
|
||||
public static final boolean provideVerboseLoggingForSpellingCompletions = false;
|
||||
public static final boolean announceSchedulingActionsInLogIfPlayers = true;
|
||||
public static final boolean announceSchedulingActionsInLogIfAlone = true;
|
||||
|
||||
// Command configuration
|
||||
// -> /msg & /reply
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package de.pickshadow.plugin;
|
||||
|
||||
import de.pickshadow.plugin.classes.Configuration;
|
||||
import de.pickshadow.plugin.classes.logger.LoggerInstanceImpl;
|
||||
import de.pickshadow.plugin.utils.Miscellaneous;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -28,68 +26,18 @@ import java.util.UUID;
|
|||
public class Scheduler {
|
||||
LoggerInstanceImpl logger;
|
||||
|
||||
// Keeps track on how many times the scheduler has been run
|
||||
// Normally this isn't required, this however prevents duplicate
|
||||
// scheduler calls in case /pssp scheduler <timeframe> is used.
|
||||
public int execsMinutely = 0;
|
||||
public int execsHourly = 0;
|
||||
|
||||
public void initializeScheduler() {
|
||||
logger = ObjHolder.logger.getInstance(getClass());
|
||||
logger.verb("Initializing scheduler");
|
||||
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runMinuteTasks(execsMinutely), 1200L);
|
||||
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runHourTasks(execsHourly), 72000L);
|
||||
logger.verb("Scheduling tasks");
|
||||
Bukkit.getScheduler().runTaskLater(ObjHolder.main, this::runMinuteTasks, 1200L);
|
||||
}
|
||||
|
||||
public void runMinuteTasks(int execs) {
|
||||
// If execution count does not match return
|
||||
if (execs != execsMinutely) return;
|
||||
|
||||
// Print announcement
|
||||
printTaskAnnouncement("minutely");
|
||||
|
||||
// Increase execution count to prevent additional calls
|
||||
execsMinutely++;
|
||||
|
||||
|
||||
public void runMinuteTasks() {
|
||||
logger.diag("Running minutely tasks");
|
||||
// Save player data
|
||||
for (UUID uuid : ObjHolder.playerDataLoader.getLoadedUUIDs()) ObjHolder.playerDataLoader.savePlayerData(uuid);
|
||||
|
||||
|
||||
// Schedule
|
||||
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runMinuteTasks(execsMinutely), 1200L);
|
||||
}
|
||||
|
||||
public void runHourTasks(int execs) {
|
||||
// If execution count does not match return
|
||||
if (execs != execsHourly) return;
|
||||
|
||||
// Print announcement
|
||||
printTaskAnnouncement("hourly");
|
||||
|
||||
// Increase execution count to prevent additional calls
|
||||
execsHourly++;
|
||||
|
||||
// Reload configuration file
|
||||
Configuration newConfig = ObjHolder.configLoader.loadConfig();
|
||||
if (newConfig == null) {
|
||||
logger.error("Unable to reload configuration file automatically");
|
||||
} else {
|
||||
ObjHolder.config = newConfig;
|
||||
}
|
||||
|
||||
|
||||
// Run garbage collection (old gen gc)
|
||||
Miscellaneous.threadedGc();
|
||||
|
||||
|
||||
// Schedule
|
||||
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runHourTasks(execsHourly), 72000L);
|
||||
}
|
||||
|
||||
private void printTaskAnnouncement(String timeframe) {
|
||||
if (Bukkit.getOnlinePlayers().isEmpty() && !BuildConfiguration.announceSchedulingActionsInLogIfAlone) return;
|
||||
if (!Bukkit.getOnlinePlayers().isEmpty() && !BuildConfiguration.announceSchedulingActionsInLogIfPlayers) return;
|
||||
logger.diag("Running " + timeframe + " tasks");
|
||||
Bukkit.getScheduler().runTaskLater(ObjHolder.main, this::runMinuteTasks, 1200L);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,18 +52,13 @@ public class Miscellaneous {
|
|||
// Ensures garbage collection
|
||||
// Stolen from JLibs
|
||||
// https://github.com/santhosh-tekuri/jlibs/blob/e001fb7286c84f456125d1be00fc9a7e3b128881/core/src/main/java/jlibs/core/lang/RuntimeUtil.java#L148
|
||||
public static void threadedGc(){
|
||||
Thread gcThread = new Thread(Miscellaneous::gc);
|
||||
gcThread.start();
|
||||
}
|
||||
|
||||
public static void gc(){
|
||||
ObjHolder.logger.warn(Miscellaneous.class, "Forcing garbage collection");
|
||||
Object obj = new Object();
|
||||
WeakReference<Object> ref = new WeakReference<>(obj);
|
||||
obj = null;
|
||||
while(ref.get() != null) System.gc();
|
||||
ObjHolder.logger.warn(Miscellaneous.class, "Garbage collector finished");
|
||||
while(ref.get() != null)
|
||||
System.gc();
|
||||
}
|
||||
|
||||
// Data type conversion
|
||||
|
|
Loading…
Reference in a new issue