Search in sources :

Example 51 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Essentials by drtshock.

the class Commandpotion method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final ItemStack stack = user.getItemInHand();
    if (args.length == 0) {
        final Set<String> potionslist = new TreeSet<>();
        for (Map.Entry<String, PotionEffectType> entry : Potions.entrySet()) {
            final String potionName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
            if (potionslist.contains(potionName) || (user.isAuthorized("essentials.potion." + potionName))) {
                potionslist.add(entry.getKey());
            }
        }
        throw new NotEnoughArgumentsException(tl("potions", StringUtil.joinList(potionslist.toArray())));
    }
    boolean holdingPotion = stack.getType() == Material.POTION;
    if (!holdingPotion && ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_9_R1)) {
        holdingPotion = stack.getType() == Material.SPLASH_POTION || stack.getType() == Material.LINGERING_POTION;
    }
    if (holdingPotion) {
        PotionMeta pmeta = (PotionMeta) stack.getItemMeta();
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("clear")) {
                pmeta.clearCustomEffects();
                stack.setItemMeta(pmeta);
            } else if (args[0].equalsIgnoreCase("apply") && user.isAuthorized("essentials.potion.apply")) {
                for (PotionEffect effect : pmeta.getCustomEffects()) {
                    effect.apply(user.getBase());
                }
            } else if (args.length < 3) {
                throw new NotEnoughArgumentsException();
            } else {
                final MetaItemStack mStack = new MetaItemStack(stack);
                for (String arg : args) {
                    mStack.addPotionMeta(user.getSource(), true, arg, ess);
                }
                if (mStack.completePotion()) {
                    pmeta = (PotionMeta) mStack.getItemStack().getItemMeta();
                    stack.setItemMeta(pmeta);
                } else {
                    user.sendMessage(tl("invalidPotion"));
                    throw new NotEnoughArgumentsException();
                }
            }
        }
    } else {
        throw new Exception(tl("holdPotion"));
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) PotionMeta(org.bukkit.inventory.meta.PotionMeta) MetaItemStack(com.earth2me.essentials.MetaItemStack) TreeSet(java.util.TreeSet) MetaItemStack(com.earth2me.essentials.MetaItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map)

Example 52 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project xAuth by CypherX.

the class PlayerDataHandler method buildPotFx.

private Collection<PotionEffect> buildPotFx(String str) {
    String[] effectSplit = str.split(";");
    String[] type = effectSplit[0].split(",");
    String[] duration = effectSplit[1].split(",");
    String[] amplifier = effectSplit[2].split(",");
    Collection<PotionEffect> effects = new ArrayList<PotionEffect>();
    for (int i = 0; i < type.length; i++) {
        PotionEffectType potFxType = PotionEffectType.getById(Integer.parseInt(type[i]));
        int potFxDur = Integer.parseInt(duration[i]);
        int potFxAmp = Integer.parseInt(amplifier[i]);
        effects.add(new PotionEffect(potFxType, potFxDur, potFxAmp));
    }
    return effects;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList)

Example 53 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Arcade2 by ShootGame.

the class GamePlayer method reset.

public void reset() {
    if (!this.isOnline()) {
        return;
    }
    Player bukkit = this.getBukkit();
    this.refresh();
    bukkit.closeInventory();
    this.getPlayer().clearInventory(true);
    this.resetHealth();
    this.setLevel(PlayerLevel.getDefaultLevel());
    bukkit.setAbsorption(AbsorptionContent.Config.DEFAULT_ABSORPTION);
    bukkit.setAllowFlight(CanFlyContent.Config.DEFAULT_CAN_FLY);
    bukkit.setArrowsStuck(RemoveArrowsContent.FINAL_COUNT);
    bukkit.setExhaustion(ExhaustionContent.Config.DEFAULT_LEVEL);
    bukkit.setExp((float) ExperienceContent.Config.DEFAULT_EXPERIENCE.getValue());
    bukkit.setFallDistance(FallDistanceContent.Config.DEFAULT_DISTANCE);
    bukkit.setFireTicks(TimeUtils.toTicksInt(BurnContent.Config.DEFAULT_TIME));
    bukkit.setFlying(FlyContent.Config.DEFAULT_FLY);
    bukkit.setFlySpeed(FlySpeedContent.Config.DEFAULT_SPEED);
    bukkit.setFoodLevel(HungerContent.Config.DEFAULT_LEVEL);
    bukkit.setGameMode(GameModeContent.Config.DEFAULT_GAME_MODE);
    bukkit.setGlowing(GlowContent.Config.DEFAULT_GLOW);
    bukkit.setGravity(GravityContent.Config.DEFAULT_GRAVITY);
    bukkit.setKnockbackReduction(KnockbackContent.Config.DEFAULT_KNOCKBACK);
    bukkit.setSaturation(SaturationContent.Config.DEFAULT_SATURATION);
    bukkit.setSilent(SilentContent.Config.DEFAULT_SILENT);
    bukkit.setSneaking(false);
    bukkit.setSprinting(false);
    bukkit.setVelocity(VelocityContent.Config.DEFAULT_VELOCITY);
    bukkit.setWalkSpeed(WalkSpeedContent.Config.DEFAULT_SPEED);
    bukkit.resetPlayerTime();
    bukkit.resetPlayerWeather();
    bukkit.resetTitle();
    for (PotionEffectType effect : PotionEffectType.values()) {
        bukkit.removePotionEffect(effect);
    }
    if (this.attributeMap != null) {
        for (AttributeKey key : this.attributeMap.getTracking()) {
            Attribute attribute = this.attributeMap.getAttribute(key);
            if (attribute != null) {
                attribute.removeAllModifers();
            }
        }
        this.attributeMap.unsubscribeAll();
    }
    this.getMojang().reset();
}
Also used : AttributeKey(pl.themolka.arcade.attribute.AttributeKey) EntityPlayer(net.minecraft.server.EntityPlayer) Player(org.bukkit.entity.Player) ArcadePlayer(pl.themolka.arcade.session.ArcadePlayer) Attribute(pl.themolka.arcade.attribute.Attribute) PotionEffectType(org.bukkit.potion.PotionEffectType)

Example 54 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project TriggerReactor by wysohn.

the class CommonFunctions method makePotionEffect.

@Override
public PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles) {
    PotionEffectType type = null;
    type = PotionEffectType.getByName(EffectType);
    if (type != null) {
        return new PotionEffect(type, duration, amplifier, ambient, particles);
    } else {
        return null;
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType)

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