mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-25 03:35:18 +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/
|
# 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)
|
# Treat hiddenplayers.txt as a whitelist for players to be shown on the map? (Default false)
|
||||||
display-whitelist: 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 HashSet<String> enabledTriggers = new HashSet<String>();
|
||||||
public PermissionProvider permissions;
|
public PermissionProvider permissions;
|
||||||
public HeroChatHandler hchand;
|
public HeroChatHandler hchand;
|
||||||
|
public ComponentManager componentManager = new ComponentManager();
|
||||||
|
|
||||||
public Timer timer;
|
public Timer timer;
|
||||||
|
|
||||||
@ -83,6 +84,11 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
loadDebuggers();
|
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"));
|
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
|
||||||
if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {
|
if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {
|
||||||
Log.warning("Could not create directory for tiles ('" + tilesDirectory + "').");
|
Log.warning("Could not create directory for tiles ('" + tilesDirectory + "').");
|
||||||
|
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