Search in sources :

Example 41 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.

the class BeaconEntity method getEffect.

public PotionEffect getEffect(BeaconEffectPriority priority) {
    PotionEffectType type = PotionEffectType.getById(priority == BeaconEffectPriority.PRIMARY ? primaryEffectId : secondaryEffectId);
    if (type == null) {
        return null;
    }
    int effectDuration = (9 + levels * 2) * 20;
    int effectAmplifier = levels >= 4 && primaryEffectId == secondaryEffectId ? 1 : 0;
    return new PotionEffect(type, effectDuration, effectAmplifier, true, true);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType)

Example 42 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.

the class GlowPotionEffect method parsePotionEffectId.

/**
 * Parses a PotionEffect id or name if possible.
 *
 * @param effectName The PotionEffectType name.
 * @return The associated PotionEffectType, or null.
 */
public static PotionEffectType parsePotionEffectId(String effectName) {
    try {
        int effectId = Integer.parseInt(effectName);
        PotionEffectType type = PotionEffectType.getById(effectId);
        if (type == null) {
            return null;
        } else {
            return type;
        }
    } catch (NumberFormatException exc) {
        if (effectName.startsWith("minecraft:")) {
            PotionEffectType type = GlowPotionEffect.getByVanillaId(effectName);
            if (type == null) {
                return null;
            } else {
                return type;
            }
        } else {
            PotionEffectType type = PotionEffectType.getByName(effectName);
            if (type == null) {
                return null;
            } else {
                return type;
            }
        }
    }
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType)

Example 43 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.

the class LivingEntityStore method load.

// these tags that apply to living entities only are documented as global:
// - short "Air"
// - string "CustomName"
// - bool "CustomNameVisible"
// todo: the following tags
// - float "AbsorptionAmount"
// - short "HurtTime"
// - int "HurtByTimestamp"
// - short "DeathTime"
// - bool "PersistenceRequired"
// on ActiveEffects, bool "ShowParticles"
@Override
public void load(T entity, CompoundTag compound) {
    super.load(entity, compound);
    compound.readShort("Air", entity::setRemainingAir);
    compound.readString("CustomName", entity::setCustomName);
    compound.readBoolean("CustomNameVisible", entity::setCustomNameVisible);
    if (!compound.readFloat("HealF", entity::setHealth)) {
        compound.readShort("Health", entity::setHealth);
    }
    compound.readShort("AttackTime", entity::setNoDamageTicks);
    compound.readBoolean("FallFlying", entity::setFallFlying);
    compound.iterateCompoundList("ActiveEffects", effect -> {
        // should really always have every field, but be forgiving if possible
        if (!effect.isByte("Id") || !effect.isInt("Duration")) {
            return;
        }
        PotionEffectType type = PotionEffectType.getById(effect.getByte("Id"));
        int duration = effect.getInt("Duration");
        if (type == null || duration < 0) {
            return;
        }
        final int amplifier = compound.tryGetInt("Amplifier").orElse(0);
        boolean ambient = compound.getBoolean("Ambient", false);
        // bool "ShowParticles"
        entity.addPotionEffect(new PotionEffect(type, duration, amplifier, ambient), true);
    });
    EntityEquipment equip = entity.getEquipment();
    if (equip != null) {
        loadEquipment(entity, equip, compound);
    }
    compound.readBoolean("CanPickUpLoot", entity::setCanPickupItems);
    AttributeManager am = entity.getAttributeManager();
    compound.iterateCompoundList("Attributes", tag -> {
        if (!tag.isString("Name") || !tag.isDouble("Base")) {
            return;
        }
        List<AttributeModifier> modifiers = new ArrayList<>();
        tag.iterateCompoundList("Modifiers", modifierTag -> {
            if (modifierTag.isDouble("Amount") && modifierTag.isString("Name") && modifierTag.isInt("Operation") && modifierTag.isLong("UUIDLeast") && modifierTag.isLong("UUIDMost")) {
                modifiers.add(new AttributeModifier(new UUID(modifierTag.getLong("UUIDLeast"), modifierTag.getLong("UUIDMost")), modifierTag.getString("Name"), modifierTag.getDouble("Amount"), AttributeModifier.Operation.values()[modifierTag.getInt("Operation")]));
            }
        });
        AttributeManager.Key key = AttributeManager.Key.fromName(tag.getString("Name"));
        am.setProperty(key, tag.getDouble("Base"), modifiers);
    });
    Optional<CompoundTag> maybeLeash = compound.tryGetCompound("Leash");
    if (maybeLeash.isPresent()) {
        CompoundTag leash = maybeLeash.get();
        if (!leash.readUniqueId("UUIDMost", "UUIDLeast", entity::setLeashHolderUniqueId) && leash.isInt("X") && leash.isInt("Y") && leash.isInt("Z")) {
            int x = leash.getInt("X");
            int y = leash.getInt("Y");
            int z = leash.getInt("Z");
            LeashHitch leashHitch = GlowLeashHitch.getLeashHitchAt(new Location(entity.getWorld(), x, y, z).getBlock());
            entity.setLeashHolder(leashHitch);
        }
    } else {
        compound.readBoolean("Leashed", leashSet -> {
            if (leashSet) {
                // We know that there was something leashed, but not what entity it was
                // This can happen, when for example Minecart got leashed
                // We still have to make sure that we drop a Leash Item
                entity.setLeashHolderUniqueId(UUID.randomUUID());
            }
        });
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) AttributeModifier(org.bukkit.attribute.AttributeModifier) AttributeManager(net.glowstone.entity.AttributeManager) EntityEquipment(org.bukkit.inventory.EntityEquipment) LeashHitch(org.bukkit.entity.LeashHitch) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) UUID(java.util.UUID) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 44 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project TokenManager by RealizedMC.

the class ItemUtil method applyMeta.

private static void applyMeta(final ItemStack item, final String key, final String value) {
    final ItemMeta meta = item.getItemMeta();
    if (key.equalsIgnoreCase("name")) {
        meta.setDisplayName(StringUtil.color(value.replace("_", " ")));
        item.setItemMeta(meta);
        return;
    }
    if (key.equalsIgnoreCase("lore")) {
        meta.setLore(StringUtil.color(Lists.newArrayList(value.split("\\|")), s -> s.replace("_", " ")));
        item.setItemMeta(meta);
        return;
    }
    if (key.equalsIgnoreCase("unbreakable") && value.equalsIgnoreCase("true")) {
        if (isPre1_12()) {
            meta.spigot().setUnbreakable(true);
        } else {
            meta.setUnbreakable(true);
        }
        item.setItemMeta(meta);
        return;
    }
    final Enchantment enchantment = ENCHANTMENTS.get(key);
    if (enchantment != null) {
        item.addUnsafeEnchantment(enchantment, Integer.parseInt(value));
        return;
    }
    if (item.getType().name().contains("POTION")) {
        final PotionEffectType effectType = EFFECTS.get(key);
        if (effectType != null) {
            String[] values = value.split(":");
            PotionMeta potionMeta = (PotionMeta) meta;
            potionMeta.addCustomEffect(new PotionEffect(effectType, Integer.parseInt(values[1]), Integer.parseInt(values[0])), true);
            item.setItemMeta(potionMeta);
            return;
        }
    }
    if (item.getType() == Material.SKULL_ITEM && item.getDurability() == 3 && key.equalsIgnoreCase("player") || key.equalsIgnoreCase("owner")) {
        final SkullMeta skullMeta = (SkullMeta) meta;
        skullMeta.setOwner(value);
        item.setItemMeta(skullMeta);
    }
}
Also used : NumberUtil(me.realized.tokenmanager.util.NumberUtil) Arrays(java.util.Arrays) Potions(me.realized.tokenmanager.util.compat.Potions) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) PotionType(org.bukkit.potion.PotionType) HashMap(java.util.HashMap) StringUtil(me.realized.tokenmanager.util.StringUtil) EntityType(org.bukkit.entity.EntityType) SpawnEggs(me.realized.tokenmanager.util.compat.SpawnEggs) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) PotionEffect(org.bukkit.potion.PotionEffect) Consumer(java.util.function.Consumer) OptionalLong(java.util.OptionalLong) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) EnumUtil(me.realized.tokenmanager.util.EnumUtil) PotionMeta(org.bukkit.inventory.meta.PotionMeta) Material(org.bukkit.Material) PotionEffectType(org.bukkit.potion.PotionEffectType) Bukkit(org.bukkit.Bukkit) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) PotionMeta(org.bukkit.inventory.meta.PotionMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 45 with PotionEffectType

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

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)

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