From d779ca366d45a992c8d748c21d4a2e28101b3ac0 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 7 Aug 2015 11:38:39 +1000 Subject: [PATCH] Fixes #507 Fixes #485 --- .../com/intellectualcrafters/plot/PS.java | 3 ++- .../plot/util/TaskManager.java | 22 +++++++++++++++++++ .../com/plotsquared/bukkit/BukkitMain.java | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index fd7a840e3..008eb0077 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -166,7 +166,7 @@ public class PS { setupDatabase(); CommentManager.registerDefaultInboxes(); // Tasks - if (Settings.KILL_ROAD_MOBS) { + if (Settings.KILL_ROAD_MOBS || Settings.KILL_ROAD_VEHICLES) { IMP.runEntityTask(); } // Events @@ -1460,6 +1460,7 @@ public class PS { */ public void disable() { try { + TASK = null; // Validate that all data in the db is correct DBFunc.validatePlots(getPlotsRaw()); diff --git a/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index 5a8156823..4041ba454 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -14,6 +14,9 @@ public abstract class TaskManager { public static int runTaskRepeat(final Runnable r, final int interval) { if (r != null) { + if (PS.get().TASK == null) { + throw new IllegalArgumentException("disabled"); + } return PS.get().TASK.taskRepeat(r, interval); } return -1; @@ -21,6 +24,9 @@ public abstract class TaskManager { public static int runTaskRepeatAsync(final Runnable r, final int interval) { if (r != null) { + if (PS.get().TASK == null) { + throw new IllegalArgumentException("disabled"); + } return PS.get().TASK.taskRepeat(r, interval); } return -1; @@ -28,12 +34,20 @@ public abstract class TaskManager { public static void runTaskAsync(final Runnable r) { if (r != null) { + if (PS.get().TASK == null) { + r.run(); + return; + } PS.get().TASK.taskAsync(r); } } public static void runTask(final Runnable r) { if (r != null) { + if (PS.get().TASK == null) { + r.run(); + return; + } PS.get().TASK.task(r); } } @@ -45,12 +59,20 @@ public abstract class TaskManager { */ public static void runTaskLater(final Runnable r, final int delay) { if (r != null) { + if (PS.get().TASK == null) { + r.run(); + return; + } PS.get().TASK.taskLater(r, delay); } } public static void runTaskLaterAsync(final Runnable r, final int delay) { if (r != null) { + if (PS.get().TASK == null) { + r.run(); + return; + } PS.get().TASK.taskLaterAsync(r, delay); } } diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 150c131d6..0f99cea9b 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -102,7 +102,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { final String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\."); version[0] = Integer.parseInt(split[0]); version[1] = Integer.parseInt(split[1]); - if (version.length == 3) { + if (split.length == 3) { version[2] = Integer.parseInt(split[2]); } } catch (Exception e) {