From b1e078493acdaa3fb6c921017858f5aa13468254 Mon Sep 17 00:00:00 2001 From: Govindas Date: Fri, 9 Apr 2021 12:56:18 +0300 Subject: [PATCH] support reloads by stopping cleanuptimer --- src/net/govindas/skooldown/Skooldown.java | 8 +++++++- src/net/govindas/skooldown/utilities/CleanupTimer.java | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/net/govindas/skooldown/Skooldown.java b/src/net/govindas/skooldown/Skooldown.java index e08ab2f..a9d49c1 100644 --- a/src/net/govindas/skooldown/Skooldown.java +++ b/src/net/govindas/skooldown/Skooldown.java @@ -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 cooldowns = new ConcurrentHashMap(); + 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; } } diff --git a/src/net/govindas/skooldown/utilities/CleanupTimer.java b/src/net/govindas/skooldown/utilities/CleanupTimer.java index 6df022b..cab9ab0 100644 --- a/src/net/govindas/skooldown/utilities/CleanupTimer.java +++ b/src/net/govindas/skooldown/utilities/CleanupTimer.java @@ -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; } }