mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 03:52:45 +01:00
Add map ID API
By: md_5 <git@md-5.net>
This commit is contained in:
parent
dd007977eb
commit
6ecf05152e
1 changed files with 41 additions and 1 deletions
|
@ -13,16 +13,19 @@ import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
||||||
import org.bukkit.inventory.meta.MapMeta;
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
|
|
||||||
@DelegateDeserialization(SerializableMeta.class)
|
@DelegateDeserialization(SerializableMeta.class)
|
||||||
class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
static final ItemMetaKey MAP_SCALING = new ItemMetaKey("map_is_scaling", "scaling");
|
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_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 ItemMetaKey MAP_ID = new ItemMetaKey("map", "map-id");
|
||||||
static final byte SCALING_EMPTY = (byte) 0;
|
static final byte SCALING_EMPTY = (byte) 0;
|
||||||
static final byte SCALING_TRUE = (byte) 1;
|
static final byte SCALING_TRUE = (byte) 1;
|
||||||
static final byte SCALING_FALSE = (byte) 2;
|
static final byte SCALING_FALSE = (byte) 2;
|
||||||
|
|
||||||
|
private Integer mapId;
|
||||||
private byte scaling = SCALING_EMPTY;
|
private byte scaling = SCALING_EMPTY;
|
||||||
private String locName;
|
private String locName;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
@ -35,6 +38,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftMetaMap map = (CraftMetaMap) meta;
|
CraftMetaMap map = (CraftMetaMap) meta;
|
||||||
|
this.mapId = map.mapId;
|
||||||
this.scaling = map.scaling;
|
this.scaling = map.scaling;
|
||||||
this.locName = map.locName;
|
this.locName = map.locName;
|
||||||
this.color = map.color;
|
this.color = map.color;
|
||||||
|
@ -43,6 +47,10 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
CraftMetaMap(NBTTagCompound tag) {
|
CraftMetaMap(NBTTagCompound tag) {
|
||||||
super(tag);
|
super(tag);
|
||||||
|
|
||||||
|
if (tag.hasKeyOfType(MAP_ID.NBT, CraftMagicNumbers.NBT.TAG_ANY_NUMBER)) {
|
||||||
|
this.mapId = tag.getInt(MAP_ID.NBT);
|
||||||
|
}
|
||||||
|
|
||||||
if (tag.hasKey(MAP_SCALING.NBT)) {
|
if (tag.hasKey(MAP_SCALING.NBT)) {
|
||||||
this.scaling = tag.getBoolean(MAP_SCALING.NBT) ? SCALING_TRUE : SCALING_FALSE;
|
this.scaling = tag.getBoolean(MAP_SCALING.NBT) ? SCALING_TRUE : SCALING_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +71,11 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
CraftMetaMap(Map<String, Object> map) {
|
CraftMetaMap(Map<String, Object> map) {
|
||||||
super(map);
|
super(map);
|
||||||
|
|
||||||
|
Integer id = SerializableMeta.getObject(Integer.class, map, MAP_ID.BUKKIT, true);
|
||||||
|
if (id != null) {
|
||||||
|
setMapId(id);
|
||||||
|
}
|
||||||
|
|
||||||
Boolean scaling = SerializableMeta.getObject(Boolean.class, map, MAP_SCALING.BUKKIT, true);
|
Boolean scaling = SerializableMeta.getObject(Boolean.class, map, MAP_SCALING.BUKKIT, true);
|
||||||
if (scaling != null) {
|
if (scaling != null) {
|
||||||
setScaling(scaling);
|
setScaling(scaling);
|
||||||
|
@ -83,6 +96,10 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
super.applyToItem(tag);
|
super.applyToItem(tag);
|
||||||
|
|
||||||
|
if (hasMapId()){
|
||||||
|
tag.setInt(MAP_ID.NBT, getMapId());
|
||||||
|
}
|
||||||
|
|
||||||
if (hasScaling()) {
|
if (hasScaling()) {
|
||||||
tag.setBoolean(MAP_SCALING.NBT, isScaling());
|
tag.setBoolean(MAP_SCALING.NBT, isScaling());
|
||||||
}
|
}
|
||||||
|
@ -112,7 +129,22 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isMapEmpty() {
|
boolean isMapEmpty() {
|
||||||
return !(hasScaling() | hasLocationName() || hasColor());
|
return !(hasMapId() || hasScaling() | hasLocationName() || hasColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMapId() {
|
||||||
|
return mapId != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMapId() {
|
||||||
|
return mapId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMapId(int id) {
|
||||||
|
this.mapId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasScaling() {
|
boolean hasScaling() {
|
||||||
|
@ -166,6 +198,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
CraftMetaMap that = (CraftMetaMap) meta;
|
CraftMetaMap that = (CraftMetaMap) meta;
|
||||||
|
|
||||||
return (this.scaling == that.scaling)
|
return (this.scaling == that.scaling)
|
||||||
|
&& (hasMapId() ? that.hasMapId() && this.mapId.equals(that.mapId) : !that.hasMapId())
|
||||||
&& (hasLocationName() ? that.hasLocationName() && this.locName.equals(that.locName) : !that.hasLocationName())
|
&& (hasLocationName() ? that.hasLocationName() && this.locName.equals(that.locName) : !that.hasLocationName())
|
||||||
&& (hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor());
|
&& (hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor());
|
||||||
}
|
}
|
||||||
|
@ -182,6 +215,9 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
final int original;
|
final int original;
|
||||||
int hash = original = super.applyHash();
|
int hash = original = super.applyHash();
|
||||||
|
|
||||||
|
if (hasMapId()) {
|
||||||
|
hash = 61 * hash + mapId.hashCode();
|
||||||
|
}
|
||||||
if (hasScaling()) {
|
if (hasScaling()) {
|
||||||
hash ^= 0x22222222 << (isScaling() ? 1 : -1);
|
hash ^= 0x22222222 << (isScaling() ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
@ -204,6 +240,10 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
||||||
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
||||||
super.serialize(builder);
|
super.serialize(builder);
|
||||||
|
|
||||||
|
if (hasMapId()) {
|
||||||
|
builder.put(MAP_ID.BUKKIT, getMapId());
|
||||||
|
}
|
||||||
|
|
||||||
if (hasScaling()) {
|
if (hasScaling()) {
|
||||||
builder.put(MAP_SCALING.BUKKIT, isScaling());
|
builder.put(MAP_SCALING.BUKKIT, isScaling());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue