mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-28 03:19:25 +00:00
Updated effects
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AttackSpeedMultiplier extends Effect<Double> {
|
||||
@@ -15,23 +13,28 @@ public class AttackSpeedMultiplier extends Effect<Double> {
|
||||
super("attack-speed-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
assert maxHealth != null;
|
||||
|
||||
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
assert movementSpeed != null;
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
|
||||
} else {
|
||||
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
|
||||
if (!movementSpeed.getModifiers().contains(modifier)) {
|
||||
movementSpeed.addModifier(modifier);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 1 - multiplier, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
|
||||
if (!maxHealth.getModifiers().contains(modifier)) {
|
||||
maxHealth.addModifier(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable(@NotNull final Player player) {
|
||||
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
assert maxHealth != null;
|
||||
|
||||
maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BonusHearts extends Effect<Integer> {
|
||||
@@ -15,23 +13,28 @@ public class BonusHearts extends Effect<Integer> {
|
||||
super("bonus-hearts", Integer.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
assert maxHealth != null;
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
Integer bonus = ArmorUtils.getEffectStrength(player, this);
|
||||
if (bonus == null) {
|
||||
maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER));
|
||||
} else {
|
||||
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", bonus * 2, AttributeModifier.Operation.ADD_NUMBER);
|
||||
if (!maxHealth.getModifiers().contains(modifier)) {
|
||||
maxHealth.addModifier(modifier);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
Integer bonus = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (bonus == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable(@NotNull final Player player) {
|
||||
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
assert maxHealth != null;
|
||||
|
||||
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER);
|
||||
if (!maxHealth.getModifiers().contains(modifier)) {
|
||||
maxHealth.addModifier(modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ public class BowDamageMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = (Player) shooter;
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
|
||||
@@ -38,6 +38,10 @@ public class DamageMultiplier extends Effect<Double> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isEnabledForPlayer(attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(attacker, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
|
||||
@@ -24,6 +24,10 @@ public class DamageTakenMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
|
||||
@@ -21,6 +21,10 @@ public class DurabilityMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (multiplier == null) {
|
||||
|
||||
@@ -25,6 +25,10 @@ public class EvadeChance extends Effect<Double> {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double chance = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (chance == null) {
|
||||
|
||||
@@ -16,6 +16,10 @@ public class ExperienceMultiplier extends Effect<Double> {
|
||||
public void listener(@NotNull final NaturalExpGainEvent event) {
|
||||
Player player = event.getExpChangeEvent().getPlayer();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getExpChangeEvent().getAmount() < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ public class FallDamageMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Flight extends Effect<Boolean> {
|
||||
@@ -13,21 +10,15 @@ public class Flight extends Effect<Boolean> {
|
||||
super("flight", Boolean.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
Boolean flight = ArmorUtils.getEffectStrength(player, this);
|
||||
if (flight == null) {
|
||||
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
player.setAllowFlight(false);
|
||||
}
|
||||
} else {
|
||||
if (flight) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
@Override
|
||||
protected void onDisable(@NotNull final Player player) {
|
||||
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
player.setAllowFlight(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ public class HungerLossMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (multiplier == null) {
|
||||
|
||||
@@ -24,6 +24,10 @@ public class MeleeDamageMultiplier extends Effect<Double> {
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
|
||||
if (!this.isEnabledForPlayer(attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(attacker, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
|
||||
@@ -24,6 +24,10 @@ public class RegenerationMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (multiplier == null) {
|
||||
|
||||
@@ -33,6 +33,10 @@ public class TridentDamageMultiplier extends Effect<Double> {
|
||||
|
||||
Player player = (Player) shooter;
|
||||
|
||||
if (!this.isEnabledForPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
|
||||
@@ -34,10 +34,6 @@ public class WarpChance extends Effect<Double> {
|
||||
Player player = (Player) event.getDamager();
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if (!ArmorUtils.hasEffect(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double chance = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (chance == null) {
|
||||
|
||||
@@ -123,37 +123,6 @@ public class ArmorUtils {
|
||||
return strength;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player has an active effect.
|
||||
*
|
||||
* @param player The player to test.
|
||||
* @param effect The effect to test.
|
||||
* @return If a player has an active effect.
|
||||
*/
|
||||
public boolean hasEffect(@NotNull final Player player,
|
||||
@NotNull final Effect<?> effect) {
|
||||
return getEffectStrength(player, effect) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a condition on a player's set.
|
||||
*
|
||||
* @param player The player to test.
|
||||
* @param condition The condition to test.
|
||||
* @param <T> Condition type.
|
||||
* @return The value or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public <T> T getConditionValue(@NotNull final Player player,
|
||||
@NotNull final Condition<T> condition) {
|
||||
ArmorSet set = getSetOnPlayer(player);
|
||||
if (set == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return set.getConditionValue(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if all conditions are met for a player.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user