Search in sources :

Example 66 with ListTag

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

the class EntityAreaEffectCloud method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("clear_custom_effects")) {
        getHelper().clearEffects();
    }
    // -->
    if (mechanism.matches("remove_custom_effect")) {
        PotionEffectType type = PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase());
        if (type != null) {
            getHelper().removeEffect(type);
        }
    }
    // -->
    if (mechanism.matches("custom_effects")) {
        ListTag list = mechanism.valueAsType(ListTag.class);
        getHelper().clearEffects();
        for (String item : list) {
            List<String> potionData = CoreUtilities.split(item, ',', 5);
            if (potionData.size() >= 3) {
                PotionEffectType type = PotionEffectType.getByName(potionData.get(0));
                ElementTag amplifier = new ElementTag(potionData.get(1));
                DurationTag duration = DurationTag.valueOf(potionData.get(2), mechanism.context);
                ElementTag ambient = new ElementTag((potionData.size() > 3) ? potionData.get(3) : "false");
                ElementTag particles = new ElementTag((potionData.size() > 4) ? potionData.get(4) : "true");
                if (type == null || duration == null || !amplifier.isInt() || !ambient.isBoolean() || !particles.isBoolean()) {
                    mechanism.echoError(item + " is not a valid potion effect!");
                } else {
                    getHelper().addEffect(new PotionEffect(type, duration.getTicksAsInt(), amplifier.asInt(), ambient.asBoolean(), particles.asBoolean()), true);
                }
            } else {
                mechanism.echoError(item + " is not a valid potion effect!");
            }
        }
    }
    // -->
    if (mechanism.matches("particle_color") && mechanism.requireObject(ColorTag.class)) {
        getHelper().setColor(mechanism.valueAsType(ColorTag.class).getColor());
    }
    // -->
    if (mechanism.matches("base_potion")) {
        List<String> data = CoreUtilities.split(mechanism.getValue().asString().toUpperCase(), ',');
        if (data.size() != 3) {
            mechanism.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
        } else {
            try {
                PotionType type = PotionType.valueOf(data.get(0));
                boolean extended = type.isExtendable() && CoreUtilities.equalsIgnoreCase(data.get(1), "true");
                boolean upgraded = type.isUpgradeable() && CoreUtilities.equalsIgnoreCase(data.get(2), "true");
                if (extended && upgraded) {
                    mechanism.echoError("Potion cannot be both upgraded and extended");
                } else {
                    getHelper().setBP(type, extended, upgraded);
                }
            } catch (Exception e) {
                mechanism.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
            }
        }
    }
    // -->
    if (mechanism.matches("duration") && mechanism.requireObject(DurationTag.class)) {
        getHelper().setDuration(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
    }
    // -->
    if (mechanism.matches("duration_on_use") && mechanism.requireObject(DurationTag.class)) {
        getHelper().setDurationOnUse(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
    }
    // -->
    if (mechanism.matches("particle") && mechanism.hasValue()) {
        getHelper().setParticle(mechanism.getValue().asString().toUpperCase());
    }
    // -->
    if (mechanism.matches("radius") && mechanism.requireFloat()) {
        getHelper().setRadius(mechanism.getValue().asFloat());
    }
    // -->
    if (mechanism.matches("radius_on_use") && mechanism.requireFloat()) {
        getHelper().setRadiusOnUse(mechanism.getValue().asFloat());
    }
    // -->
    if (mechanism.matches("radius_per_tick") && mechanism.requireFloat()) {
        getHelper().setRadiusPerTick(mechanism.getValue().asFloat());
    }
    // -->
    if (mechanism.matches("reapplication_delay") && mechanism.requireObject(DurationTag.class)) {
        getHelper().setReappDelay(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
    }
    // -->
    if (mechanism.matches("source") && mechanism.requireObject(EntityTag.class)) {
        getHelper().setSource((ProjectileSource) mechanism.valueAsType(EntityTag.class).getBukkitEntity());
    }
    // -->
    if (mechanism.matches("wait_time") && mechanism.requireObject(DurationTag.class)) {
        getHelper().setWaitTime(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ColorTag(com.denizenscript.denizen.objects.ColorTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) PotionType(org.bukkit.potion.PotionType) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 67 with ListTag

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

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

the class EntityArmorPose method getPoseList.

private ListTag getPoseList() {
    ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
    ListTag list = new ListTag();
    for (PosePart posePart : PosePart.values()) {
        list.add(CoreUtilities.toLowerCase(posePart.name()));
        list.addObject(fromEulerAngle(posePart.getAngle(armorStand)));
    }
    return list;
}
Also used : ArmorStand(org.bukkit.entity.ArmorStand) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 69 with ListTag

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

the class EntityAttributeModifiers method getAttributes.

@Deprecated
public ListTag getAttributes() {
    ListTag list = new ListTag();
    for (Attribute attribute : Attribute.values()) {
        AttributeInstance instance = getAttributable().getAttribute(attribute);
        if (instance == null) {
            continue;
        }
        StringBuilder modifiers = new StringBuilder();
        for (AttributeModifier modifier : instance.getModifiers()) {
            modifiers.append("/").append(stringify(modifier));
        }
        list.add(EscapeTagBase.escape(attribute.name()) + "/" + instance.getBaseValue() + modifiers.toString());
    }
    return list;
}
Also used : Attribute(org.bukkit.attribute.Attribute) AttributeInstance(org.bukkit.attribute.AttributeInstance) AttributeModifier(org.bukkit.attribute.AttributeModifier) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 70 with ListTag

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

the class TriggerTrait method trigger.

public TriggerContext trigger(AbstractTrigger triggerClass, PlayerTag player, Map<String, ObjectTag> context) {
    String trigger_type = triggerClass.getName();
    if (!Denizen.getInstance().triggerRegistry.checkCooldown(npc, player, triggerClass)) {
        return new TriggerContext(false);
    }
    if (context == null) {
        context = new HashMap<>();
    }
    if (EngageCommand.getEngaged(npc, player)) {
        context.put("trigger_type", new ElementTag(trigger_type));
        // TODO: Should this be refactored?
        if (new NPCTag(npc).action("unavailable", player, context).containsCaseInsensitive("available")) {
        // If determined available, continue on...
        // else, return a 'non-triggered' state.
        } else {
            return new TriggerContext(false);
        }
    }
    Denizen.getInstance().triggerRegistry.setCooldown(npc, player, triggerClass, getCooldownDuration(trigger_type));
    ListTag determination = new NPCTag(npc).action(trigger_type, player, context);
    return new TriggerContext(determination, true);
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

ListTag (com.denizenscript.denizencore.objects.core.ListTag)122 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)71 MapTag (com.denizenscript.denizencore.objects.core.MapTag)21 ItemStack (org.bukkit.inventory.ItemStack)18 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)14 List (java.util.List)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)13 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)13 Player (org.bukkit.entity.Player)13 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)12 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)9 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)9 ArrayList (java.util.ArrayList)9 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)7 NPC (net.citizensnpcs.api.npc.NPC)7 Entity (org.bukkit.entity.Entity)7