Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply potion effects without adding onto current duration #2621

Merged
merged 3 commits into from
Feb 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/main/java/ch/njol/skript/effects/EffPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@
"remove haste from the victim",
"on join:",
" apply potion of strength of tier {strength.%player%} to the player for 999 days"})
@Since("2.0, 2.2-dev27 (ambient and particle-less potion effects)")
@Since("2.0, 2.2-dev27 (ambient and particle-less potion effects), INSERT VERSION (replacing existing effect)")
public class EffPotion extends Effect {
static {
Skript.registerEffect(EffPotion.class,
"apply [potion of] %potioneffecttypes% [potion] [[[of] tier] %-number%] to %livingentities% [for %-timespan%]",
"apply ambient [potion of] %potioneffecttypes% [potion] [[[of] tier] %-number%] to %livingentities% [for %-timespan%]",
"apply [potion of] %potioneffecttypes% [potion] [[[of] tier] %-number%] without [any] particles to %livingentities% [for %-timespan%]"
"apply [potion of] %potioneffecttypes% [potion] [[[of] tier] %-number%] to %livingentities% [for %-timespan%] [(1¦replacing [the] existing effect)]",
"apply ambient [potion of] %potioneffecttypes% [potion] [[[of] tier] %-number%] to %livingentities% [for %-timespan%] [(1¦replacing [the] existing effect)]",
"apply [potion of] %potioneffecttypes% [potion] [[[of] tier] %-number%] without [any] particles to %livingentities% [for %-timespan%] [(1¦replacing [the] existing effect)]"
//, "apply %itemtypes% to %livingentities%"
/*,"remove %potioneffecttypes% from %livingentities%"*/);
}

private final static int DEFAULT_DURATION = 15 * 20; // 15 seconds, same as EffPoison
private int mark;
APickledWalrus marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings("null")
private Expression<PotionEffectType> potions;
Expand All @@ -74,6 +75,7 @@ public class EffPotion extends Effect {
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
apply = matchedPattern < 3;
this.mark = parseResult.mark;
if (apply) {
potions = (Expression<PotionEffectType>) exprs[0];
tier = (Expression<Number>) exprs[1];
Expand Down Expand Up @@ -132,11 +134,13 @@ protected void execute(final Event e) {
for (final LivingEntity en : entities.getArray(e)) {
for (final PotionEffectType t : ts) {
int duration = d;
if (en.hasPotionEffect(t)) {
for (final PotionEffect eff : en.getActivePotionEffects()) {
if (eff.getType() == t) {
duration += eff.getDuration();
break;
if (mark != 1) {
if (en.hasPotionEffect(t)) {
for (final PotionEffect eff : en.getActivePotionEffects()) {
if (eff.getType() == t) {
duration += eff.getDuration();
break;
}
}
}
}
Expand Down