Search in sources :

Example 11 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", Material.REDSTONE_TORCH_ON, 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.WATCH, 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 12 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"
// - bool "Leashed"
// - compound "Leash"
// on ActiveEffects, bool "ShowParticles"
@Override
public void load(T entity, CompoundTag compound) {
    super.load(entity, compound);
    if (compound.isShort("Air")) {
        entity.setRemainingAir(compound.getShort("Air"));
    }
    if (compound.isString("CustomName")) {
        entity.setCustomName(compound.getString("CustomName"));
    }
    if (compound.isByte("CustomNameVisible")) {
        entity.setCustomNameVisible(compound.getBool("CustomNameVisible"));
    }
    if (compound.isFloat("HealF")) {
        entity.setHealth(compound.getFloat("HealF"));
    } else if (compound.isShort("Health")) {
        entity.setHealth(compound.getShort("Health"));
    }
    if (compound.isShort("AttackTime")) {
        entity.setNoDamageTicks(compound.getShort("AttackTime"));
    }
    if (compound.isByte("FallFlying")) {
        entity.setFallFlying(compound.getBool("FallFlying"));
    }
    if (compound.isList("ActiveEffects", TagType.COMPOUND)) {
        for (CompoundTag effect : compound.getCompoundList("ActiveEffects")) {
            // should really always have every field, but be forgiving if possible
            if (!effect.isByte("Id") || !effect.isInt("Duration")) {
                continue;
            }
            PotionEffectType type = PotionEffectType.getById(effect.getByte("Id"));
            int duration = effect.getInt("Duration");
            if (type == null || duration < 0) {
                continue;
            }
            int amplifier = 0;
            boolean ambient = false;
            if (compound.isByte("Amplifier")) {
                amplifier = compound.getByte("Amplifier");
            }
            if (compound.isByte("Ambient")) {
                ambient = compound.getBool("Ambient");
            }
            // bool "ShowParticles"
            entity.addPotionEffect(new PotionEffect(type, duration, amplifier, ambient), true);
        }
    }
    EntityEquipment equip = entity.getEquipment();
    if (equip != null) {
        if (compound.isList("Equipment", TagType.COMPOUND)) {
            List<CompoundTag> list = compound.getCompoundList("Equipment");
            if (list.size() == 5) {
                equip.setItemInHand(NbtSerialization.readItem(list.get(0)));
                equip.setBoots(NbtSerialization.readItem(list.get(1)));
                equip.setLeggings(NbtSerialization.readItem(list.get(2)));
                equip.setChestplate(NbtSerialization.readItem(list.get(3)));
                equip.setHelmet(NbtSerialization.readItem(list.get(4)));
            }
        }
        if (compound.isList("DropChances", TagType.FLOAT)) {
            List<Float> list = compound.getList("DropChances", TagType.FLOAT);
            if (list.size() == 5) {
                equip.setItemInHandDropChance(list.get(0));
                equip.setBootsDropChance(list.get(1));
                equip.setLeggingsDropChance(list.get(2));
                equip.setChestplateDropChance(list.get(3));
                equip.setHelmetDropChance(list.get(4));
            }
        }
    }
    if (compound.isByte("CanPickUpLoot")) {
        entity.setCanPickupItems(compound.getBool("CanPickUpLoot"));
    }
    if (compound.isList("Attributes", TagType.COMPOUND)) {
        List<CompoundTag> attributes = compound.getCompoundList("Attributes");
        AttributeManager am = entity.getAttributeManager();
        for (CompoundTag tag : attributes) {
            if (tag.isString("Name") && tag.isDouble("Base")) {
                List<Modifier> modifiers = null;
                if (tag.isList("Modifiers", TagType.COMPOUND)) {
                    modifiers = new ArrayList<>();
                    List<CompoundTag> modifierTags = tag.getCompoundList("Modifiers");
                    for (CompoundTag modifierTag : modifierTags) {
                        if (modifierTag.isDouble("Amount") && modifierTag.isString("Name") && modifierTag.isInt("Operation") && modifierTag.isLong("UUIDLeast") && modifierTag.isLong("UUIDMost")) {
                            modifiers.add(new Modifier(modifierTag.getString("Name"), new UUID(modifierTag.getLong("UUIDLeast"), modifierTag.getLong("UUIDMost")), modifierTag.getDouble("Amount"), (byte) modifierTag.getInt("Operation")));
                        }
                    }
                }
                am.setProperty(tag.getString("Name"), tag.getDouble("Base"), modifiers);
            }
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) AttributeManager(net.glowstone.entity.AttributeManager) EntityEquipment(org.bukkit.inventory.EntityEquipment) Modifier(net.glowstone.entity.AttributeManager.Modifier) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 13 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project BKCommonLib by bergerhealer.

the class WrapperConversion method toPotionEffectType.

@SuppressWarnings("deprecation")
@ConverterMethod(input = "net.minecraft.server.MobEffectList")
public static PotionEffectType toPotionEffectType(Object nmsMobEffectListHandle) {
    int id = NMSMobEffect.List.getId.invoke(null, nmsMobEffectListHandle);
    PotionEffectType type = PotionEffectType.getById(id);
    if (type != null) {
        return type;
    } else {
        return null;
    }
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType) ConverterMethod(com.bergerkiller.mountiplex.conversion.annotations.ConverterMethod)

Example 14 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())));
    }
    if (stack.getType() == Material.POTION) {
        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) TreeSet(java.util.TreeSet) PotionEffectType(org.bukkit.potion.PotionEffectType) PotionMeta(org.bukkit.inventory.meta.PotionMeta) MetaItemStack(com.earth2me.essentials.MetaItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) MetaItemStack(com.earth2me.essentials.MetaItemStack)

Aggregations

PotionEffectType (org.bukkit.potion.PotionEffectType)14 PotionEffect (org.bukkit.potion.PotionEffect)12 ArrayList (java.util.ArrayList)5 List (java.util.List)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 Callback (au.com.mineauz.minigames.menu.Callback)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItemInteger (au.com.mineauz.minigames.menu.MenuItemInteger)1 MenuItemList (au.com.mineauz.minigames.menu.MenuItemList)1 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)1 MenuItemTime (au.com.mineauz.minigames.menu.MenuItemTime)1 ConverterMethod (com.bergerkiller.mountiplex.conversion.annotations.ConverterMethod)1 MetaItemStack (com.earth2me.essentials.MetaItemStack)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Pattern (java.util.regex.Pattern)1 FlagManager (net.aufdemrand.denizen.flags.FlagManager)1 EntityHelper (net.aufdemrand.denizen.nms.interfaces.EntityHelper)1