Search in sources :

Example 46 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Minigames by AddstarMC.

the class ApplyPotionAction method displayMenu.

@Override
public boolean displayMenu(MinigamePlayer player, Menu previous) {
    Menu m = new Menu(3, "Apply Potion", player);
    m.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), previous), m.getSize() - 9);
    List<String> pots = new ArrayList<>(PotionEffectType.values().length);
    for (PotionEffectType type : PotionEffectType.values()) {
        if (type != null) {
            pots.add(MinigameUtils.capitalize(type.getName().replace("_", " ")));
        }
    }
    m.addItem(new MenuItemList("Potion Type", Material.POTION, new Callback<String>() {

        @Override
        public void setValue(String value) {
            type.setFlag(value.toUpperCase().replace(" ", "_"));
        }

        @Override
        public String getValue() {
            return MinigameUtils.capitalize(type.getFlag().replace("_", " "));
        }
    }, pots));
    m.addItem(new MenuItemTime("Duration", Material.CLOCK, new Callback<Integer>() {

        @Override
        public void setValue(Integer value) {
            dur.setFlag(value);
        }

        @Override
        public Integer getValue() {
            return dur.getFlag();
        }
    }, 0, 86400));
    m.addItem(new MenuItemInteger("Level", Material.STONE, new Callback<Integer>() {

        @Override
        public void setValue(Integer value) {
            amp.setFlag(value);
        }

        @Override
        public Integer getValue() {
            return amp.getFlag();
        }
    }, 0, 100));
    m.displayMenu(player);
    return true;
}
Also used : MenuItemInteger(au.com.mineauz.minigames.menu.MenuItemInteger) Callback(au.com.mineauz.minigames.menu.Callback) MenuItemList(au.com.mineauz.minigames.menu.MenuItemList) MenuItemInteger(au.com.mineauz.minigames.menu.MenuItemInteger) PotionEffectType(org.bukkit.potion.PotionEffectType) MenuItemPage(au.com.mineauz.minigames.menu.MenuItemPage) MenuItemTime(au.com.mineauz.minigames.menu.MenuItemTime) ArrayList(java.util.ArrayList) Menu(au.com.mineauz.minigames.menu.Menu)

Example 47 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Denizen-For-Bukkit by DenizenScript.

the class EntityAreaEffectCloud method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("base_potion")) {
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("type")) {
            return new ElementTag(getHelper().getBPName()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("is_upgraded")) {
            return new ElementTag(getHelper().getBPUpgraded()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("is_extended")) {
            return new ElementTag(getHelper().getBPExtended()).getObjectAttribute(attribute.fulfill(1));
        }
        return new ElementTag(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended()).getObjectAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("particle")) {
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("color")) {
            return new ColorTag(getHelper().getColor()).getObjectAttribute(attribute.fulfill(1));
        }
        return new ElementTag(getHelper().getParticle()).getObjectAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("duration")) {
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("on_use")) {
            return new DurationTag(getHelper().getDurationOnUse()).getObjectAttribute(attribute.fulfill(1));
        }
        return new DurationTag(getHelper().getDuration()).getObjectAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("radius")) {
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("on_use")) {
            return new ElementTag(getHelper().getRadiusOnUse()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("per_tick")) {
            return new ElementTag(getHelper().getRadiusPerTick()).getObjectAttribute(attribute.fulfill(1));
        }
        return new ElementTag(getHelper().getRadius()).getObjectAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("reapplication_delay")) {
        return new DurationTag(getHelper().getReappDelay()).getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("wait_time")) {
        return new DurationTag(getHelper().getWaitTime()).getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_custom_effect")) {
        if (attribute.hasParam()) {
            PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
            for (PotionEffect effect : getHelper().getCustomEffects()) {
                if (effect.getType().equals(effectType)) {
                    return new ElementTag(true).getObjectAttribute(attribute.fulfill(1));
                }
            }
            return new ElementTag(false).getObjectAttribute(attribute.fulfill(1));
        }
        return new ElementTag(getHelper().hasCustomEffects()).getObjectAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("source")) {
        ProjectileSource shooter = getHelper().getSource();
        if (shooter instanceof LivingEntity) {
            return new EntityTag((LivingEntity) shooter).getObjectAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("custom_effects")) {
        List<PotionEffect> effects = getHelper().getCustomEffects();
        if (!attribute.hasParam()) {
            ListTag list = new ListTag();
            for (PotionEffect effect : effects) {
                list.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles());
            }
            return list.getObjectAttribute(attribute.fulfill(1));
        }
        int val = attribute.getIntParam() - 1;
        if (val < 0 || val >= effects.size()) {
            return null;
        }
        attribute = attribute.fulfill(1);
        PotionEffect effect = effects.get(val);
        // -->
        if (attribute.startsWith("type")) {
            return new ElementTag(effect.getType().getName()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("amplifier")) {
            return new ElementTag(effect.getAmplifier()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("duration")) {
            return new DurationTag((long) effect.getDuration()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("has_particles")) {
            return new ElementTag(effect.hasParticles()).getObjectAttribute(attribute.fulfill(1));
        }
        // -->
        if (attribute.startsWith("is_ambient")) {
            return new ElementTag(effect.isAmbient()).getObjectAttribute(attribute.fulfill(1));
        }
        return new ElementTag(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles()).getObjectAttribute(attribute);
    }
    return null;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) 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) ProjectileSource(org.bukkit.projectiles.ProjectileSource) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 48 with PotionEffectType

use of org.bukkit.potion.PotionEffectType 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 49 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Denizen-For-Bukkit by DenizenScript.

the class ItemPotion method parseEffect.

public static PotionEffect parseEffect(MapTag effectMap, TagContext context) {
    PotionEffectType type;
    DurationTag duration = new DurationTag(0);
    int amplifier = 0;
    boolean ambient = true;
    boolean particles = true;
    boolean icon = false;
    if (effectMap.getObject("type") != null) {
        String typeString = effectMap.getObject("type").toString();
        type = PotionEffectType.getByName(typeString);
        if (type == null) {
            if (context.showErrors()) {
                Debug.echoError("Invalid potion effect type '" + typeString + "': effect type is required.");
            }
            return null;
        }
    } else {
        if (context.showErrors()) {
            Debug.echoError("Invalid potion effect type: effect type is required.");
        }
        return null;
    }
    if (effectMap.getObject("amplifier") != null) {
        ElementTag amplifierElement = effectMap.getObject("amplifier").asElement();
        if (amplifierElement.isInt()) {
            amplifier = amplifierElement.asInt();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid amplifier '" + amplifierElement + "': must be an integer.");
        }
    }
    if (effectMap.getObject("duration") != null) {
        ObjectTag durationObj = effectMap.getObject("duration");
        if (durationObj.canBeType(DurationTag.class)) {
            duration = durationObj.asType(DurationTag.class, context);
        } else if (context.showErrors()) {
            Debug.echoError("Invalid duration '" + durationObj + "': must be a valid DurationTag");
        }
    }
    if (effectMap.getObject("ambient") != null) {
        ElementTag ambientElement = effectMap.getObject("ambient").asElement();
        if (ambientElement.isBoolean()) {
            ambient = ambientElement.asBoolean();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid ambient state '" + ambientElement + "': must be a boolean.");
        }
    }
    if (effectMap.getObject("particles") != null) {
        ElementTag particlesElement = effectMap.getObject("particles").asElement();
        if (particlesElement.isBoolean()) {
            particles = particlesElement.asBoolean();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid particles state '" + particlesElement + "': must be a boolean.");
        }
    }
    if (effectMap.getObject("icon") != null) {
        ElementTag iconElement = effectMap.getObject("icon").asElement();
        if (iconElement.isBoolean()) {
            icon = iconElement.asBoolean();
        } else if (context.showErrors()) {
            Debug.echoError("Invalid icon state '" + iconElement + "': must be a boolean.");
        }
    }
    return new PotionEffect(type, duration.getTicksAsInt(), amplifier, ambient, particles, icon);
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 50 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Denizen-For-Bukkit by DenizenScript.

the class CastCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    PotionEffectType effect = (PotionEffectType) scriptEntry.getObject("effect");
    int amplifier = scriptEntry.getElement("amplifier").asInt();
    DurationTag duration = scriptEntry.getObjectTag("duration");
    boolean remove = scriptEntry.getElement("remove").asBoolean();
    ElementTag showParticles = scriptEntry.getElement("show_particles");
    ElementTag ambient = scriptEntry.getElement("ambient");
    ElementTag showIcon = scriptEntry.getElement("show_icon");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Target(s)", entities.toString()), db("Effect", effect.getName()), db("Amplifier", amplifier), duration, ambient, showParticles, showIcon);
    }
    boolean amb = ambient.asBoolean();
    boolean showP = showParticles.asBoolean();
    boolean icon = showIcon.asBoolean();
    for (EntityTag entity : entities) {
        if (entity.getLivingEntity().hasPotionEffect(effect)) {
            entity.getLivingEntity().removePotionEffect(effect);
        }
        if (remove) {
            continue;
        }
        PotionEffect potion = new PotionEffect(effect, duration.getTicksAsInt(), amplifier, amb, showP, icon);
        if (!potion.apply(entity.getLivingEntity())) {
            Debug.echoError(scriptEntry, "Bukkit was unable to apply '" + potion.getType().getName() + "' to '" + entity.toString() + "'.");
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

PotionEffectType (org.bukkit.potion.PotionEffectType)54 PotionEffect (org.bukkit.potion.PotionEffect)41 ArrayList (java.util.ArrayList)12 Player (org.bukkit.entity.Player)8 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)6 HashMap (java.util.HashMap)6 ItemStack (org.bukkit.inventory.ItemStack)6 Map (java.util.Map)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 PotionType (org.bukkit.potion.PotionType)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)4 Material (org.bukkit.Material)4 LivingEntity (org.bukkit.entity.LivingEntity)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 EntityTag (com.denizenscript.denizen.objects.EntityTag)3 File (java.io.File)3 IOException (java.io.IOException)3 List (java.util.List)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 Entity (org.bukkit.entity.Entity)3