Skip to content

Commit

Permalink
Support infinite potion effect durations
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jul 31, 2023
1 parent dd33d40 commit d9e80c1
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.laytonsmith.abstraction.MCPotionData;
import com.laytonsmith.abstraction.MCPotionMeta;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
Expand Down Expand Up @@ -36,6 +38,13 @@ public void setBasePotionData(MCPotionData bpd) {

@Override
public boolean addCustomEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t) {
if(ticks < 0) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_X)) {
ticks = -1;
} else {
ticks = Integer.MAX_VALUE;
}
}
PotionEffect pe = new PotionEffect((PotionEffectType) type.getConcrete(), ticks, strength, ambient, particles, icon);
return pm.addCustomEffect(pe, force);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.laytonsmith.abstraction.MCLivingEntity.MCEffect;
import com.laytonsmith.abstraction.MCSuspiciousStewMeta;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import org.bukkit.inventory.meta.SuspiciousStewMeta;
import org.bukkit.potion.PotionEffect;
Expand All @@ -23,6 +25,13 @@ public BukkitMCSuspiciousStewMeta(SuspiciousStewMeta ssm) {

@Override
public boolean addCustomEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t) {
if(ticks < 0) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_X)) {
ticks = -1;
} else {
ticks = Integer.MAX_VALUE;
}
}
PotionEffect pe = new PotionEffect((PotionEffectType) type.getConcrete(), ticks, strength, ambient, particles, icon);
return this.ssm.addCustomEffect(pe, force);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlockProjectileSource;
import com.laytonsmith.abstraction.entities.MCAreaEffectCloud;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCParticle;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.Static;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;
Expand Down Expand Up @@ -110,8 +112,16 @@ public int getWaitTime() {

@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect) {
int ticks = effect.getTicksRemaining();
if(ticks < 0) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_X)) {
ticks = -1;
} else {
ticks = Integer.MAX_VALUE;
}
}
PotionEffectType type = (PotionEffectType) effect.getPotionEffectType().getConcrete();
PotionEffect pe = new PotionEffect(type, effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(),
PotionEffect pe = new PotionEffect(type, ticks, effect.getStrength(), effect.isAmbient(),
effect.hasParticles(), effect.showIcon());
aec.addCustomEffect(pe, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.laytonsmith.abstraction.MCPotionData;
import com.laytonsmith.abstraction.bukkit.BukkitMCPotionData;
import com.laytonsmith.abstraction.entities.MCArrow;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.Static;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.potion.PotionData;
Expand Down Expand Up @@ -70,8 +72,16 @@ public List<MCLivingEntity.MCEffect> getCustomEffects() {

@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect) {
int ticks = effect.getTicksRemaining();
if(ticks < 0) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_X)) {
ticks = -1;
} else {
ticks = Integer.MAX_VALUE;
}
}
PotionEffect pe = new PotionEffect((PotionEffectType) effect.getPotionEffectType().getConcrete(),
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles(),
ticks, effect.getStrength(), effect.isAmbient(), effect.hasParticles(),
effect.showIcon());
arrow.addCustomEffect(pe, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlock;
import com.laytonsmith.abstraction.enums.MCAttribute;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCAttribute;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.exceptions.CRE.CREBadEntityException;
import org.bukkit.Material;
Expand Down Expand Up @@ -222,6 +224,13 @@ public boolean hasAI() {

@Override
public boolean addEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
if(ticks < 0) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_X)) {
ticks = -1;
} else {
ticks = Integer.MAX_VALUE;
}
}
PotionEffect pe = new PotionEffect((PotionEffectType) type.getConcrete(), ticks, strength, ambient, particles, icon);
return le.addPotionEffect(pe);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1763,9 +1763,7 @@ public List<MCLivingEntity.MCEffect> potions(CArray ea, Target t) {
}
if(effect.containsKey("seconds")) {
seconds = ArgumentValidation.getDouble(effect.get("seconds", t), t);
if(seconds < 0.0) {
throw new CRERangeException("Seconds cannot be less than 0", t);
} else if(seconds * 20 > Integer.MAX_VALUE) {
if(seconds * 20 > Integer.MAX_VALUE) {
throw new CRERangeException("Seconds cannot be greater than 107374182", t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ public String docs() {
+ ". It also accepts an integer corresponding to the effect id listed on the Minecraft wiki."
+ " Strength is an integer representing the power level of the effect, starting at 0."
+ " Seconds defaults to 30.0. To remove an effect, set the seconds to 0."
+ " If seconds is less than 0 or greater than 107374182 a RangeException is thrown."
+ " If seconds is greater than 107374182 a RangeException is thrown."
+ " Negative seconds makes the effect infinite. (or max in versions prior to 1.19.4)"
+ " Ambient takes a boolean of whether the particles should be more transparent."
+ " Particles takes a boolean of whether the particles should be visible at all."
+ " The function returns whether or not the effect was modified.";
Expand Down Expand Up @@ -594,9 +595,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime

if(args.length >= 4) {
seconds = ArgumentValidation.getDouble(args[3], t);
if(seconds < 0.0) {
throw new CRERangeException("Seconds cannot be less than 0.0", t);
} else if(seconds * 20 > Integer.MAX_VALUE) {
if(seconds * 20 > Integer.MAX_VALUE) {
throw new CRERangeException("Seconds cannot be greater than 107374182.0", t);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,8 @@ public String docs() {
+ ". It also accepts an integer corresponding to the effect id listed on the Minecraft wiki."
+ " Strength is an integer representing the power level of the effect, starting at 0."
+ " Seconds defaults to 30.0. To remove an effect, set the seconds to 0."
+ " If seconds is less than 0 or greater than 107374182 a RangeException is thrown."
+ " If seconds is greater than 107374182 a RangeException is thrown."
+ " Negative seconds makes the effect infinite. (or max in versions prior to 1.19.4)"
+ " Ambient takes a boolean of whether the particles should be more transparent."
+ " Particles takes a boolean of whether the particles should be visible at all."
+ " The function returns whether or not the effect was modified.";
Expand Down Expand Up @@ -2294,9 +2295,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime

if(args.length >= 4) {
seconds = ArgumentValidation.getDouble(args[3], t);
if(seconds < 0.0) {
throw new CRERangeException("Seconds cannot be less than 0.0", t);
} else if(seconds * 20 > Integer.MAX_VALUE) {
if(seconds * 20 > Integer.MAX_VALUE) {
throw new CRERangeException("Seconds cannot be greater than 107374182.0", t);
}

Expand Down

0 comments on commit d9e80c1

Please sign in to comment.