diff options
author | md_5 <git@md-5.net> | 2018-07-24 10:18:06 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-07-24 10:18:06 +1000 |
commit | f732acf24fce2e8e292f1c486eb7025cce892b7b (patch) | |
tree | bd4593532bc61361c7f639658ac69a4f620006b9 /src/main/java/org | |
parent | fbf903a1bcbb180194338da188077dba0ab93199 (diff) | |
download | craftbukkit-f732acf24fce2e8e292f1c486eb7025cce892b7b.tar craftbukkit-f732acf24fce2e8e292f1c486eb7025cce892b7b.tar.gz craftbukkit-f732acf24fce2e8e292f1c486eb7025cce892b7b.tar.lz craftbukkit-f732acf24fce2e8e292f1c486eb7025cce892b7b.tar.xz craftbukkit-f732acf24fce2e8e292f1c486eb7025cce892b7b.zip |
Add map ID API
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java index d35c5b03..5f075f65 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java @@ -13,16 +13,19 @@ import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.inventory.meta.MapMeta; import com.google.common.collect.ImmutableMap; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; @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_ID = new ItemMetaKey("map", "map-id"); static final byte SCALING_EMPTY = (byte) 0; static final byte SCALING_TRUE = (byte) 1; static final byte SCALING_FALSE = (byte) 2; + private Integer mapId; private byte scaling = SCALING_EMPTY; private String locName; private Color color; @@ -35,6 +38,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { } CraftMetaMap map = (CraftMetaMap) meta; + this.mapId = map.mapId; this.scaling = map.scaling; this.locName = map.locName; this.color = map.color; @@ -43,6 +47,10 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { CraftMetaMap(NBTTagCompound 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)) { 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) { 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); if (scaling != null) { setScaling(scaling); @@ -83,6 +96,10 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { void applyToItem(NBTTagCompound tag) { super.applyToItem(tag); + if (hasMapId()){ + tag.setInt(MAP_ID.NBT, getMapId()); + } + if (hasScaling()) { tag.setBoolean(MAP_SCALING.NBT, isScaling()); } @@ -112,7 +129,22 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { } 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() { @@ -166,6 +198,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { CraftMetaMap that = (CraftMetaMap) meta; 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()) && (hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor()); } @@ -182,6 +215,9 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { final int original; int hash = original = super.applyHash(); + if (hasMapId()) { + hash = 61 * hash + mapId.hashCode(); + } if (hasScaling()) { 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) { super.serialize(builder); + if (hasMapId()) { + builder.put(MAP_ID.BUKKIT, getMapId()); + } + if (hasScaling()) { builder.put(MAP_SCALING.BUKKIT, isScaling()); } |