
org.bukkit.craftbukkit.inventory.CraftMetaMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of walk-server Show documentation
Show all versions of walk-server Show documentation
A spigot fork to kotlin structure and news.
package org.bukkit.craftbukkit.inventory;
import com.google.common.collect.ImmutableMap;
import net.minecraft.server.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.inventory.meta.MapMeta;
import java.util.Map;
@DelegateDeserialization(SerializableMeta.class)
class CraftMetaMap extends CraftMetaItem implements MapMeta {
static final ItemMetaKey MAP_SCALING = new ItemMetaKey("map_is_scaling", "scaling");
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;
CraftMetaMap(CraftMetaItem meta) {
super(meta);
if (!(meta instanceof CraftMetaMap)) {
return;
}
CraftMetaMap map = (CraftMetaMap) meta;
this.scaling = map.scaling;
}
CraftMetaMap(NBTTagCompound tag) {
super(tag);
if (tag.hasKey(MAP_SCALING.NBT)) {
this.scaling = tag.getBoolean(MAP_SCALING.NBT) ? SCALING_TRUE : SCALING_FALSE;
}
}
CraftMetaMap(Map map) {
super(map);
Boolean scaling = SerializableMeta.getObject(Boolean.class, map, MAP_SCALING.BUKKIT, true);
if (scaling != null) {
setScaling(scaling);
}
}
@Override
void applyToItem(NBTTagCompound tag) {
super.applyToItem(tag);
if (hasScaling()) {
tag.setBoolean(MAP_SCALING.NBT, isScaling());
}
}
@Override
boolean applicableTo(Material type) {
switch (type) {
case MAP:
return true;
default:
return false;
}
}
@Override
boolean isEmpty() {
return super.isEmpty() && isMapEmpty();
}
boolean isMapEmpty() {
return !hasScaling();
}
boolean hasScaling() {
return scaling != SCALING_EMPTY;
}
public boolean isScaling() {
return scaling == SCALING_TRUE;
}
public void setScaling(boolean scaling) {
this.scaling = scaling ? SCALING_TRUE : SCALING_FALSE;
}
@Override
boolean equalsCommon(CraftMetaItem meta) {
if (!super.equalsCommon(meta)) {
return false;
}
if (meta instanceof CraftMetaMap) {
CraftMetaMap that = (CraftMetaMap) meta;
return (this.scaling == that.scaling);
}
return true;
}
@Override
boolean notUncommon(CraftMetaItem meta) {
return super.notUncommon(meta) && (meta instanceof CraftMetaMap || isMapEmpty());
}
@Override
int applyHash() {
final int original;
int hash = original = super.applyHash();
if (hasScaling()) {
hash ^= 0x22222222 << (isScaling() ? 1 : -1);
}
return original != hash ? CraftMetaMap.class.hashCode() ^ hash : hash;
}
public CraftMetaMap clone() {
return (CraftMetaMap) super.clone();
}
@Override
ImmutableMap.Builder serialize(ImmutableMap.Builder builder) {
super.serialize(builder);
if (hasScaling()) {
builder.put(MAP_SCALING.BUKKIT, isScaling());
}
return builder;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy