org.bukkit.potion.PotionEffect Java Examples

The following examples show how to use org.bukkit.potion.PotionEffect. 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: Withered.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
public PotionEffect getPotionEffect(@Nullable Event event, @Nullable Entity entity, @NotNull Player player, @NotNull ItemStack tool) {
	int level = modManager.getModLevel(tool, this);
	int duration = (int) (this.duration * Math.pow(this.durationMultiplier, (level - 1)));
	int amplifier = this.effectAmplifier * (level - 1);
	if (entity == null) {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")");
	} else {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")",
				"Entity(" + entity.getType().toString() + ")");
	}

	return new PotionEffect(PotionEffectType.WITHER, duration, amplifier, false, false);
}
 
Example #2
Source File: EffPoison.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity le : entites.getArray(e)) {
		if (!cure) {
			Timespan dur;
			int d = (int) (duration != null && (dur = duration.getSingle(e)) != null ? 
					(dur.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : dur.getTicks_i()) : DEFAULT_DURATION);
			if (le.hasPotionEffect(PotionEffectType.POISON)) {
				for (final PotionEffect pe : le.getActivePotionEffects()) {
					if (pe.getType() != PotionEffectType.POISON)
						continue;
					d += pe.getDuration();
				}
			}
			le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, d, 0), true);
		} else {
			le.removePotionEffect(PotionEffectType.POISON);
		}
	}
}
 
Example #3
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);

    tag.setString(DEFAULT_POTION.NBT, (this.type.getType() == PotionType.UNCRAFTABLE && emptyType != null) ? emptyType : CraftPotionUtil.fromBukkit(type));

    if (hasColor()) {
        tag.setInteger(POTION_COLOR.NBT, color.asRGB());
    }

    if (customEffects != null) {
        NBTTagList effectList = new NBTTagList();
        tag.setTag(POTION_EFFECTS.NBT, effectList);

        for (PotionEffect effect : customEffects) {
            NBTTagCompound effectData = new NBTTagCompound();
            effectData.setByte(ID.NBT, (byte) effect.getType().getId());
            effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
            effectData.setInteger(DURATION.NBT, effect.getDuration());
            effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
            effectData.setBoolean(SHOW_PARTICLES.NBT, effect.hasParticles());
            effectList.appendTag(effectData);
        }
    }
}
 
Example #4
Source File: TeleportPlayersThread.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
	
	for(UhcPlayer uhcPlayer : team.getMembers()){
		Player player;
		try {
			player = uhcPlayer.getPlayer();
		}catch (UhcPlayerNotOnlineException ex){
			continue;
		}

		Bukkit.getLogger().info("[UhcCore] Teleporting "+player.getName());

		for(PotionEffect effect : GameManager.getGameManager().getConfiguration().getPotionEffectOnStart()){
			player.addPotionEffect(effect);
		}

		uhcPlayer.freezePlayer(team.getStartingLocation());
		player.teleport(team.getStartingLocation());
		player.removePotionEffect(PotionEffectType.BLINDNESS);
		player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
		player.setFireTicks(0);
		uhcPlayer.setHasBeenTeleportedToLocation(true);
	}
}
 
Example #5
Source File: FriendlyFire.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
    boolean proceed = false;
    for (PotionEffect effect : event.getPotion().getEffects()) {
        if (effect.getType().equals(PotionEffectType.POISON) || effect.getType().equals(PotionEffectType.BLINDNESS) ||
                effect.getType().equals(PotionEffectType.CONFUSION) || effect.getType().equals(PotionEffectType.HARM) ||
                effect.getType().equals(PotionEffectType.HUNGER) || effect.getType().equals(PotionEffectType.SLOW) ||
                effect.getType().equals(PotionEffectType.SLOW_DIGGING) || effect.getType().equals(PotionEffectType.WITHER) ||
                effect.getType().equals(PotionEffectType.WEAKNESS)) {
            proceed = true;
        }
    }
    if (proceed && event.getPotion().getShooter() instanceof Player && Teams.getTeamByPlayer((Player) event.getPotion().getShooter()) != null) {
        Optional<TeamModule> team = Teams.getTeamByPlayer((Player) event.getPotion().getShooter());
        for (LivingEntity affected : event.getAffectedEntities()) {
            if (affected instanceof Player && Teams.getTeamByPlayer((Player) affected) != null && Teams.getTeamByPlayer((Player) affected).equals(team) && !affected.equals(event.getPotion().getShooter())) {
                event.setIntensity(affected, 0);
            }
        }
    }
}
 
Example #6
Source File: ArmorTask.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void handleSlimefunArmor(Player p, ItemStack[] armor, HashedArmorpiece[] cachedArmor) {
    for (int slot = 0; slot < 4; slot++) {
        ItemStack item = armor[slot];
        HashedArmorpiece armorpiece = cachedArmor[slot];

        if (armorpiece.hasDiverged(item)) {
            SlimefunItem sfItem = SlimefunItem.getByItem(item);
            if (!(sfItem instanceof SlimefunArmorPiece) || !Slimefun.hasUnlocked(p, sfItem, true)) {
                sfItem = null;
            }

            armorpiece.update(item, sfItem);
        }

        if (item != null && armorpiece.getItem().isPresent()) {
            Slimefun.runSync(() -> {
                for (PotionEffect effect : armorpiece.getItem().get().getPotionEffects()) {
                    p.removePotionEffect(effect.getType());
                    p.addPotionEffect(effect);
                }
            });
        }
    }
}
 
Example #7
Source File: XMLUtils.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public static PotionEffect parseCompactPotionEffect(Node node, String text)
    throws InvalidXMLException {
  String[] parts = text.split(":");

  if (parts.length == 0) throw new InvalidXMLException("Missing potion effect type", node);
  PotionEffectType type = parsePotionEffectType(node, parts[0]);
  Duration duration = TimeUtils.INFINITE_DURATION;
  int amplifier = 0;
  boolean ambient = false;

  if (parts.length >= 2) {
    duration = parseTickDuration(node, parts[1]);
    if (parts.length >= 3) {
      amplifier = parseNumber(node, parts[2], Integer.class);
      if (parts.length >= 4) {
        ambient = parseBoolean(node, parts[3]);
      }
    }
  }

  return createPotionEffect(type, duration, amplifier, ambient);
}
 
Example #8
Source File: Bandage.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();

        // Player is neither burning nor injured
        if (p.getFireTicks() <= 0 && p.getHealth() >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
            return;
        }

        if (p.getGameMode() != GameMode.CREATIVE) {
            ItemUtils.consumeItem(e.getItem(), false);
        }

        p.getWorld().playEffect(p.getLocation(), Effect.STEP_SOUND, Material.WHITE_WOOL);
        p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1));
        p.setFireTicks(0);

        e.cancel();
    };
}
 
Example #9
Source File: PotionEffectSerializer.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize a Collection of PotionEffects into a JsonArray of JsonObjects. Each
 * JsonObject contains the type, amplifier, duration and color of a potion effect.
 * The color is saved in the RGB format.
 *
 * @param effects The PotionEffects to serialize
 * @return A JsonArray of JsonObjects of serialized PotionEffects.
 */
public static JsonArray serialize(Collection<PotionEffect> effects) {
    JsonArray all = new JsonArray();

    for (PotionEffect effect : effects) {
        JsonObject pot = new JsonObject();
        pot.addProperty("type", effect.getType().getName());
        pot.addProperty("amp", effect.getAmplifier());
        pot.addProperty("duration", effect.getDuration());
        pot.addProperty("ambient", effect.isAmbient());
        pot.addProperty("particles", effect.hasParticles());
        // TODO: Figure out what version of Spigot this method was added.
        /*if (effect.getColor() != null) {
            pot.addProperty("color", effect.getColor().asRGB());
        }*/

        all.add(pot);
    }

    return all;
}
 
Example #10
Source File: CraftMetaPotion.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean removeCustomEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");

    if (!hasCustomEffects()) {
        return false;
    }

    boolean changed = false;
    Iterator<PotionEffect> iterator = customEffects.iterator();
    while (iterator.hasNext()) {
        PotionEffect effect = iterator.next();
        if (effect.getType() == type) {
            iterator.remove();
            changed = true;
        }
    }
    return changed;
}
 
Example #11
Source File: CraftMetaPotion.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
    Validate.notNull(effect, "Potion effect must not be null");

    int index = indexOfEffect(effect.getType());
    if (index != -1) {
        if (overwrite) {
            PotionEffect old = customEffects.get(index);
            if (old.getAmplifier() == effect.getAmplifier() && old.getDuration() == effect.getDuration() && old.isAmbient() == effect.isAmbient()) {
                return false;
            }
            customEffects.set(index, effect);
            return true;
        } else {
            return false;
        }
    } else {
        if (customEffects == null) {
            customEffects = new ArrayList<PotionEffect>();
        }
        customEffects.add(effect);
        return true;
    }
}
 
Example #12
Source File: Poisonous.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
public PotionEffect getPotionEffect(@Nullable Event event, @Nullable Entity entity, @NotNull Player player, @NotNull ItemStack tool) {
	int level = modManager.getModLevel(tool, this);
	int duration = (int) (this.duration * Math.pow(this.durationMultiplier, (level - 1)));
	int amplifier = this.effectAmplifier * (level - 1);
	if (entity == null) {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")");
	} else {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")",
				"Entity(" + entity.getType().toString() + ")");
	}

	return new PotionEffect(PotionEffectType.POISON, duration, amplifier, false, false);
}
 
Example #13
Source File: KitParser.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<PotionEffect> parsePotions(Element el) throws InvalidXMLException {
  List<PotionEffect> effects = new ArrayList<>();

  Node attr = Node.fromAttr(el, "potion", "potions", "effect", "effects");
  if (attr != null) {
    for (String piece : attr.getValue().split(";")) {
      effects.add(XMLUtils.parseCompactPotionEffect(attr, piece));
    }
  }

  for (Node elPotion : Node.fromChildren(el, "potion", "effect")) {
    effects.add(XMLUtils.parsePotionEffect(elPotion.getElement()));
  }

  return effects;
}
 
Example #14
Source File: Webbed.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
public PotionEffect getPotionEffect(@Nullable Event event, @Nullable Entity entity, @NotNull Player player, @NotNull ItemStack tool) {
	int level = modManager.getModLevel(tool, this);
	int duration = (int) (this.duration * Math.pow(this.durationMultiplier, (level - 1)));
	int amplifier = this.effectAmplifier * (level - 1);
	if (entity == null) {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")");
	} else {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")",
				"Entity(" + entity.getType().toString() + ")");
	}

	return new PotionEffect(PotionEffectType.SLOW, duration, amplifier, false, false);
}
 
Example #15
Source File: Shulking.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
public PotionEffect getPotionEffect(@Nullable Event event, @Nullable Entity entity, @NotNull Player player, @NotNull ItemStack tool) {
	int level = modManager.getModLevel(tool, this);
	int amplifier = this.effectAmplifier * (level - 1);
	if (entity == null) {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")");
	} else {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")",
				"Entity(" + entity.getType().toString() + ")");
	}

	return new PotionEffect(PotionEffectType.LEVITATION, this.duration, amplifier, false, false);
}
 
Example #16
Source File: Players.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static void resetPlayer(Player player, boolean heal) {
    if (heal) player.setHealth(player.getMaxHealth());
    player.setFoodLevel(20);
    player.setSaturation(20);
    player.getInventory().clear();
    player.getInventory().setArmorContents(new ItemStack[]{new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR)});
    for (PotionEffect effect : player.getActivePotionEffects()) {
        try {
            player.removePotionEffect(effect.getType());
        } catch (NullPointerException ignored) {
        }
    }
    player.setTotalExperience(0);
    player.setExp(0);
    player.setLevel(0);
    player.setPotionParticles(false);
    player.setWalkSpeed(0.2F);
    player.setFlySpeed(0.1F);
    player.setKnockbackReduction(0);
    player.setArrowsStuck(0);

    player.hideTitle();

    player.setFastNaturalRegeneration(false);

    for (Attribute attribute : Attribute.values()) {
        if (player.getAttribute(attribute) == null) continue;
        for (AttributeModifier modifier : player.getAttribute(attribute).getModifiers()) {
            player.getAttribute(attribute).removeModifier(modifier);
        }
    }
    player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(new AttributeModifier(UUID.randomUUID(), "generic.attackSpeed", 4.001D, AttributeModifier.Operation.ADD_SCALAR));
    player.getAttribute(Attribute.ARROW_ACCURACY).addModifier(new AttributeModifier(UUID.randomUUID(), "sportbukkit.arrowAccuracy", -1D, AttributeModifier.Operation.ADD_NUMBER));
    player.getAttribute(Attribute.ARROW_VELOCITY_TRANSFER).addModifier(new AttributeModifier(UUID.randomUUID(), "sportbukkit.arrowVelocityTransfer", -1D, AttributeModifier.Operation.ADD_NUMBER));
}
 
Example #17
Source File: CraftTippedArrow.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<PotionEffect> getCustomEffects() {
    ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
    for (net.minecraft.potion.PotionEffect effect : getHandle().customPotionEffects) {
        builder.add(CraftPotionUtil.toBukkit(effect));
    }
    return builder.build();
}
 
Example #18
Source File: Cloaking.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
    EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
    Player player = (Player) event.getEntity();
    player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, duration * level, 0));
    player.sendMessage(ChatColor.DARK_GRAY + "You have become invisible!");
    generateCooldown(player, cooldown);
}
 
Example #19
Source File: CraftPotionUtil.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
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 #20
Source File: PotionEffectApplier.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
private PotionEffect continuousPotionEffect(PotionEffectType potionEffectType, int potionEffectMagnitude) {

        if (potionEffectType.equals(PotionEffectType.NIGHT_VISION)) {
            return new PotionEffect(potionEffectType, 15 * 20, potionEffectMagnitude);
        }
        if (potionEffectType.equals(PotionEffectType.SATURATION)) {
            return new PotionEffect(potionEffectType, 1, potionEffectMagnitude);
        }
        return new PotionEffect(potionEffectType, 5 * 20, potionEffectMagnitude);

    }
 
Example #21
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<PotionEffect> getCustomEffects() {
    ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
    for (net.minecraft.potion.PotionEffect effect : getHandle().effects) {
        builder.add(CraftPotionUtil.toBukkit(effect));
    }
    return builder.build();
}
 
Example #22
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
private boolean isPotionDisabled(PotionEffect type) {
	if (type.getType().equals(PotionEffectType.SPEED) ||
		type.getType().equals(PotionEffectType.FIRE_RESISTANCE) ||
		type.getType().equals(PotionEffectType.HEAL)) {
		return false;
	}
	
	return true;
}
 
Example #23
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public boolean setMainEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");
    int index = indexOfEffect(type);
    if (index == -1 || index == 0) {
        return false;
    }

    PotionEffect old = customEffects.get(0);
    customEffects.set(0, customEffects.get(index));
    customEffects.set(index, old);
    return true;
}
 
Example #24
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean hasCustomEffect(PotionEffectType type) {
    for (net.minecraft.potion.PotionEffect effect : getHandle().effects) {
        if (CraftPotionUtil.equals(effect.getPotion(), type)) {
            return true;
        }
    }
    return false;
}
 
Example #25
Source File: Assassin.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected boolean performSpecialAction(Player player, AnniPlayer p)
{
	p.setData("Arm",player.getInventory().getArmorContents().clone());
	p.setData("Cur", true);
	player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,160,0));
	player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,160,0));
	player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING,160,1));
	player.getInventory().setArmorContents(null);
	player.updateInventory();
	player.setVelocity(player.getLocation().getDirection().setY(1).multiply(1));
	new EndLeap(player,p).runTaskLater(AnnihilationMain.getInstance(), 160);
	return true;
}
 
Example #26
Source File: Utils.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a player's stats to defaults, and optionally clear their inventory.
 *
 * @param plugin {@link PerWorldInventory} for econ.
 * @param player The player to zero.
 * @param clearInventory Clear the player's inventory.
 */
public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) {
    if (clearInventory) {
        player.getInventory().clear();
        player.getEnderChest().clear();
    }

    player.setExp(0f);
    player.setFoodLevel(20);

    if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) {
        player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    } else {
        player.setHealth(player.getMaxHealth());
    }

    player.setLevel(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }
    player.setSaturation(5f);
    player.setFallDistance(0f);
    player.setFireTicks(0);

    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        econ.withdrawPlayer(player, econ.getBalance(player));
    }
}
 
Example #27
Source File: AcidEffect.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if player is safe from rain
 * @param player
 * @return true if they are safe
 */
private boolean isSafeFromRain(Player player) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: safe from acid rain");
    if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: wrong world");
        return true;
    }
    // Check if player has a helmet on and helmet protection is true
    if (Settings.helmetProtection && (player.getInventory().getHelmet() != null
            && player.getInventory().getHelmet().getType().name().contains("HELMET"))) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: wearing helmet.");
        return true;
    }
    // Check potions
    Collection<PotionEffect> activePotions = player.getActivePotionEffects();
    for (PotionEffect s : activePotions) {
        if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
            // Safe!
            if (DEBUG)
                plugin.getLogger().info("DEBUG: potion");
            return true;
        }
    }
    // Check if all air above player
    for (int y = player.getLocation().getBlockY() + 2; y < player.getLocation().getWorld().getMaxHeight(); y++) {
        if (!player.getLocation().getWorld().getBlockAt(player.getLocation().getBlockX(), y, player.getLocation().getBlockZ()).getType().equals(Material.AIR)) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: something other than air above player");
            return true;
        }
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: acid rain damage");
    return false;
}
 
Example #28
Source File: PotionEffectSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove any PotionEffects the entity currently has, then apply the new effects.
 *
 * @param effects The PotionEffects to apply.
 * @param entity The entity to apply the effects to.
 */
public static void setPotionEffects(JsonArray effects, LivingEntity entity) {
    if (entity.getActivePotionEffects() != null && !entity.getActivePotionEffects().isEmpty()) {
        for (PotionEffect effect : entity.getActivePotionEffects()) {
            entity.removePotionEffect(effect.getType());
        }
    }

    addPotionEffects(effects, entity);
}
 
Example #29
Source File: Parser.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static PotionEffect getPotion(Element potion) {
    PotionEffectType type = PotionEffectType.getByName(Strings.getTechnicalName(potion.getText()));
    if (type == null) type = new CraftPotionEffectType(MobEffectList.getByName(potion.getText().toLowerCase().replace(" ","_")));
    int duration = (int) (Strings.timeStringToExactSeconds(potion.getAttributeValue("duration")) * 20);
    int amplifier = 0;
    boolean ambient = false;
    if (potion.getAttributeValue("amplifier") != null)
        amplifier = Numbers.parseInt(potion.getAttributeValue("amplifier")) - 1;
    if (potion.getAttributeValue("ambient") != null)
        ambient = Boolean.parseBoolean(potion.getAttributeValue("ambient").toUpperCase());
    return new PotionEffect(type, duration, amplifier, ambient);
}
 
Example #30
Source File: CustomPotion.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) {
	super(Material.POTION, name, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setBasePotionData(new PotionData(type));
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}