summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenmori <thesenmori@gmail.com>2018-03-15 20:53:18 +1100
committermd_5 <git@md-5.net>2018-03-15 20:54:35 +1100
commitbf61ffc26b4845816da86e9ce53c29b7263fb7a7 (patch)
treeea2788e54b615daf9b2aa2805dc5d8e6cdf24105
parent02f0647216dfe7515e3d7fa75a618faf6f010a7c (diff)
downloadbukkit-bf61ffc26b4845816da86e9ce53c29b7263fb7a7.tar
bukkit-bf61ffc26b4845816da86e9ce53c29b7263fb7a7.tar.gz
bukkit-bf61ffc26b4845816da86e9ce53c29b7263fb7a7.tar.lz
bukkit-bf61ffc26b4845816da86e9ce53c29b7263fb7a7.tar.xz
bukkit-bf61ffc26b4845816da86e9ce53c29b7263fb7a7.zip
Expand on ConfigurationSerializable methods in ConfigurationSection
-rw-r--r--src/main/java/org/bukkit/attribute/AttributeModifier.java4
-rw-r--r--src/main/java/org/bukkit/configuration/ConfigurationSection.java33
-rw-r--r--src/main/java/org/bukkit/configuration/MemorySection.java51
3 files changed, 62 insertions, 26 deletions
diff --git a/src/main/java/org/bukkit/attribute/AttributeModifier.java b/src/main/java/org/bukkit/attribute/AttributeModifier.java
index ade7bf08..3c0c4bc5 100644
--- a/src/main/java/org/bukkit/attribute/AttributeModifier.java
+++ b/src/main/java/org/bukkit/attribute/AttributeModifier.java
@@ -71,7 +71,7 @@ public class AttributeModifier implements ConfigurationSerializable {
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<String, Object>();
- data.put("uuid", uuid);
+ data.put("uuid", uuid.toString());
data.put("name", name);
data.put("operation", operation.ordinal());
data.put("amount", amount);
@@ -79,7 +79,7 @@ public class AttributeModifier implements ConfigurationSerializable {
}
public static AttributeModifier deserialize(Map<String, Object> args) {
- return new AttributeModifier((UUID) args.get("uuid"), (String) args.get("name"), NumberConversions.toDouble(args.get("amount")), Operation.values()[NumberConversions.toInt(args.get("operation"))]);
+ return new AttributeModifier(UUID.fromString((String) args.get("uuid")), (String) args.get("name"), NumberConversions.toDouble(args.get("amount")), Operation.values()[NumberConversions.toInt(args.get("operation"))]);
}
/**
diff --git a/src/main/java/org/bukkit/configuration/ConfigurationSection.java b/src/main/java/org/bukkit/configuration/ConfigurationSection.java
index 166f2a65..d8575d1b 100644
--- a/src/main/java/org/bukkit/configuration/ConfigurationSection.java
+++ b/src/main/java/org/bukkit/configuration/ConfigurationSection.java
@@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.Color;
import org.bukkit.OfflinePlayer;
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.util.Vector;
import org.bukkit.inventory.ItemStack;
@@ -607,6 +608,38 @@ public interface ConfigurationSection {
// Bukkit
/**
+ * Gets the requested {@link ConfigurationSerializable} object at the given
+ * path.
+ *
+ * If the Object does not exist but a default value has been specified, this
+ * will return the default value. If the Object does not exist and no
+ * default value was specified, this will return null.
+ *
+ * @param <T> the type of {@link ConfigurationSerializable}
+ * @param path the path to the object.
+ * @param clazz the type of {@link ConfigurationSerializable}
+ * @return Requested {@link ConfigurationSerializable} object
+ */
+ public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz);
+
+ /**
+ * Gets the requested {@link ConfigurationSerializable} object at the given
+ * path, returning a default value if not found
+ *
+ * If the Object does not exist then the specified default value will
+ * returned regardless of if a default has been identified in the root
+ * {@link Configuration}.
+ *
+ * @param <T> the type of {@link ConfigurationSerializable}
+ * @param path the path to the object.
+ * @param clazz the type of {@link ConfigurationSerializable}
+ * @param def the default object to return if the object is not present at
+ * the path
+ * @return Requested {@link ConfigurationSerializable} object
+ */
+ public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz, T def);
+
+ /**
* Gets the requested Vector by path.
* <p>
* If the Vector does not exist but a default value has been specified,
diff --git a/src/main/java/org/bukkit/configuration/MemorySection.java b/src/main/java/org/bukkit/configuration/MemorySection.java
index 6e5ba586..fe7762b9 100644
--- a/src/main/java/org/bukkit/configuration/MemorySection.java
+++ b/src/main/java/org/bukkit/configuration/MemorySection.java
@@ -12,6 +12,7 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.Color;
import org.bukkit.OfflinePlayer;
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@@ -623,64 +624,66 @@ public class MemorySection implements ConfigurationSection {
}
// Bukkit
- public Vector getVector(String path) {
+ @Override
+ public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz) {
+ Validate.notNull(clazz, "ConfigurationSerializable class cannot be null");
Object def = getDefault(path);
- return getVector(path, (def instanceof Vector) ? (Vector) def : null);
+ return getSerializable(path, clazz, (def != null && clazz.isInstance(def)) ? clazz.cast(def) : null);
+ }
+
+ @Override
+ public <T extends ConfigurationSerializable> T getSerializable(String path, Class<T> clazz, T def) {
+ Validate.notNull(clazz, "ConfigurationSerializable class cannot be null");
+ Object val = get(path);
+ return (val != null && clazz.isInstance(val)) ? clazz.cast(val) : def;
+ }
+
+ public Vector getVector(String path) {
+ return getSerializable(path, Vector.class);
}
public Vector getVector(String path, Vector def) {
- Object val = get(path, def);
- return (val instanceof Vector) ? (Vector) val : def;
+ return getSerializable(path, Vector.class, def);
}
public boolean isVector(String path) {
- Object val = get(path);
- return val instanceof Vector;
+ return getSerializable(path, Vector.class) != null;
}
public OfflinePlayer getOfflinePlayer(String path) {
- Object def = getDefault(path);
- return getOfflinePlayer(path, (def instanceof OfflinePlayer) ? (OfflinePlayer) def : null);
+ return getSerializable(path, OfflinePlayer.class);
}
public OfflinePlayer getOfflinePlayer(String path, OfflinePlayer def) {
- Object val = get(path, def);
- return (val instanceof OfflinePlayer) ? (OfflinePlayer) val : def;
+ return getSerializable(path, OfflinePlayer.class, def);
}
public boolean isOfflinePlayer(String path) {
- Object val = get(path);
- return val instanceof OfflinePlayer;
+ return getSerializable(path, OfflinePlayer.class) != null;
}
public ItemStack getItemStack(String path) {
- Object def = getDefault(path);
- return getItemStack(path, (def instanceof ItemStack) ? (ItemStack) def : null);
+ return getSerializable(path, ItemStack.class);
}
public ItemStack getItemStack(String path, ItemStack def) {
- Object val = get(path, def);
- return (val instanceof ItemStack) ? (ItemStack) val : def;
+ return getSerializable(path, ItemStack.class, def);
}
public boolean isItemStack(String path) {
- Object val = get(path);
- return val instanceof ItemStack;
+ return getSerializable(path, ItemStack.class) != null;
}
public Color getColor(String path) {
- Object def = getDefault(path);
- return getColor(path, (def instanceof Color) ? (Color) def : null);
+ return getSerializable(path, Color.class);
}
public Color getColor(String path, Color def) {
- Object val = get(path, def);
- return (val instanceof Color) ? (Color) val : def;
+ return getSerializable(path, Color.class, def);
}
public boolean isColor(String path) {
- Object val = get(path);
- return val instanceof Color;
+ return getSerializable(path, Color.class) != null;
}
public ConfigurationSection getConfigurationSection(String path) {