Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
SPIGOT-2768: Fully implement map color
Dieser Commit ist enthalten in:
Ursprung
c25ddf063a
Commit
54450b727e
@ -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;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren