Search in sources :

Example 1 with Tag

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));
    }
}
Also used : ByteTag(com.denizenscript.denizen.nms.util.jnbt.ByteTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) Tag(com.denizenscript.denizen.nms.util.jnbt.Tag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ByteTag(com.denizenscript.denizen.nms.util.jnbt.ByteTag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ByteTag (com.denizenscript.denizen.nms.util.jnbt.ByteTag)1 CompoundTag (com.denizenscript.denizen.nms.util.jnbt.CompoundTag)1 Tag (com.denizenscript.denizen.nms.util.jnbt.Tag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 LinkedHashMap (java.util.LinkedHashMap)1