Permalink
Browse files

Add potion effect type names and modify the potion effect array to re…

…flect this.

This probably won't break any existing scripts that read or write potion effects, but it is possible.
  • Loading branch information...
PseudoKnight committed Aug 22, 2018
1 parent 6e10805 commit 18868348eb180610d30d9254c2b92d2d59bdeea3
@@ -2,26 +2,20 @@
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.core.constructs.Target;
import java.util.HashSet;
import java.util.List;
public interface MCLivingEntity extends MCEntity, MCProjectileSource {
void addEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, boolean icon);
boolean addEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon);
boolean removeEffect(int potionID);
boolean removeEffect(MCPotionEffectType type);
void removeEffects();
/**
* Returns the maximum effect id, inclusive.
*
* @return
*/
int getMaxEffect();
List<MCEffect> getEffects();
void damage(double amount);
@@ -118,42 +112,42 @@
class MCEffect {
private int potionID;
private MCPotionEffectType type;
private int strength;
private int ticksRemaining;
private boolean ambient;
private boolean particles;
private boolean icon;
public MCEffect(int potionID, int strength, int ticks, boolean ambient) {
this.potionID = potionID;
public MCEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient) {
this.type = type;
this.strength = strength;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = true;
this.icon = true;
}
public MCEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles) {
this.potionID = potionID;
public MCEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles) {
this.type = type;
this.strength = strength;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = particles;
this.icon = particles;
}
public MCEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
this.potionID = potionID;
public MCEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
this.type = type;
this.strength = strength;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = particles;
this.icon = icon;
}
public int getPotionID() {
return potionID;
public MCPotionEffectType getPotionEffectType() {
return type;
}
public int getStrength() {
@@ -3,6 +3,7 @@
import com.laytonsmith.abstraction.blocks.MCBlockData;
import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.MCSound;
import com.laytonsmith.abstraction.enums.MCSoundCategory;
import com.laytonsmith.abstraction.enums.MCWeather;
@@ -66,7 +67,7 @@
void kickPlayer(String message);
@Override
boolean removeEffect(int effect);
boolean removeEffect(MCPotionEffectType type);
void resetPlayerTime();
@@ -1,6 +1,7 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.MCLivingEntity.MCEffect;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.core.constructs.Target;
import java.util.List;
@@ -10,15 +11,15 @@
void setBasePotionData(MCPotionData pd);
boolean addCustomEffect(int id, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t);
boolean addCustomEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t);
boolean clearCustomEffects();
List<MCEffect> getCustomEffects();
boolean hasCustomEffect(int id);
boolean hasCustomEffect(MCPotionEffectType type);
boolean hasCustomEffects();
boolean removeCustomEffect(int id);
boolean removeCustomEffect(MCPotionEffectType type);
}
@@ -3,8 +3,9 @@
import com.laytonsmith.abstraction.MCLivingEntity.MCEffect;
import com.laytonsmith.abstraction.MCPotionData;
import com.laytonsmith.abstraction.MCPotionMeta;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
@@ -33,12 +34,8 @@ public void setBasePotionData(MCPotionData bpd) {
}
@Override
public boolean addCustomEffect(int id, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t) {
int maxID = PotionEffectType.values().length;
if(id < 1 || id > maxID) {
throw new CRERangeException("Invalid effect ID, must be from 1-" + maxID, t);
}
PotionEffect pe = new PotionEffect(PotionEffectType.getById(id), ticks, strength, ambient, particles, icon);
public boolean addCustomEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t) {
PotionEffect pe = new PotionEffect((PotionEffectType) type.getConcrete(), ticks, strength, ambient, particles, icon);
return pm.addCustomEffect(pe, force);
}
@@ -51,15 +48,15 @@ public boolean clearCustomEffects() {
public List<MCEffect> getCustomEffects() {
List<MCEffect> list = new ArrayList<>();
for(PotionEffect pe : pm.getCustomEffects()) {
list.add(new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(),
pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
list.add(new MCEffect(BukkitMCPotionEffectType.valueOfConcrete(pe.getType()), pe.getAmplifier(),
pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
}
return list;
}
@Override
public boolean hasCustomEffect(int id) {
return pm.hasCustomEffect(PotionEffectType.getById(id));
public boolean hasCustomEffect(MCPotionEffectType type) {
return pm.hasCustomEffect((PotionEffectType) type.getConcrete());
}
@Override
@@ -68,8 +65,8 @@ public boolean hasCustomEffects() {
}
@Override
public boolean removeCustomEffect(int id) {
return pm.removeCustomEffect(PotionEffectType.getById(id));
public boolean removeCustomEffect(MCPotionEffectType type) {
return pm.removeCustomEffect((PotionEffectType) type.getConcrete());
}
}
@@ -12,6 +12,7 @@
import com.laytonsmith.abstraction.entities.MCAreaEffectCloud;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCParticle;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Entity;
import org.bukkit.potion.PotionData;
@@ -46,8 +47,8 @@ public MCColor getColor() {
public List<MCLivingEntity.MCEffect> getCustomEffects() {
List<MCLivingEntity.MCEffect> list = new ArrayList<>();
for(PotionEffect pe : aec.getCustomEffects()) {
list.add(new MCLivingEntity.MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
list.add(new MCLivingEntity.MCEffect(BukkitMCPotionEffectType.valueOfConcrete(pe.getType()),
pe.getAmplifier(), pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
}
return list;
}
@@ -103,7 +104,7 @@ public int getWaitTime() {
@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect) {
PotionEffectType type = PotionEffectType.getById(effect.getPotionID());
PotionEffectType type = (PotionEffectType) effect.getPotionEffectType().getConcrete();
PotionEffect pe = new PotionEffect(type, effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(),
effect.hasParticles(), effect.showIcon());
aec.addCustomEffect(pe, true);
@@ -11,6 +11,8 @@
import com.laytonsmith.abstraction.bukkit.BukkitMCEntityEquipment;
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlock;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.exceptions.CRE.CREBadEntityException;
import org.bukkit.Material;
@@ -189,20 +191,14 @@ public boolean hasAI() {
}
@Override
public void addEffect(int id, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
PotionEffectType type = PotionEffectType.getById(id);
PotionEffect pe = new PotionEffect(type, ticks, strength, ambient, particles, icon);
le.addPotionEffect(pe, true);
public boolean addEffect(MCPotionEffectType type, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
PotionEffect pe = new PotionEffect((PotionEffectType) type.getConcrete(), ticks, strength, ambient, particles, icon);
return le.addPotionEffect(pe, true);
}
@Override
public int getMaxEffect() {
return PotionEffectType.values().length - 1;
}
@Override
public boolean removeEffect(int potionID) {
PotionEffectType t = PotionEffectType.getById(potionID);
public boolean removeEffect(MCPotionEffectType type) {
PotionEffectType t = (PotionEffectType) type.getConcrete();
boolean hasIt = false;
for(PotionEffect pe : le.getActivePotionEffects()) {
if(pe.getType() == t) {
@@ -225,8 +221,8 @@ public void removeEffects() {
public List<MCEffect> getEffects() {
List<MCEffect> effects = new ArrayList<>();
for(PotionEffect pe : le.getActivePotionEffects()) {
MCEffect e = new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient(),
pe.hasParticles(), pe.hasIcon());
MCEffect e = new MCEffect(BukkitMCPotionEffectType.valueOfConcrete(pe.getType()), pe.getAmplifier(), pe.getDuration(),
pe.isAmbient(), pe.hasParticles(), pe.hasIcon());
effects.add(e);
}
return effects;
@@ -21,6 +21,7 @@
import com.laytonsmith.abstraction.bukkit.BukkitMCScoreboard;
import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.MCPotionEffectType;
import com.laytonsmith.abstraction.enums.MCSound;
import com.laytonsmith.abstraction.enums.MCSoundCategory;
import com.laytonsmith.abstraction.enums.MCWeather;
@@ -292,8 +293,8 @@ public void kickPlayer(String message) {
}
@Override
public boolean removeEffect(int potionID) {
PotionEffectType t = PotionEffectType.getById(potionID);
public boolean removeEffect(MCPotionEffectType type) {
PotionEffectType t = (PotionEffectType) type.getConcrete();
boolean hasIt = false;
for(PotionEffect pe : p.getActivePotionEffects()) {
if(pe.getType() == t) {
@@ -4,6 +4,7 @@
import com.laytonsmith.abstraction.MCPotionData;
import com.laytonsmith.abstraction.bukkit.BukkitMCPotionData;
import com.laytonsmith.abstraction.entities.MCTippedArrow;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TippedArrow;
import org.bukkit.potion.PotionData;
@@ -31,15 +32,15 @@ public MCPotionData getBasePotionData() {
public List<MCLivingEntity.MCEffect> getCustomEffects() {
List<MCLivingEntity.MCEffect> list = new ArrayList<>();
for(PotionEffect pe : ta.getCustomEffects()) {
list.add(new MCLivingEntity.MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
list.add(new MCLivingEntity.MCEffect(BukkitMCPotionEffectType.valueOfConcrete(pe.getType()),
pe.getAmplifier(), pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
}
return list;
}
@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect) {
PotionEffect pe = new PotionEffect(PotionEffectType.getById(effect.getPotionID()),
PotionEffect pe = new PotionEffect((PotionEffectType) effect.getPotionEffectType().getConcrete(),
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles(),
effect.showIcon());
ta.addCustomEffect(pe, true);
Oops, something went wrong.

0 comments on commit 1886834

Please sign in to comment.