Added simple start for server-side components.

This commit is contained in:
FrozenCow 2011-05-19 11:06:19 +02:00
parent 5b5b217be2
commit 38c8254707
5 changed files with 71 additions and 0 deletions

View File

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

View File

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

View File

@ -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<Component> components = new HashSet<Component>();
public Map<String, List<Component>> componentLookup = new HashMap<String, List<Component>>();
public void add(Component c) {
if (components.add(c)) {
String key = c.getClass().toString();
List<Component> clist = componentLookup.get(key);
if (clist == null) {
clist = new ArrayList<Component>();
componentLookup.put(key, clist);
}
clist.add(c);
}
}
public void remove(Component c) {
if (components.remove(c)) {
String key = c.getClass().toString();
List<Component> clist = componentLookup.get(key);
if (clist != null) {
clist.remove(c);
}
}
}
public Iterable<Component> getComponents(Class<Component> c) {
List<Component> list = componentLookup.get(c.toString());
if (list == null)
return new ArrayList<Component>();
return list;
}
}

View File

@ -56,6 +56,7 @@ public class DynmapPlugin extends JavaPlugin {
public HashSet<String> enabledTriggers = new HashSet<String>();
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.<Component>createInstances("components", new Class<?>[] { DynmapPlugin.class }, new Object[] { this })) {
componentManager.add(component);
}
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {

View File

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