From 2866eaa905c9b0d737d9d5b8665a523db4c47487 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 22 May 2011 19:42:47 +0200 Subject: [PATCH] Added ability to reload (also using 'dynmap reload'). --- src/main/java/org/dynmap/Component.java | 3 ++ .../java/org/dynmap/ComponentManager.java | 5 ++++ src/main/java/org/dynmap/DynmapPlugin.java | 29 +++++++++++++------ .../dynmap/JsonFileClientUpdateComponent.java | 6 ++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/dynmap/Component.java b/src/main/java/org/dynmap/Component.java index 125137e9..e88f5456 100644 --- a/src/main/java/org/dynmap/Component.java +++ b/src/main/java/org/dynmap/Component.java @@ -7,4 +7,7 @@ public abstract class Component { this.plugin = plugin; this.configuration = configuration; } + + public void dispose() { + } } diff --git a/src/main/java/org/dynmap/ComponentManager.java b/src/main/java/org/dynmap/ComponentManager.java index 7829aaad..ce737940 100644 --- a/src/main/java/org/dynmap/ComponentManager.java +++ b/src/main/java/org/dynmap/ComponentManager.java @@ -33,6 +33,11 @@ public class ComponentManager { } } + public void clear() { + componentLookup.clear(); + components.clear(); + } + public Iterable getComponents(Class c) { List list = componentLookup.get(c.toString()); if (list == null) diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 3af5fce6..506c3afd 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -57,8 +57,6 @@ public class DynmapPlugin extends JavaPlugin { public ComponentManager componentManager = new ComponentManager(); public Events events = new Events(); - public Timer timer; - public static File dataDirectory; public static File tilesDirectory; @@ -70,10 +68,11 @@ public class DynmapPlugin extends JavaPlugin { return webServer; } + @Override public void onEnable() { permissions = NijikokunPermissions.create(getServer(), "dynmap"); if (permissions == null) - permissions = new OpPermissions(new String[] { "fullrender" }); + permissions = new OpPermissions(new String[] { "fullrender", "reload" }); dataDirectory = this.getDataFolder(); @@ -109,6 +108,7 @@ public class DynmapPlugin extends JavaPlugin { for(Component component : configuration.createInstances("components", new Class[] { DynmapPlugin.class }, new Object[] { this })) { componentManager.add(component); } + Log.info("Loaded " + componentManager.components.size() + " components."); registerEvents(); @@ -151,7 +151,15 @@ public class DynmapPlugin extends JavaPlugin { } } + @Override public void onDisable() { + int componentCount = componentManager.components.size(); + for(Component component : componentManager.components) { + component.dispose(); + } + componentManager.clear(); + Log.info("Unloaded " + componentCount + " components."); + mapManager.stopRendering(); if (webServer != null) { @@ -159,13 +167,9 @@ public class DynmapPlugin extends JavaPlugin { webServer = null; } - if (timer != null) { - timer.cancel(); - } - Debug.clearDebuggers(); } - + public boolean isTrigger(String s) { return enabledTriggers.contains(s); } @@ -275,7 +279,8 @@ public class DynmapPlugin extends JavaPlugin { "render", "hide", "show", - "fullrender" })); + "fullrender", + "reload" })); @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { @@ -340,6 +345,12 @@ public class DynmapPlugin extends JavaPlugin { mapManager.renderFullWorld(loc); return true; } + } else if (c.equals("reload") && checkPlayerPermission(sender, "reload")) { + sender.sendMessage("Reloading Dynmap..."); + onDisable(); + onEnable(); + sender.sendMessage("Dynmap reloaded"); + return true; } return true; } diff --git a/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java b/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java index 186d6ea2..a4dd7adc 100644 --- a/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java +++ b/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java @@ -147,4 +147,10 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent { ChatEvent event = new ChatEvent("web", name, message); plugin.events.trigger("webchat", event); } + + @Override + public void dispose() { + super.dispose(); + timer.cancel(); + } }