Java Code Examples for org.bukkit.potion.PotionEffectType#getById()
The following examples show how to use
org.bukkit.potion.PotionEffectType#getById() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftMetaPotion.java From Thermos with GNU General Public License v3.0 | 6 votes |
CraftMetaPotion(net.minecraft.nbt.NBTTagCompound tag) { super(tag); if (tag.hasKey(POTION_EFFECTS.NBT)) { net.minecraft.nbt.NBTTagList list = tag.getTagList(POTION_EFFECTS.NBT, 10); int length = list.tagCount(); if (length > 0) { customEffects = new ArrayList<PotionEffect>(length); for (int i = 0; i < length; i++) { net.minecraft.nbt.NBTTagCompound effect = list.getCompoundTagAt(i); PotionEffectType type = PotionEffectType.getById(effect.getByte(ID.NBT)); int amp = effect.getByte(AMPLIFIER.NBT); int duration = effect.getInteger(DURATION.NBT); boolean ambient = effect.getBoolean(AMBIENT.NBT); customEffects.add(new PotionEffect(type, duration, amp, ambient)); } } } }
Example 2
Source File: CraftPotionBrewer.java From Thermos with GNU General Public License v3.0 | 6 votes |
public Collection<PotionEffect> getEffectsFromDamage(int damage) { if (cache.containsKey(damage)) return cache.get(damage); List<?> mcEffects = net.minecraft.potion.PotionHelper.getPotionEffects(damage, false); List<PotionEffect> effects = new ArrayList<PotionEffect>(); if (mcEffects == null) return effects; for (Object raw : mcEffects) { if (raw == null || !(raw instanceof net.minecraft.potion.PotionEffect)) continue; net.minecraft.potion.PotionEffect mcEffect = (net.minecraft.potion.PotionEffect) raw; PotionEffect effect = new PotionEffect(PotionEffectType.getById(mcEffect.getPotionID()), mcEffect.getDuration(), mcEffect.getAmplifier()); // Minecraft PotionBrewer applies duration modifiers automatically. effects.add(effect); } cache.put(damage, effects); return effects; }
Example 3
Source File: CraftPotionUtil.java From Kettle with GNU General Public License v3.0 | 5 votes |
public static PotionEffect toBukkit(net.minecraft.potion.PotionEffect effect) { PotionEffectType type = PotionEffectType.getById(Potion.getIdFromPotion(effect.getPotion())); int amp = effect.getAmplifier(); int duration = effect.getDuration(); boolean ambient = effect.getIsAmbient(); boolean particles = effect.doesShowParticles(); return new PotionEffect(type, duration, amp, ambient, particles); }
Example 4
Source File: Items.java From TabooLib with MIT License | 5 votes |
public static PotionEffectType asPotionEffectType(String potion) { try { PotionEffectType type = PotionEffectType.getByName(potion); return type != null ? type : PotionEffectType.getById(NumberConversions.toInt(potion)); } catch (Throwable e) { return null; } }
Example 5
Source File: PotionEffectSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Get a Collection of PotionEffects from the given potion effect code * * @param serializedEffects The potion effect code to decode from * @return A Collection of PotionEffects from the given potion effect code * * @deprecated Uses deprecated methods that may be removed. Additionally, may not have all the data. */ @Deprecated public static Collection<PotionEffect> deserialize(String serializedEffects) { ArrayList<PotionEffect> effects = new ArrayList<>(); if (serializedEffects.isEmpty()) return effects; String[] effs = serializedEffects.split(";"); for (int i = 0; i < effs.length; i++) { String[] effect = effs[i].split(":"); if (effect.length < 3) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): split must at least have a length of 3"); if (DeprecatedMethodUtil.isNum(effect[0])) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): id is not an integer"); if (DeprecatedMethodUtil.isNum(effect[1])) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): duration is not an integer"); if (DeprecatedMethodUtil.isNum(effect[2])) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): amplifier is not an integer"); int id = Integer.parseInt(effect[0]); int duration = Integer.parseInt(effect[1]); int amplifier = Integer.parseInt(effect[2]); PotionEffectType effectType = PotionEffectType.getById(id); if (effectType == null) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): no PotionEffectType with id of " + id); PotionEffect e = new PotionEffect(effectType, duration, amplifier); effects.add(e); } return effects; }
Example 6
Source File: CraftLivingEntity.java From Thermos with GNU General Public License v3.0 | 5 votes |
public Collection<PotionEffect> getActivePotionEffects() { List<PotionEffect> effects = new ArrayList<PotionEffect>(); for (Object raw : getHandle().activePotionsMap.values()) { if (!(raw instanceof net.minecraft.potion.PotionEffect)) continue; net.minecraft.potion.PotionEffect handle = (net.minecraft.potion.PotionEffect) raw; if (PotionEffectType.getById(handle.getPotionID()) == null) continue; // Cauldron - ignore null types effects.add(new PotionEffect(PotionEffectType.getById(handle.getPotionID()), handle.getDuration(), handle.getAmplifier(), handle.getIsAmbient())); } return effects; }
Example 7
Source File: PotionEffectSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Get a Collection of PotionEffects from the given potion effect code * * @param serializedEffects The potion effect code to decode from * @return A Collection of PotionEffects from the given potion effect code * * @deprecated Uses deprecated methods that may be removed. Additionally, may not have all the data. */ @Deprecated public static Collection<PotionEffect> deserialize(String serializedEffects) { ArrayList<PotionEffect> effects = new ArrayList<>(); if (serializedEffects.isEmpty()) return effects; String[] effs = serializedEffects.split(";"); for (int i = 0; i < effs.length; i++) { String[] effect = effs[i].split(":"); if (effect.length < 3) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): split must at least have a length of 3"); if (DeprecatedMethodUtil.isNum(effect[0])) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): id is not an integer"); if (DeprecatedMethodUtil.isNum(effect[1])) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): duration is not an integer"); if (DeprecatedMethodUtil.isNum(effect[2])) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): amplifier is not an integer"); int id = Integer.parseInt(effect[0]); int duration = Integer.parseInt(effect[1]); int amplifier = Integer.parseInt(effect[2]); PotionEffectType effectType = PotionEffectType.getById(id); if (effectType == null) throw new IllegalArgumentException(serializedEffects + " - PotionEffect " + i + " (" + effs[i] + "): no PotionEffectType with id of " + id); PotionEffect e = new PotionEffect(effectType, duration, amplifier); effects.add(e); } return effects; }
Example 8
Source File: NMSHacks.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
static PotionEffectType getPotionEffectType(String key) { MobEffectList nms = MobEffectList.b(key); return nms == null ? null : PotionEffectType.getById(nms.id); }
Example 9
Source File: CraftLivingEntity.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public PotionEffect getPotionEffect(PotionEffectType type) { net.minecraft.potion.PotionEffect handle = getHandle().getActivePotionEffect(Potion.getPotionById(type.getId())); return (handle == null) ? null : new PotionEffect(PotionEffectType.getById(Potion.getIdFromPotion(handle.getPotion())), handle.getDuration(), handle.getAmplifier(), handle.getIsAmbient(), handle.doesShowParticles()); }
Example 10
Source File: CraftPotionUtil.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static boolean equals(Potion mobEffect, PotionEffectType type) { PotionEffectType typeV = PotionEffectType.getById(Potion.getIdFromPotion(mobEffect)); return typeV.equals(type); }
Example 11
Source File: WrapperPlayServerRemoveEntityEffect.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
/** * Retrieve the effect. * @return The current effect */ @SuppressWarnings("deprecation") public PotionEffectType getEffect() { return PotionEffectType.getById(getEffectId()); }
Example 12
Source File: WrapperPlayServerEntityEffect.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
/** * Retrieve the effect. * @return The current effect */ @SuppressWarnings("deprecation") public PotionEffectType getEffect() { return PotionEffectType.getById(getEffectId()); }