9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-27 10:59:22 +00:00

Fixed type erasure issue with integer values in double getters

This commit is contained in:
Auxilor
2021-01-23 15:54:48 +00:00
parent 5923e3cb40
commit 3901849977
18 changed files with 46 additions and 20 deletions

View File

@@ -25,13 +25,22 @@ public abstract class Effect<T> implements Listener {
@Getter
private boolean enabled;
/**
* The class of the config getter type.
*/
@Getter
private final Class<T> typeClass;
/**
* Create a new effect.
*
* @param name The effect name.
* @param name The effect name.
* @param typeClass The class of the config type.
*/
protected Effect(@NotNull final String name) {
protected Effect(@NotNull final String name,
@NotNull final Class<T> typeClass) {
this.name = name;
this.typeClass = typeClass;
update();
Effects.addNewEffect(this);

View File

@@ -16,7 +16,7 @@ public class AttackSpeedMultiplier extends Effect<Double> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("attack-speed-multiplier".getBytes());
public AttackSpeedMultiplier() {
super("attack-speed-multiplier");
super("attack-speed-multiplier", Double.class);
}
@EventHandler

View File

@@ -16,7 +16,7 @@ public class BonusHearts extends Effect<Integer> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("bonus-hearts".getBytes());
public BonusHearts() {
super("bonus-hearts");
super("bonus-hearts", Integer.class);
}
@EventHandler

View File

@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
public class BowDamageMultiplier extends Effect<Double> {
public BowDamageMultiplier() {
super("bow-damage-multiplier");
super("bow-damage-multiplier", Double.class);
}
@EventHandler

View File

@@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
public class DamageMultiplier extends Effect<Double> {
public DamageMultiplier() {
super("damage-multiplier");
super("damage-multiplier", Double.class);
}
@EventHandler

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
public class DamageTakenMultiplier extends Effect<Double> {
public DamageTakenMultiplier() {
super("damage-taken-multiplier");
super("damage-taken-multiplier", Double.class);
}
@EventHandler

View File

@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class DurabilityMultiplier extends Effect<Double> {
public DurabilityMultiplier() {
super("durability-multiplier");
super("durability-multiplier", Double.class);
}
@EventHandler

View File

@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class EvadeChance extends Effect<Double> {
public EvadeChance() {
super("evade-chance");
super("evade-chance", Double.class);
}
@EventHandler

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
public class ExperienceMultiplier extends Effect<Double> {
public ExperienceMultiplier() {
super("experience-multiplier");
super("experience-multiplier", Double.class);
}
@EventHandler

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
public class FallDamageMultiplier extends Effect<Double> {
public FallDamageMultiplier() {
super("fall-damage-multiplier");
super("fall-damage-multiplier", Double.class);
}
@EventHandler

View File

@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class Flight extends Effect<Boolean> {
public Flight() {
super("flight");
super("flight", Boolean.class);
}
@EventHandler

View File

@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class HungerLossMultiplier extends Effect<Double> {
public HungerLossMultiplier() {
super("hunger-loss-multiplier");
super("hunger-loss-multiplier", Double.class);
}
@EventHandler

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
public class MeleeDamageMultiplier extends Effect<Double> {
public MeleeDamageMultiplier() {
super("melee-damage-multiplier");
super("melee-damage-multiplier", Double.class);
}
@EventHandler

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
public class RegenerationMultiplier extends Effect<Double> {
public RegenerationMultiplier() {
super("regeneration-multiplier");
super("regeneration-multiplier", Double.class);
}
@EventHandler

View File

@@ -16,7 +16,7 @@ public class SpeedMutiplier extends Effect<Double> {
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed-multiplier".getBytes());
public SpeedMutiplier() {
super("speed-multiplier");
super("speed-multiplier", Double.class);
}
@EventHandler

View File

@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
public class TridentDamageMultiplier extends Effect<Double> {
public TridentDamageMultiplier() {
super("trident-damage-multiplier");
super("trident-damage-multiplier", Double.class);
}
@EventHandler

View File

@@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
public class WarpChance extends Effect<Double> {
public WarpChance() {
super("warp-chance");
super("warp-chance", Double.class);
}
@EventHandler

View File

@@ -27,6 +27,7 @@ import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -291,8 +292,16 @@ public class ArmorSet {
* @param <T> The type of the effect value.
* @return The strength.
*/
@Nullable
public <T> T getEffectStrength(@NotNull final Effect<T> effect) {
return (T) effects.get(effect);
Object strength = effects.get(effect);
if (strength instanceof Integer) {
if (effect.getTypeClass().equals(Double.class)) {
strength = (double) (int) strength;
}
}
return (T) strength;
}
/**
@@ -302,8 +311,16 @@ public class ArmorSet {
* @param <T> The type of the effect value.
* @return The strength.
*/
@Nullable
public <T> T getAdvancedEffectStrength(@NotNull final Effect<T> effect) {
return (T) advancedEffects.get(effect);
Object strength = advancedEffects.get(effect);
if (strength instanceof Integer) {
if (effect.getTypeClass().equals(Double.class)) {
strength = (double) (int) strength;
}
}
return (T) strength;
}
@Override