Search in sources :

Example 6 with StringHolder

use of com.denizenscript.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.

the class EntityArmorPose method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("armor_pose")) {
        ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
        if (mechanism.value.canBeType(MapTag.class)) {
            MapTag map = mechanism.valueAsType(MapTag.class);
            for (Map.Entry<StringHolder, ObjectTag> entry : map.map.entrySet()) {
                PosePart posePart = PosePart.fromName(entry.getKey().str);
                if (posePart == null) {
                    mechanism.echoError("Invalid pose part specified: " + entry.getKey().str);
                } else {
                    posePart.setAngle(armorStand, toEulerAngle(entry.getValue().asType(LocationTag.class, mechanism.context)));
                }
            }
        } else {
            ListTag list = mechanism.valueAsType(ListTag.class);
            Iterator<String> iterator = list.iterator();
            while (iterator.hasNext()) {
                String name = iterator.next();
                String angle = iterator.next();
                PosePart posePart = PosePart.fromName(name);
                if (posePart == null) {
                    mechanism.echoError("Invalid pose part specified: " + name + "; ignoring next: " + angle);
                } else {
                    posePart.setAngle(armorStand, toEulerAngle(LocationTag.valueOf(angle, mechanism.context)));
                }
            }
        }
    }
}
Also used : StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ArmorStand(org.bukkit.entity.ArmorStand) Map(java.util.Map) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 7 with StringHolder

use of com.denizenscript.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.

the class EntityAttributeBaseValues method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("attribute_base_values") && mechanism.requireObject(MapTag.class)) {
        MapTag input = mechanism.valueAsType(MapTag.class);
        Attributable ent = getAttributable();
        for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
            Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
            AttributeInstance instance = ent.getAttribute(attr);
            if (instance == null) {
                mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
                continue;
            }
            ElementTag value = subValue.getValue().asElement();
            if (!value.isDouble()) {
                mechanism.echoError("Invalid input '" + value + "': must be a decimal number.");
                continue;
            }
            instance.setBaseValue(value.asDouble());
        }
    }
}
Also used : Attributable(org.bukkit.attribute.Attributable) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) Attribute(org.bukkit.attribute.Attribute) AttributeInstance(org.bukkit.attribute.AttributeInstance) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Map(java.util.Map) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 8 with StringHolder

use of com.denizenscript.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.

the class ItemRawNBT method setFullNBT.

public void setFullNBT(ItemTag item, MapTag input, TagContext context, boolean retainOld) {
    CompoundTag compoundTag = retainOld ? NMSHandler.getItemHelper().getNbtData(item.getItemStack()) : null;
    Map<String, Tag> result = compoundTag == null ? new LinkedHashMap<>() : new LinkedHashMap<>(compoundTag.getValue());
    for (Map.Entry<StringHolder, ObjectTag> entry : input.map.entrySet()) {
        try {
            Tag tag = convertObjectToNbt(entry.getValue().toString(), context, "(item).");
            if (tag != null) {
                result.put(entry.getKey().str, tag);
            }
        } catch (Exception ex) {
            Debug.echoError("Raw_Nbt input failed for root key '" + entry.getKey().str + "'.");
            Debug.echoError(ex);
            return;
        }
    }
    compoundTag = NMSHandler.getInstance().createCompoundTag(result);
    item.setItemStack(NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag));
}
Also used : StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 9 with StringHolder

use of com.denizenscript.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.

the class ItemRawNBT method getNonDefaultNBTMap.

public MapTag getNonDefaultNBTMap() {
    MapTag result = getFullNBTMap();
    for (StringHolder key : defaultNbtKeys) {
        result.map.remove(key);
    }
    if (item.getBukkitMaterial() == Material.ITEM_FRAME) {
        MapTag entityMap = (MapTag) result.getObject("EntityTag");
        if (entityMap != null) {
            entityMap.putObject("Invisible", null);
            if (entityMap.map.isEmpty()) {
                result.putObject("EntityTag", null);
            }
        }
    }
    if (item.getBukkitMaterial() == Material.ARMOR_STAND) {
        MapTag entityMap = (MapTag) result.getObject("EntityTag");
        if (entityMap != null) {
            entityMap.putObject("Pose", null);
            entityMap.putObject("Small", null);
            entityMap.putObject("NoBasePlate", null);
            entityMap.putObject("Marker", null);
            entityMap.putObject("Invisible", null);
            entityMap.putObject("ShowArms", null);
            if (entityMap.map.isEmpty()) {
                result.putObject("EntityTag", null);
            }
        }
    }
    return result;
}
Also used : StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 10 with StringHolder

use of com.denizenscript.denizencore.utilities.text.StringHolder in project Denizen-For-Bukkit by DenizenScript.

the class ConstantsTrait method rebuildAssignmentConstants.

public void rebuildAssignmentConstants() {
    assignmentConstants.clear();
    if (!npc.hasTrait(AssignmentTrait.class)) {
        npc.removeTrait(ConstantsTrait.class);
        return;
    }
    AssignmentTrait trait = npc.getOrAddTrait(AssignmentTrait.class);
    for (AssignmentScriptContainer container : trait.containerCache) {
        if (container != null) {
            if (container.contains("default constants", Map.class)) {
                for (StringHolder constant : container.getConfigurationSection("default constants").getKeys(false)) {
                    assignmentConstants.put(CoreUtilities.toLowerCase(constant.str), container.getString("default constants." + constant.str.toUpperCase(), ""));
                }
            }
        }
    }
}
Also used : StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)

Aggregations

StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)18 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)11 MapTag (com.denizenscript.denizencore.objects.core.MapTag)8 ListTag (com.denizenscript.denizencore.objects.core.ListTag)7 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)6 YamlConfiguration (com.denizenscript.denizencore.utilities.YamlConfiguration)6 ItemTag (com.denizenscript.denizen.objects.ItemTag)4 Map (java.util.Map)4 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 EnchantmentTag (com.denizenscript.denizen.objects.EnchantmentTag)2 NPCTag (com.denizenscript.denizen.objects.NPCTag)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 AbstractFlagTracker (com.denizenscript.denizencore.flags.AbstractFlagTracker)2 Mechanism (com.denizenscript.denizencore.objects.Mechanism)2 TimeTag (com.denizenscript.denizencore.objects.core.TimeTag)2 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)2 TagContext (com.denizenscript.denizencore.tags.TagContext)2