summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThinkofdeath <thinkofdeath@spigotmc.org>2014-12-04 10:10:54 +0000
committerThinkofdeath <thinkofdeath@spigotmc.org>2014-12-04 10:10:54 +0000
commitde35b9f746aa9ad4018a494106ab42c8f549ed1b (patch)
treeba0b96fffbadc16a804320606c18e40a388339c0
parentefd0c5172379a1f441c7eeade39d42777094b3ee (diff)
downloadbukkit-de35b9f746aa9ad4018a494106ab42c8f549ed1b.tar
bukkit-de35b9f746aa9ad4018a494106ab42c8f549ed1b.tar.gz
bukkit-de35b9f746aa9ad4018a494106ab42c8f549ed1b.tar.lz
bukkit-de35b9f746aa9ad4018a494106ab42c8f549ed1b.tar.xz
bukkit-de35b9f746aa9ad4018a494106ab42c8f549ed1b.zip
Fix Pattern serialization
-rw-r--r--src/main/java/org/bukkit/block/banner/Pattern.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/block/banner/Pattern.java b/src/main/java/org/bukkit/block/banner/Pattern.java
index ba51c1fc..95b0f3c8 100644
--- a/src/main/java/org/bukkit/block/banner/Pattern.java
+++ b/src/main/java/org/bukkit/block/banner/Pattern.java
@@ -1,11 +1,18 @@
package org.bukkit.block.banner;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
import org.bukkit.DyeColor;
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
@SerializableAs("Pattern")
-public class Pattern {
+public class Pattern implements ConfigurationSerializable {
+ private static final String COLOR = "color";
+ private static final String PATTERN = "pattern";
+
private final DyeColor color;
private final PatternType pattern;
@@ -20,6 +27,32 @@ public class Pattern {
this.color = color;
this.pattern = pattern;
}
+
+ /**
+ * Constructor for deserialization.
+ *
+ * @param map the map to deserialize from
+ */
+ public Pattern(Map<String, Object> map) {
+ color = DyeColor.valueOf(getString(map, COLOR));
+ pattern = PatternType.getByIdentifier(getString(map, PATTERN));
+ }
+
+ private static String getString(Map<?,?> map, Object key) {
+ Object str = map.get(key);
+ if (str instanceof String) {
+ return (String) str;
+ }
+ throw new NoSuchElementException(map + " does not contain " + key);
+ }
+
+ @Override
+ public Map<String, Object> serialize() {
+ return ImmutableMap.<String, Object>of(
+ COLOR, color.toString(),
+ PATTERN, pattern.getIdentifier()
+ );
+ }
/**
* Returns the color of the pattern