Search in sources :

Example 31 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag 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 32 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class EntityArmorPose method getPoseMap.

public MapTag getPoseMap() {
    ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
    MapTag map = new MapTag();
    for (PosePart posePart : PosePart.values()) {
        map.putObject(CoreUtilities.toLowerCase(posePart.name()), fromEulerAngle(posePart.getAngle(armorStand)));
    }
    return map;
}
Also used : ArmorStand(org.bukkit.entity.ArmorStand) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 33 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class EntityAttributeBaseValues method attributeBaseValues.

public MapTag attributeBaseValues() {
    MapTag result = new MapTag();
    Attributable ent = getAttributable();
    for (Attribute attr : Attribute.values()) {
        AttributeInstance instance = ent.getAttribute(attr);
        if (instance != null) {
            result.putObject(attr.name(), new ElementTag(instance.getBaseValue()));
        }
    }
    return result;
}
Also used : Attributable(org.bukkit.attribute.Attributable) Attribute(org.bukkit.attribute.Attribute) AttributeInstance(org.bukkit.attribute.AttributeInstance) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 34 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag 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 35 with MapTag

use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemPotion method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("potion_effects")) {
        List<ObjectTag> data = new ArrayList<>(CoreUtilities.objectToList(mechanism.value, mechanism.context));
        ObjectTag firstObj = data.remove(0);
        PotionMeta meta = getMeta();
        PotionType type;
        boolean upgraded = false;
        boolean extended = false;
        ColorTag color = null;
        if (firstObj.canBeType(MapTag.class)) {
            MapTag baseEffect = firstObj.asType(MapTag.class, mechanism.context);
            if (baseEffect.getObject("type") != null) {
                ElementTag typeElement = baseEffect.getObject("type").asElement();
                if (!typeElement.matchesEnum(PotionType.class)) {
                    mechanism.echoError("Invalid base potion type '" + typeElement + "': type is required");
                    return;
                }
                type = PotionType.valueOf(typeElement.asString().toUpperCase());
            } else {
                mechanism.echoError("No base potion type specified: type is required");
                return;
            }
            if (baseEffect.getObject("upgraded") != null) {
                ElementTag upgradedElement = baseEffect.getObject("upgraded").asElement();
                if (upgradedElement.isBoolean()) {
                    upgraded = upgradedElement.asBoolean();
                } else {
                    mechanism.echoError("Invalid upgraded state '" + upgradedElement + "': must be a boolean");
                }
            }
            if (baseEffect.getObject("extended") != null) {
                ElementTag extendedElement = baseEffect.getObject("extended").asElement();
                if (extendedElement.isBoolean()) {
                    extended = extendedElement.asBoolean();
                } else {
                    mechanism.echoError("Invalid extended state '" + extendedElement + "': must be a boolean");
                }
            }
            if (baseEffect.getObject("color") != null) {
                ObjectTag colorObj = baseEffect.getObject("color");
                if (colorObj.canBeType(ColorTag.class)) {
                    color = colorObj.asType(ColorTag.class, mechanism.context);
                } else {
                    mechanism.echoError("Invalid color '" + colorObj + "': must be a valid ColorTag");
                }
            }
        } else {
            String[] d1 = firstObj.toString().split(",");
            try {
                type = PotionType.valueOf(d1[0].toUpperCase());
            } catch (IllegalArgumentException ex) {
                mechanism.echoError("Invalid base potion type '" + d1[0] + "': type is required");
                return;
            }
            upgraded = CoreUtilities.equalsIgnoreCase(d1[1], "true");
            extended = CoreUtilities.equalsIgnoreCase(d1[2], "true");
            if (d1.length > 3) {
                ColorTag temp = ColorTag.valueOf(d1[3].replace("&comma", ","), mechanism.context);
                if (temp == null) {
                    mechanism.echoError("Invalid color '" + d1[3] + "': must be a valid ColorTag");
                } else {
                    color = temp;
                }
            }
        }
        if (upgraded && !type.isUpgradeable()) {
            mechanism.echoError("Cannot upgrade potion of type '" + type.name() + "'");
            upgraded = false;
        }
        if (extended && !type.isExtendable()) {
            mechanism.echoError("Cannot extend potion of type '" + type.name() + "'");
            extended = false;
        }
        if (upgraded && extended) {
            mechanism.echoError("Cannot both upgrade and extend a potion");
            extended = false;
        }
        if (color != null) {
            meta.setColor(color.getColor());
        }
        meta.setBasePotionData(new PotionData(type, extended, upgraded));
        meta.clearCustomEffects();
        for (ObjectTag effectObj : data) {
            PotionEffect effect;
            if (effectObj.canBeType(MapTag.class)) {
                effect = parseEffect(effectObj.asType(MapTag.class, mechanism.context), mechanism.context);
            } else {
                effect = parseEffect(effectObj.toString(), mechanism.context);
            }
            if (effect != null) {
                meta.addCustomEffect(effect, false);
            } else {
                mechanism.echoError("Invalid potion effect '" + effectObj + "'");
            }
        }
        item.setItemMeta(meta);
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) ColorTag(com.denizenscript.denizen.objects.ColorTag) PotionMeta(org.bukkit.inventory.meta.PotionMeta) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) PotionData(org.bukkit.potion.PotionData) PotionType(org.bukkit.potion.PotionType) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

MapTag (com.denizenscript.denizencore.objects.core.MapTag)46 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)30 ListTag (com.denizenscript.denizencore.objects.core.ListTag)23 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)9 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)8 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ItemStack (org.bukkit.inventory.ItemStack)5 ColorTag (com.denizenscript.denizen.objects.ColorTag)4 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 Attributable (org.bukkit.attribute.Attributable)3 Attribute (org.bukkit.attribute.Attribute)3 AttributeInstance (org.bukkit.attribute.AttributeInstance)3 AttributeModifier (org.bukkit.attribute.AttributeModifier)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 FlaggableObject (com.denizenscript.denizencore.flags.FlaggableObject)2 Attribute (com.denizenscript.denizencore.tags.Attribute)2 ArmorStandMeta (com.destroystokyo.paper.inventory.meta.ArmorStandMeta)2 UUID (java.util.UUID)2