Compare commits

..

No commits in common. "5d51ae33b07c8ec58c43449cc4d82074b338ad6c" and "c9ef0d2d9a8a06ca5d1d0fed0fabb9460a127017" have entirely different histories.

3 changed files with 8 additions and 67 deletions

View file

@ -42,8 +42,6 @@ public final class BuildConfiguration {
// Verbose logging // Verbose logging
public static final boolean provideVerboseLoggingForSpellingHelpers = false; public static final boolean provideVerboseLoggingForSpellingHelpers = false;
public static final boolean provideVerboseLoggingForSpellingCompletions = false; public static final boolean provideVerboseLoggingForSpellingCompletions = false;
public static final boolean announceSchedulingActionsInLogIfPlayers = true;
public static final boolean announceSchedulingActionsInLogIfAlone = true;
// Command configuration // Command configuration
// -> /msg & /reply // -> /msg & /reply

View file

@ -18,9 +18,7 @@
*/ */
package de.pickshadow.plugin; package de.pickshadow.plugin;
import de.pickshadow.plugin.classes.Configuration;
import de.pickshadow.plugin.classes.logger.LoggerInstanceImpl; import de.pickshadow.plugin.classes.logger.LoggerInstanceImpl;
import de.pickshadow.plugin.utils.Miscellaneous;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.UUID; import java.util.UUID;
@ -28,68 +26,18 @@ import java.util.UUID;
public class Scheduler { public class Scheduler {
LoggerInstanceImpl logger; 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() { public void initializeScheduler() {
logger = ObjHolder.logger.getInstance(getClass()); logger = ObjHolder.logger.getInstance(getClass());
logger.verb("Initializing scheduler"); logger.verb("Scheduling tasks");
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runMinuteTasks(execsMinutely), 1200L); Bukkit.getScheduler().runTaskLater(ObjHolder.main, this::runMinuteTasks, 1200L);
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runHourTasks(execsHourly), 72000L);
} }
public void runMinuteTasks(int execs) { public void runMinuteTasks() {
// If execution count does not match return logger.diag("Running minutely tasks");
if (execs != execsMinutely) return;
// Print announcement
printTaskAnnouncement("minutely");
// Increase execution count to prevent additional calls
execsMinutely++;
// Save player data // Save player data
for (UUID uuid : ObjHolder.playerDataLoader.getLoadedUUIDs()) ObjHolder.playerDataLoader.savePlayerData(uuid); for (UUID uuid : ObjHolder.playerDataLoader.getLoadedUUIDs()) ObjHolder.playerDataLoader.savePlayerData(uuid);
// Schedule // Schedule
Bukkit.getScheduler().runTaskLater(ObjHolder.main, () -> runMinuteTasks(execsMinutely), 1200L); Bukkit.getScheduler().runTaskLater(ObjHolder.main, this::runMinuteTasks, 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");
} }
} }

View file

@ -52,18 +52,13 @@ public class Miscellaneous {
// Ensures garbage collection // Ensures garbage collection
// Stolen from JLibs // Stolen from JLibs
// https://github.com/santhosh-tekuri/jlibs/blob/e001fb7286c84f456125d1be00fc9a7e3b128881/core/src/main/java/jlibs/core/lang/RuntimeUtil.java#L148 // https://github.com/santhosh-tekuri/jlibs/blob/e001fb7286c84f456125d1be00fc9a7e3b128881/core/src/main/java/jlibs/core/lang/RuntimeUtil.java#L148
public static void threadedGc(){ public static void gc(){
Thread gcThread = new Thread(Miscellaneous::gc);
gcThread.start();
}
public static void gc() {
ObjHolder.logger.warn(Miscellaneous.class, "Forcing garbage collection"); ObjHolder.logger.warn(Miscellaneous.class, "Forcing garbage collection");
Object obj = new Object(); Object obj = new Object();
WeakReference<Object> ref = new WeakReference<>(obj); WeakReference<Object> ref = new WeakReference<>(obj);
obj = null; obj = null;
while(ref.get() != null) System.gc(); while(ref.get() != null)
ObjHolder.logger.warn(Miscellaneous.class, "Garbage collector finished"); System.gc();
} }
// Data type conversion // Data type conversion