Search in sources :

Example 46 with ElementTag

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

the class ItemPotion method effectToMap.

public static MapTag effectToMap(PotionEffect effect) {
    MapTag map = new MapTag();
    map.putObject("type", new ElementTag(effect.getType().getName()));
    map.putObject("amplifier", new ElementTag(effect.getAmplifier()));
    map.putObject("duration", new DurationTag((long) effect.getDuration()));
    map.putObject("ambient", new ElementTag(effect.isAmbient()));
    map.putObject("particles", new ElementTag(effect.hasParticles()));
    map.putObject("icon", new ElementTag(effect.hasIcon()));
    return map;
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 47 with ElementTag

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

the class ItemPotion method getMapTagData.

public ListTag getMapTagData() {
    ListTag result = new ListTag();
    MapTag base = new MapTag();
    PotionMeta meta = getMeta();
    base.putObject("type", new ElementTag(meta.getBasePotionData().getType().name()));
    base.putObject("upgraded", new ElementTag(meta.getBasePotionData().isUpgraded()));
    base.putObject("extended", new ElementTag(meta.getBasePotionData().isExtended()));
    if (meta.hasColor()) {
        base.putObject("color", new ColorTag(meta.getColor()));
    }
    result.addObject(base);
    for (PotionEffect effect : meta.getCustomEffects()) {
        result.addObject(effectToMap(effect));
    }
    return result;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ColorTag(com.denizenscript.denizen.objects.ColorTag) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 48 with ElementTag

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

the class ItemPotion method parseEffect.

public static PotionEffect parseEffect(String str, TagContext context) {
    String[] d2 = str.split(",");
    PotionEffectType type;
    try {
        type = PotionEffectType.getByName(d2[0].toUpperCase());
    } catch (IllegalArgumentException ex) {
        if (context.showErrors()) {
            Debug.echoError("Invalid potion effect type '" + d2[0] + "'");
        }
        return null;
    }
    if (d2.length < 3) {
        return null;
    }
    // NOTE: amplifier and duration are swapped around in the input format
    // as compared to the PotionEffect constructor!
    int duration = new ElementTag(d2[2]).asInt();
    int amplifier = new ElementTag(d2[1]).asInt();
    boolean ambient = true;
    boolean particles = true;
    if (d2.length > 3) {
        ambient = new ElementTag(d2[3]).asBoolean();
        particles = new ElementTag(d2[4]).asBoolean();
    }
    boolean icon = false;
    if (d2.length > 5) {
        ElementTag check = new ElementTag(d2[5]);
        if (check.isBoolean()) {
            icon = check.asBoolean();
        }
    }
    return new PotionEffect(type, duration, amplifier, ambient, particles, icon);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 49 with ElementTag

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

the class ItemSpawnerMaxNearbyEntities method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("spawner_max_nearby_entities")) {
        BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
        CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
        return new ElementTag(state.getMaxNearbyEntities()).getObjectAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 50 with ElementTag

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

the class ItemAttributeModifiers method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
        Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = LinkedHashMultimap.create();
        MapTag map = mechanism.valueAsType(MapTag.class);
        for (Map.Entry<StringHolder, ObjectTag> mapEntry : map.map.entrySet()) {
            org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(mapEntry.getKey().str.toUpperCase());
            for (ObjectTag listValue : CoreUtilities.objectToList(mapEntry.getValue(), mechanism.context)) {
                metaMap.put(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
            }
        }
        ItemMeta meta = item.getItemMeta();
        meta.setAttributeModifiers(metaMap);
        item.setItemMeta(meta);
    }
    // -->
    if (mechanism.matches("add_attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
        ItemMeta meta = item.getItemMeta();
        MapTag input = mechanism.valueAsType(MapTag.class);
        for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
            org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(subValue.getKey().str.toUpperCase());
            for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
                meta.addAttributeModifier(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
            }
        }
        item.setItemMeta(meta);
    }
    // -->
    if (mechanism.matches("remove_attribute_modifiers") && mechanism.requireObject(ListTag.class)) {
        ItemMeta meta = item.getItemMeta();
        ArrayList<String> inputList = new ArrayList<>(mechanism.valueAsType(ListTag.class));
        for (String toRemove : new ArrayList<>(inputList)) {
            if (new ElementTag(toRemove).matchesEnum(org.bukkit.attribute.Attribute.class)) {
                inputList.remove(toRemove);
                org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(toRemove.toUpperCase());
                meta.removeAttributeModifier(attr);
            }
        }
        for (String toRemove : inputList) {
            UUID id = UUID.fromString(toRemove);
            Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = meta.getAttributeModifiers();
            for (org.bukkit.attribute.Attribute attribute : metaMap.keys()) {
                for (AttributeModifier modifer : metaMap.get(attribute)) {
                    if (modifer.getUniqueId().equals(id)) {
                        meta.removeAttributeModifier(attribute, modifer);
                        break;
                    }
                }
            }
        }
        item.setItemMeta(meta);
    }
}
Also used : Attribute(com.denizenscript.denizencore.tags.Attribute) ArrayList(java.util.ArrayList) AttributeModifier(org.bukkit.attribute.AttributeModifier) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12