support reloads by stopping cleanuptimer

This commit is contained in:
Govindas 2021-04-09 12:56:18 +03:00
parent 0313f6512a
commit 637415efe1
2 changed files with 10 additions and 2 deletions

View File

@ -10,10 +10,12 @@ import net.govindas.skooldown.expressions.ExprCooldown;
import net.govindas.skooldown.utilities.CleanupTimer;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
public final class Skooldown extends JavaPlugin {
public static ConcurrentHashMap<String, Long> cooldowns = new ConcurrentHashMap<String, Long>();
private Timer cleanupTimer;
@Override
public void onEnable() {
@ -27,12 +29,16 @@ public final class Skooldown extends JavaPlugin {
Skript.registerExpression(ExprCooldown.class, Timespan.class, ExpressionType.PROPERTY, "cooldown %string%");
getLogger().info("Skript addon enabled!");
new CleanupTimer();
cleanupTimer = new CleanupTimer().start();
}
@Override
public void onDisable() {
cooldowns = null;
getLogger().info("Skript addon disabled!");
cleanupTimer.cancel();
cleanupTimer = null;
}
}

View File

@ -11,7 +11,8 @@ import java.util.logging.Level;
public class CleanupTimer {
//Regular Cleanup Timer to prevent memory leaks
public CleanupTimer() {
public CleanupTimer() {}
public Timer start() {
Timer timer = new Timer();
TimerTask regularTask = new TimerTask() {
int i = 0;
@ -39,5 +40,6 @@ public class CleanupTimer {
//regular schedule
int minutes = 30;
timer.schedule(regularTask, 100, 1000 * 60 * minutes);
return timer;
}
}