use of com.denizenscript.denizen.nms.util.jnbt.Tag in project Denizen-For-Bukkit by DenizenScript.
the class ItemFrameInvisible method adjust.
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("invisible") && mechanism.requireBoolean()) {
CompoundTag compoundTag = NMSHandler.getItemHelper().getNbtData(item.getItemStack());
Map<String, Tag> result = new LinkedHashMap<>(compoundTag.getValue());
CompoundTag entityTag = (CompoundTag) result.get("EntityTag");
Map<String, Tag> entMap;
if (entityTag != null) {
entMap = new LinkedHashMap<>(entityTag.getValue());
} else {
entMap = new LinkedHashMap<>();
}
if (mechanism.getValue().asBoolean()) {
entMap.put("Invisible", new ByteTag((byte) 1));
} else {
entMap.remove("Invisible");
}
if (entMap.isEmpty()) {
result.remove("EntityTag");
} else {
result.put("EntityTag", NMSHandler.getInstance().createCompoundTag(entMap));
}
compoundTag = NMSHandler.getInstance().createCompoundTag(result);
item.setItemStack(NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag));
}
}
Aggregations