summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2016-11-17 17:24:20 +1100
committermd_5 <git@md-5.net>2016-11-17 17:32:50 +1100
commit54450b727e169a02edb6785efe79fe6d452855a8 (patch)
tree6e11b1edcc7fe9f1d2ec5f791b701eecc7879714 /src
parentc25ddf063a808e3adb749e22017661f403c5fb7e (diff)
downloadcraftbukkit-54450b727e169a02edb6785efe79fe6d452855a8.tar
craftbukkit-54450b727e169a02edb6785efe79fe6d452855a8.tar.gz
craftbukkit-54450b727e169a02edb6785efe79fe6d452855a8.tar.lz
craftbukkit-54450b727e169a02edb6785efe79fe6d452855a8.tar.xz
craftbukkit-54450b727e169a02edb6785efe79fe6d452855a8.zip
SPIGOT-2768: Fully implement map color
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java63
1 files changed, 50 insertions, 13 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java
index 83dfda52..eaa9ff88 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java
@@ -3,27 +3,30 @@ package org.bukkit.craftbukkit.inventory;
import java.util.Map;
import net.minecraft.server.NBTTagCompound;
+import net.minecraft.server.NBTTagInt;
import net.minecraft.server.NBTTagString;
+import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.inventory.meta.MapMeta;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
@DelegateDeserialization(SerializableMeta.class)
class CraftMetaMap extends CraftMetaItem implements MapMeta {
static final ItemMetaKey MAP_SCALING = new ItemMetaKey("map_is_scaling", "scaling");
static final ItemMetaKey MAP_LOC_NAME = new ItemMetaKey("LocName", "display-loc-name");
- static final ItemMetaKey MAP_COLOR = new ItemMetaKey("Mapcolor", "display-map-color");
+ static final ItemMetaKey MAP_COLOR = new ItemMetaKey("MapColor", "display-map-color");
static final byte SCALING_EMPTY = (byte) 0;
static final byte SCALING_TRUE = (byte) 1;
static final byte SCALING_FALSE = (byte) 2;
private byte scaling = SCALING_EMPTY;
private String locName;
- private String mapColor;
+ private Color color;
CraftMetaMap(CraftMetaItem meta) {
super(meta);
@@ -34,6 +37,8 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
CraftMetaMap map = (CraftMetaMap) meta;
this.scaling = map.scaling;
+ this.locName = map.locName;
+ this.color = map.color;
}
CraftMetaMap(NBTTagCompound tag) {
@@ -42,7 +47,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
if (tag.hasKey(MAP_SCALING.NBT)) {
this.scaling = tag.getBoolean(MAP_SCALING.NBT) ? SCALING_TRUE : SCALING_FALSE;
}
-
+
if (tag.hasKey(DISPLAY.NBT)) {
NBTTagCompound display = tag.getCompound(DISPLAY.NBT);
@@ -51,7 +56,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
}
if (display.hasKey(MAP_COLOR.NBT)) {
- mapColor = display.getString(MAP_COLOR.NBT);
+ color = Color.fromRGB(display.getInt(MAP_COLOR.NBT));
}
}
}
@@ -63,6 +68,16 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
if (scaling != null) {
setScaling(scaling);
}
+
+ String locName = SerializableMeta.getString(map, MAP_LOC_NAME.BUKKIT, true);
+ if (locName != null) {
+ setLocationName(locName);
+ }
+
+ Color color = SerializableMeta.getObject(Color.class, map, MAP_COLOR.BUKKIT, true);
+ if (color != null) {
+ setColor(color);
+ }
}
@Override
@@ -77,8 +92,8 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
setDisplayTag(tag, MAP_LOC_NAME.NBT, new NBTTagString(getLocationName()));
}
- if (hasMapColor()) {
- setDisplayTag(tag, MAP_COLOR.NBT, new NBTTagString(mapColor));
+ if (hasColor()) {
+ setDisplayTag(tag, MAP_COLOR.NBT, new NBTTagInt(color.asRGB()));
}
}
@@ -98,7 +113,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
}
boolean isMapEmpty() {
- return !hasScaling();
+ return !(hasScaling() | hasLocationName() || hasColor());
}
boolean hasScaling() {
@@ -125,11 +140,26 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
@Override
public void setLocationName(String name) {
+ Preconditions.checkArgument(name != null, "name");
+
this.locName = name;
}
- public boolean hasMapColor() {
- return this.mapColor != null;
+ @Override
+ public boolean hasColor() {
+ return this.color != null;
+ }
+
+ @Override
+ public Color getColor() {
+ return this.color;
+ }
+
+ @Override
+ public void setColor(Color color) {
+ Preconditions.checkArgument(color != null, "color");
+
+ this.color = color;
}
@Override
@@ -141,8 +171,8 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
CraftMetaMap that = (CraftMetaMap) meta;
return (this.scaling == that.scaling)
- && (hasLocationName() ? that.hasLocationName() && this.getLocationName().equals(that.getLocationName()) : !that.hasLocationName())
- && (hasMapColor() ? that.hasMapColor() && this.mapColor.equals(that.mapColor) : !that.hasMapColor());
+ && (hasLocationName() ? that.hasLocationName() && this.locName.equals(that.locName) : !that.hasLocationName())
+ && (hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor());
}
return true;
}
@@ -160,10 +190,17 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
if (hasScaling()) {
hash ^= 0x22222222 << (isScaling() ? 1 : -1);
}
+ if (hasLocationName()) {
+ hash = 61 * hash + locName.hashCode();
+ }
+ if (hasColor()) {
+ hash = 61 * hash + color.hashCode();
+ }
return original != hash ? CraftMetaMap.class.hashCode() ^ hash : hash;
}
+
public CraftMetaMap clone() {
return (CraftMetaMap) super.clone();
}
@@ -180,8 +217,8 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
builder.put(MAP_LOC_NAME.BUKKIT, getLocationName());
}
- if (hasMapColor()) {
- builder.put(MAP_COLOR.BUKKIT, mapColor);
+ if (hasColor()) {
+ builder.put(MAP_COLOR.BUKKIT, getColor());
}
return builder;