add same logic I did for chi move passive/stances to air passive and avatar state effects, everywhere else it looks like TempPotionEffect is used which is basically just a more complicated way of doing the same thing as this change

This commit is contained in:
PhanaticD 2019-01-24 11:14:34 -05:00
parent 375da96239
commit 1757e7ad1a
5 changed files with 29 additions and 58 deletions

View file

@ -1,18 +1,14 @@
package com.projectkorra.projectkorra.airbending.passive; package com.projectkorra.projectkorra.airbending.passive;
import com.projectkorra.projectkorra.ability.AirAbility;
import com.projectkorra.projectkorra.ability.PassiveAbility;
import com.projectkorra.projectkorra.attribute.Attribute;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.projectkorra.projectkorra.ability.AirAbility;
import com.projectkorra.projectkorra.ability.ChiAbility;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.PassiveAbility;
import com.projectkorra.projectkorra.attribute.Attribute;
import com.projectkorra.projectkorra.chiblocking.passive.ChiAgility;
import com.projectkorra.projectkorra.configuration.ConfigManager;
public class AirAgility extends AirAbility implements PassiveAbility { public class AirAgility extends AirAbility implements PassiveAbility {
// Configurable variables. // Configurable variables.
@ -31,8 +27,8 @@ public class AirAgility extends AirAbility implements PassiveAbility {
} }
public void setFields() { public void setFields() {
this.jumpPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.JumpPower"); this.jumpPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.JumpPower") - 1;
this.speedPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.SpeedPower"); this.speedPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.SpeedPower") - 1;
} }
@Override @Override
@ -41,42 +37,13 @@ public class AirAgility extends AirAbility implements PassiveAbility {
return; return;
} }
if (CoreAbility.hasAbility(this.player, ChiAgility.class) && this.bPlayer.canBendPassive(CoreAbility.getAbility(ChiAbility.class))) {
final ChiAgility chiAgility = CoreAbility.getAbility(this.player, ChiAgility.class);
if (chiAgility.getJumpPower() > this.jumpPower) {
this.jumpPower = chiAgility.getJumpPower();
}
if (chiAgility.getSpeedPower() > this.speedPower) {
this.speedPower = chiAgility.getSpeedPower();
}
}
// Jump Buff. // Jump Buff.
this.jumpActivate = true; if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jumpPower || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() == this.jumpPower && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) {
if (this.player.hasPotionEffect(PotionEffectType.JUMP)) { this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jumpPower, true, false), true);
final PotionEffect potion = this.player.getPotionEffect(PotionEffectType.JUMP);
if (potion.getAmplifier() > this.jumpPower - 1) {
this.jumpActivate = false;
} else {
this.player.removePotionEffect(PotionEffectType.JUMP);
}
} }
if (this.jumpActivate) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, this.jumpPower - 1, true, false), false);
}
// Speed Buff. // Speed Buff.
this.speedActivate = true; if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speedPower || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() == this.speedPower && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) {
if (this.player.hasPotionEffect(PotionEffectType.SPEED)) { this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speedPower, true, false), true);
final PotionEffect potion = this.player.getPotionEffect(PotionEffectType.SPEED);
if (potion.getAmplifier() > this.speedPower - 1) {
this.speedActivate = false;
} else {
this.player.removePotionEffect(PotionEffectType.SPEED);
}
}
if (this.speedActivate) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, this.speedPower - 1, true, false), false);
} }
} }

View file

@ -1,14 +1,13 @@
package com.projectkorra.projectkorra.avatar; package com.projectkorra.projectkorra.avatar;
import java.util.HashMap; import com.projectkorra.projectkorra.ability.AvatarAbility;
import com.projectkorra.projectkorra.attribute.Attribute;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.projectkorra.projectkorra.ability.AvatarAbility; import java.util.HashMap;
import com.projectkorra.projectkorra.attribute.Attribute;
public class AvatarState extends AvatarAbility { public class AvatarState extends AvatarAbility {
@ -85,18 +84,23 @@ public class AvatarState extends AvatarAbility {
} }
private void addPotionEffects() { private void addPotionEffects() {
final int duration = 70;
if (this.regenEnabled) { if (this.regenEnabled) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, this.regenPower)); addProgressPotionEffect(PotionEffectType.REGENERATION, this.regenPower);
} }
if (this.speedEnabled) { if (this.speedEnabled) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, duration, this.speedPower)); addProgressPotionEffect(PotionEffectType.SPEED, this.speedPower);
} }
if (this.resistanceEnabled) { if (this.resistanceEnabled) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, this.resistancePower)); addProgressPotionEffect(PotionEffectType.DAMAGE_RESISTANCE, this.resistancePower);
} }
if (this.fireResistanceEnabled) { if (this.fireResistanceEnabled) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, duration, this.fireResistancePower)); addProgressPotionEffect(PotionEffectType.FIRE_RESISTANCE, this.fireResistancePower);
}
}
private void addProgressPotionEffect(PotionEffectType effect, int power) {
if (!this.player.hasPotionEffect(effect) || this.player.getPotionEffect(effect).getAmplifier() < power || (this.player.getPotionEffect(effect).getAmplifier() == power && this.player.getPotionEffect(effect).getDuration() == 1)) {
this.player.addPotionEffect(new PotionEffect(effect, 10, power, true, false), true);
} }
} }

View file

@ -62,10 +62,10 @@ public class AcrobatStance extends ChiAbility {
return; return;
} }
if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speed || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() <= this.speed && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) { if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speed || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() == this.speed && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speed, true, false), true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speed, true, false), true);
} }
if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jump || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() <= this.jump && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) { if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jump || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() == this.jump && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jump, true, false), true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jump, true, false), true);
} }
} }

View file

@ -57,10 +57,10 @@ public class WarriorStance extends ChiAbility {
return; return;
} }
if (!this.player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE) || this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getAmplifier() > this.resistance || (this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getAmplifier() >= this.resistance && this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getDuration() == 1)) { //special case for negative resistance if (!this.player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE) || this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getAmplifier() > this.resistance || (this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getAmplifier() == this.resistance && this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getDuration() == 1)) { //special case for negative resistance
this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10, this.resistance, true, false), true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10, this.resistance, true, false), true);
} }
if (!this.player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE) || this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() < this.strength || (this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() <= this.strength && this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getDuration() == 1)) { if (!this.player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE) || this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() < this.strength || (this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() == this.strength && this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getDuration() == 1)) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10, this.strength, true, false), true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10, this.strength, true, false), true);
} }
} }

View file

@ -34,11 +34,11 @@ public class ChiAgility extends ChiAbility implements PassiveAbility {
} }
// Jump Buff. // Jump Buff.
if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jumpPower || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() <= this.jumpPower && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) { if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jumpPower || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() == this.jumpPower && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jumpPower, true, false), true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jumpPower, true, false), true);
} }
// Speed Buff. // Speed Buff.
if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speedPower || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() <= this.speedPower && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) { if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speedPower || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() == this.speedPower && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speedPower, true, false), true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speedPower, true, false), true);
} }
} }