From 38c82547075a1d14ed4e89040406a7a4cd689f8b Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Thu, 19 May 2011 11:06:19 +0200 Subject: [PATCH] Added simple start for server-side components. --- configuration.txt | 3 ++ src/main/java/org/dynmap/Component.java | 10 +++++ .../java/org/dynmap/ComponentManager.java | 42 +++++++++++++++++++ src/main/java/org/dynmap/DynmapPlugin.java | 6 +++ src/main/java/org/dynmap/TestComponent.java | 10 +++++ 5 files changed, 71 insertions(+) create mode 100644 src/main/java/org/dynmap/Component.java create mode 100644 src/main/java/org/dynmap/ComponentManager.java create mode 100644 src/main/java/org/dynmap/TestComponent.java diff --git a/configuration.txt b/configuration.txt index 6924b988..a11751f1 100644 --- a/configuration.txt +++ b/configuration.txt @@ -1,5 +1,8 @@ # All paths in this configuration file are relative to Dynmap's data-folder: minecraft_server/plugins/dynmap/ +components: + - class: org.dynmap.TestComponent + stuff: "this is some stuff" # Treat hiddenplayers.txt as a whitelist for players to be shown on the map? (Default false) display-whitelist: false diff --git a/src/main/java/org/dynmap/Component.java b/src/main/java/org/dynmap/Component.java new file mode 100644 index 00000000..125137e9 --- /dev/null +++ b/src/main/java/org/dynmap/Component.java @@ -0,0 +1,10 @@ +package org.dynmap; + +public abstract class Component { + protected DynmapPlugin plugin; + protected ConfigurationNode configuration; + public Component(DynmapPlugin plugin, ConfigurationNode configuration) { + this.plugin = plugin; + this.configuration = configuration; + } +} diff --git a/src/main/java/org/dynmap/ComponentManager.java b/src/main/java/org/dynmap/ComponentManager.java new file mode 100644 index 00000000..7829aaad --- /dev/null +++ b/src/main/java/org/dynmap/ComponentManager.java @@ -0,0 +1,42 @@ +package org.dynmap; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class ComponentManager { + public Set components = new HashSet(); + public Map> componentLookup = new HashMap>(); + + public void add(Component c) { + if (components.add(c)) { + String key = c.getClass().toString(); + List clist = componentLookup.get(key); + if (clist == null) { + clist = new ArrayList(); + componentLookup.put(key, clist); + } + clist.add(c); + } + } + + public void remove(Component c) { + if (components.remove(c)) { + String key = c.getClass().toString(); + List clist = componentLookup.get(key); + if (clist != null) { + clist.remove(c); + } + } + } + + public Iterable getComponents(Class c) { + List list = componentLookup.get(c.toString()); + if (list == null) + return new ArrayList(); + return list; + } +} diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index a723de4e..3aeccebc 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -56,6 +56,7 @@ public class DynmapPlugin extends JavaPlugin { public HashSet enabledTriggers = new HashSet(); public PermissionProvider permissions; public HeroChatHandler hchand; + public ComponentManager componentManager = new ComponentManager(); public Timer timer; @@ -82,6 +83,11 @@ public class DynmapPlugin extends JavaPlugin { configuration = new ConfigurationNode(bukkitConfiguration); loadDebuggers(); + + // Load components. + for(Component component : configuration.createInstances("components", new Class[] { DynmapPlugin.class }, new Object[] { this })) { + componentManager.add(component); + } tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles")); if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) { diff --git a/src/main/java/org/dynmap/TestComponent.java b/src/main/java/org/dynmap/TestComponent.java new file mode 100644 index 00000000..304679c2 --- /dev/null +++ b/src/main/java/org/dynmap/TestComponent.java @@ -0,0 +1,10 @@ +package org.dynmap; + +public class TestComponent extends Component { + + public TestComponent(DynmapPlugin plugin, ConfigurationNode configuration) { + super(plugin, configuration); + Log.info("Hello! I'm a component that does stuff! Like saying what is in my configuration: " + configuration.getString("stuff")); + } + +}