mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-19 15:09:26 +00:00
Quick push in case pc dies
This commit is contained in:
@@ -6,7 +6,7 @@ import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Effect implements Listener {
|
||||
public abstract class Effect<T> implements Listener {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
@@ -19,6 +19,11 @@ public abstract class Effect implements Listener {
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Create a new effect.
|
||||
*
|
||||
* @param name The effect name.
|
||||
*/
|
||||
protected Effect(@NotNull final String name) {
|
||||
this.name = name;
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.w3c.dom.Attr;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -17,7 +16,7 @@ public class BonusHearts extends Effect {
|
||||
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("bonus-hearts".getBytes());
|
||||
|
||||
public BonusHearts() {
|
||||
super("bonus-hearts");
|
||||
super("bonus-hearts", ValueType.INT);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BowDamageMultiplier extends Effect {
|
||||
public BowDamageMultiplier() {
|
||||
super("bow-damage-multiplier");
|
||||
super("bow-damage-multiplier", ValueType.DOUBLE);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DamageMultiplier extends Effect {
|
||||
public DamageMultiplier() {
|
||||
super("damage-multiplier");
|
||||
super("damage-multiplier", ValueType.DOUBLE);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DamageTakenMultiplier extends Effect {
|
||||
public DamageTakenMultiplier() {
|
||||
super("damage-taken-multiplier");
|
||||
super("damage-taken-multiplier", ValueType.DOUBLE);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DurabilityMultiplier extends Effect {
|
||||
public class DurabilityMultiplier extends Effect<Double> {
|
||||
public DurabilityMultiplier() {
|
||||
super("durability-multiplier");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EvadeChance extends Effect {
|
||||
public class EvadeChance extends Effect<Double> {
|
||||
public EvadeChance() {
|
||||
super("evade-chance");
|
||||
}
|
||||
@@ -25,7 +25,11 @@ public class EvadeChance extends Effect {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
double chance = ArmorUtils.getEffectStrength(player, this);
|
||||
Double chance = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (chance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NumberUtils.randFloat(0, 100) < chance) {
|
||||
event.setCancelled(true);
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExperienceMultiplier extends Effect {
|
||||
public class ExperienceMultiplier extends Effect<Double> {
|
||||
public ExperienceMultiplier() {
|
||||
super("experience-multiplier");
|
||||
}
|
||||
@@ -20,9 +20,9 @@ public class ExperienceMultiplier extends Effect {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (multiplier == 0) {
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FallDamageMultiplier extends Effect {
|
||||
public class FallDamageMultiplier extends Effect<Double> {
|
||||
public FallDamageMultiplier() {
|
||||
super("fall-damage-multiplier");
|
||||
}
|
||||
@@ -28,8 +28,8 @@ public class FallDamageMultiplier extends Effect {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == 0) {
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MeleeDamageMultiplier extends Effect {
|
||||
public class MeleeDamageMultiplier extends Effect<Double> {
|
||||
public MeleeDamageMultiplier() {
|
||||
super("melee-damage-multiplier");
|
||||
}
|
||||
@@ -24,8 +24,8 @@ public class MeleeDamageMultiplier extends Effect {
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
|
||||
double multiplier = ArmorUtils.getEffectStrength(attacker, this);
|
||||
if (multiplier == 0) {
|
||||
Double multiplier = ArmorUtils.getEffectStrength(attacker, this);
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RegenerationMultiplier extends Effect {
|
||||
public class RegenerationMultiplier extends Effect<Double> {
|
||||
public RegenerationMultiplier() {
|
||||
super("regeneration-multiplier");
|
||||
}
|
||||
@@ -24,9 +24,9 @@ public class RegenerationMultiplier extends Effect {
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (multiplier == 0) {
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpeedMutiplier extends Effect {
|
||||
public class SpeedMutiplier extends Effect<Double> {
|
||||
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed-multiplier".getBytes());
|
||||
|
||||
public SpeedMutiplier() {
|
||||
@@ -27,8 +27,8 @@ public class SpeedMutiplier extends Effect {
|
||||
assert movementSpeed != null;
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == 0) {
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
if (multiplier == null) {
|
||||
movementSpeed.removeModifier(new AttributeModifier(MODIFIER_UUID, "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
|
||||
} else {
|
||||
AttributeModifier modifier = new AttributeModifier(MODIFIER_UUID, "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TridentDamageMultiplier extends Effect {
|
||||
public class TridentDamageMultiplier extends Effect<Double> {
|
||||
public TridentDamageMultiplier() {
|
||||
super("trident-damage-multiplier");
|
||||
}
|
||||
@@ -37,7 +37,12 @@ public class TridentDamageMultiplier extends Effect {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = ArmorUtils.getEffectStrength(attacker, this);
|
||||
Double multiplier = ArmorUtils.getEffectStrength(attacker, this);
|
||||
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (multiplier == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.willfp.ecoarmor.effects.effects;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@@ -13,7 +12,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WarpChance extends Effect {
|
||||
public class WarpChance extends Effect<Double> {
|
||||
public WarpChance() {
|
||||
super("warp-chance");
|
||||
}
|
||||
@@ -35,7 +34,15 @@ public class WarpChance extends Effect {
|
||||
Player player = (Player) event.getDamager();
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
double chance = ArmorUtils.getEffectStrength(player, this);
|
||||
if (!ArmorUtils.hasEffect(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Double chance = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (chance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NumberUtils.randFloat(0, 100) > chance) {
|
||||
return;
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ArmorSet {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
@@ -48,7 +49,7 @@ public class ArmorSet {
|
||||
* Effects and their strengths.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<Effect, Double> effects = new HashMap<>();
|
||||
private final Map<Effect<?>, Object> effects = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Potion effects to be applied on equip.
|
||||
@@ -70,8 +71,8 @@ public class ArmorSet {
|
||||
this.name = name;
|
||||
|
||||
for (String effectName : EcoArmorConfigs.SETS.getConfig().getConfigurationSection(name + ".set-bonus").getKeys(false)) {
|
||||
Effect effect = Effects.getByName(effectName);
|
||||
double value = EcoArmorConfigs.SETS.getDouble(name + ".set-bonus." + effectName);
|
||||
Effect<?> effect = Effects.getByName(effectName);
|
||||
Object value = EcoArmorConfigs.SETS.getConfig().get(name + ".set-bonus." + effectName);
|
||||
effects.put(effect, value);
|
||||
}
|
||||
|
||||
@@ -160,6 +161,17 @@ public class ArmorSet {
|
||||
return items.get(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get effect strength of effect.
|
||||
*
|
||||
* @param effect The effect to query.
|
||||
* @param <T> The type of the effect value.
|
||||
* @return The strength.
|
||||
*/
|
||||
public <T> T getEffectStrength(@NotNull final Effect<T> effect) {
|
||||
return (T) effects.get(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -99,20 +99,18 @@ public class ArmorUtils {
|
||||
*
|
||||
* @param player The player to test.
|
||||
* @param effect The effect to test.
|
||||
* @return The strength, or 0 if not found.
|
||||
* @param <T> Effect type.
|
||||
* @return The strength, or null if not found.
|
||||
*/
|
||||
public double getEffectStrength(@NotNull final Player player,
|
||||
@NotNull final Effect effect) {
|
||||
@Nullable
|
||||
public <T> T getEffectStrength(@NotNull final Player player,
|
||||
@NotNull final Effect<T> effect) {
|
||||
ArmorSet set = getSetOnPlayer(player);
|
||||
if (set == null) {
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (set.getEffects().containsKey(effect)) {
|
||||
return set.getEffects().get(effect);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return set.getEffectStrength(effect);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,8 +121,8 @@ public class ArmorUtils {
|
||||
* @return If a player has an active effect.
|
||||
*/
|
||||
public boolean hasEffect(@NotNull final Player player,
|
||||
@NotNull final Effect effect) {
|
||||
return getEffectStrength(player, effect) != 0;
|
||||
@NotNull final Effect<?> effect) {
|
||||
return getEffectStrength(player, effect) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user