Added events for components and implemented 'buildclientconfiguration'-event in ClientConfigurationComponent.
This commit is contained in:
parent
38c8254707
commit
e57301b14e
13 changed files with 358 additions and 129 deletions
50
src/main/java/org/dynmap/ClientComponent.java
Normal file
50
src/main/java/org/dynmap/ClientComponent.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package org.dynmap;
|
||||
|
||||
import static org.dynmap.JSONUtils.a;
|
||||
import static org.dynmap.JSONUtils.s;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
public class ClientComponent extends Component {
|
||||
|
||||
public ClientComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) {
|
||||
super(plugin, configuration);
|
||||
plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void triggered(JSONObject t) {
|
||||
JSONObject o = convertMap(configuration);
|
||||
o.remove("class");
|
||||
a(t, "components", o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
JSONObject convertMap(Map<String, ?> m) {
|
||||
JSONObject o = new JSONObject();
|
||||
for(Map.Entry<String, ?> entry : m.entrySet()) {
|
||||
s(o, entry.getKey(), convert(entry.getValue()));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
JSONArray convertList(List<?> l) {
|
||||
JSONArray o = new JSONArray();
|
||||
for(Object entry : l) {
|
||||
o.add(convert(entry));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
Object convert(Object o) {
|
||||
if (o instanceof Map<?, ?>) {
|
||||
return convertMap((Map<String, ?>)o);
|
||||
} else if (o instanceof List<?>) {
|
||||
return convertList((List<?>)o);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue