mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 00:07:56 +01:00
Fix Pattern serialization
By: Thinkofdeath <thinkofdeath@spigotmc.org>
This commit is contained in:
parent
d6048829a5
commit
dbfed2c8bf
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user