From 46cd88a18a6373f8a2fe2f70aea0e6661347344f Mon Sep 17 00:00:00 2001 From: Jerom van der Sar Date: Mon, 27 Apr 2015 00:53:07 +0200 Subject: [PATCH] Add protected spawnpoints after all worlds have been loaded. Resolves #438 --- .../TotalFreedomMod/TFM_AdminList.java | 3 ++- .../TotalFreedomMod/TFM_ProtectedArea.java | 26 +++++++++++++------ .../TotalFreedomMod/TotalFreedomMod.java | 13 +++------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java index 70d2d3e..68ef5d9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java @@ -415,7 +415,8 @@ public class TFM_AdminList return admin != null && admin.isActivated(); } - public static synchronized boolean isSuperAdminSync(CommandSender sender) { + public static synchronized boolean isSuperAdminSync(CommandSender sender) + { return isSuperAdmin(sender); } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java index bad8df3..0520b2a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java @@ -66,7 +66,7 @@ public class TFM_ProtectedArea if (doSave) { - saveProtectedAreas(); + save(); } return inProtectedArea; @@ -110,7 +110,7 @@ public class TFM_ProtectedArea if (doSave) { - saveProtectedAreas(); + save(); } return inProtectedArea; @@ -156,13 +156,13 @@ public class TFM_ProtectedArea public static void addProtectedArea(String label, Location location, double radius) { TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius)); - saveProtectedAreas(); + save(); } public static void removeProtectedArea(String label) { TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase()); - saveProtectedAreas(); + save(); } public static void clearProtectedAreas() @@ -179,7 +179,7 @@ public class TFM_ProtectedArea autoAddSpawnpoints(); } - saveProtectedAreas(); + save(); } public static void cleanProtectedAreas() @@ -203,7 +203,7 @@ public class TFM_ProtectedArea if (doSave) { - saveProtectedAreas(); + save(); } } @@ -212,7 +212,7 @@ public class TFM_ProtectedArea return TFM_ProtectedArea.PROTECTED_AREAS.keySet(); } - public static void saveProtectedAreas() + public static void save() { try { @@ -229,8 +229,13 @@ public class TFM_ProtectedArea } @SuppressWarnings("unchecked") - public static void loadProtectedAreas() + public static void load() { + if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) + { + return; + } + File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME); try { @@ -255,6 +260,11 @@ public class TFM_ProtectedArea public static void autoAddSpawnpoints() { + if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) + { + return; + } + if (TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) { for (World world : Bukkit.getWorlds()) diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index e289b4e..95a1ae2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -105,14 +105,7 @@ public class TotalFreedomMod extends JavaPlugin TFM_PlayerList.load(); TFM_BanManager.load(); TFM_Announcer.load(); - - // Protect area - // TODO: Refractor to single .load() method - if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) - { - TFM_ProtectedArea.loadProtectedAreas(); - TFM_ProtectedArea.autoAddSpawnpoints(); - } + TFM_ProtectedArea.load(); // Start SuperAdmin service server.getServicesManager().register(Function.class, TFM_AdminList.SUPERADMIN_SERVICE, plugin, ServicePriority.Normal); @@ -191,7 +184,6 @@ public class TotalFreedomMod extends JavaPlugin TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage()); } - // Load commands later new BukkitRunnable() { @Override @@ -199,6 +191,9 @@ public class TotalFreedomMod extends JavaPlugin { TFM_CommandLoader.scan(); TFM_CommandBlocker.load(); + + // Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438 + TFM_ProtectedArea.autoAddSpawnpoints(); } }.runTaskLater(plugin, 20L); }