Add protected spawnpoints after all worlds have been loaded. Resolves #438

This commit is contained in:
Jerom van der Sar 2015-04-27 00:53:07 +02:00
parent 2ff0f6f5d6
commit 46cd88a18a
3 changed files with 24 additions and 18 deletions

View File

@ -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);
}

View File

@ -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())

View File

@ -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);
}