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
68
src/main/java/org/dynmap/JSONUtils.java
Normal file
68
src/main/java/org/dynmap/JSONUtils.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package org.dynmap;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class JSONUtils {
|
||||
|
||||
// Gets a value at the specified path.
|
||||
public static Object g(JSONObject o, String path) {
|
||||
int index = path.indexOf('/');
|
||||
if (index == -1) {
|
||||
return o.get(path);
|
||||
} else {
|
||||
String key = path.substring(0, index);
|
||||
String subpath = path.substring(index+1);
|
||||
Object oo = o.get(key);
|
||||
JSONObject subobject;
|
||||
if (oo == null) {
|
||||
return null;
|
||||
} else /*if (oo instanceof JSONObject)*/ {
|
||||
subobject = (JSONObject)o;
|
||||
}
|
||||
return g(subobject, subpath);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets a value on the specified path. If JSONObjects inside the path are missing, they'll be created.
|
||||
public static void s(JSONObject o, String path, Object value) {
|
||||
int index = path.indexOf('/');
|
||||
if (index == -1) {
|
||||
o.put(path, value);
|
||||
} else {
|
||||
String key = path.substring(0, index);
|
||||
String subpath = path.substring(index+1);
|
||||
Object oo = o.get(key);
|
||||
JSONObject subobject;
|
||||
if (oo == null) {
|
||||
subobject = new JSONObject();
|
||||
o.put(key, subobject);
|
||||
} else /*if (oo instanceof JSONObject)*/ {
|
||||
subobject = (JSONObject)oo;
|
||||
}
|
||||
s(subobject, subpath, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a value to the list at the specified path. If the list does not exist, it will be created.
|
||||
public static void a(JSONObject o, String path, Object value) {
|
||||
Object oo = g(o, path);
|
||||
JSONArray array;
|
||||
if (oo == null) {
|
||||
array =new JSONArray();
|
||||
s(o, path, array);
|
||||
} else {
|
||||
array = (JSONArray)oo;
|
||||
}
|
||||
array.add(value);
|
||||
}
|
||||
|
||||
// Simply creates a JSONArray.
|
||||
public static JSONArray l(Object... items) {
|
||||
JSONArray arr = new JSONArray();
|
||||
for(Object item : items) {
|
||||
arr.add(item);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue