mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-02 16:49:56 +01:00
Added simple start for server-side components.
This commit is contained in:
parent
5b5b217be2
commit
38c8254707
@ -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
|
||||
|
||||
|
10
src/main/java/org/dynmap/Component.java
Normal file
10
src/main/java/org/dynmap/Component.java
Normal 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;
|
||||
}
|
||||
}
|
42
src/main/java/org/dynmap/ComponentManager.java
Normal file
42
src/main/java/org/dynmap/ComponentManager.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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()) {
|
||||
|
10
src/main/java/org/dynmap/TestComponent.java
Normal file
10
src/main/java/org/dynmap/TestComponent.java
Normal 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"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user