9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-30 20:39:13 +00:00

Merge remote-tracking branch 'origin/master' into master

This commit is contained in:
Auxilor
2021-02-21 17:07:40 +00:00
38 changed files with 904 additions and 157 deletions

View File

@@ -8,7 +8,10 @@
<!-- Effects don't need javadoc. -->
<suppress files="[\\/]effects[\\/]effects[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]effects[\\/]effects[\\/]" checks="JavadocVariable"/>
<suppress files="[\\/]conditions[\\/]conditions[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]conditions[\\/]conditions[\\/]" checks="JavadocVariable"/>
<!-- Fields don't need javadoc -->
<suppress files="Effects.java" checks="JavadocVariable"/>
<suppress files="Conditions.java" checks="JavadocVariable"/>
</suppressions>

View File

@@ -8,15 +8,17 @@ import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.ecoarmor.commands.CommandEagive;
import com.willfp.ecoarmor.commands.CommandEareload;
import com.willfp.ecoarmor.commands.TabcompleterEagive;
import com.willfp.ecoarmor.conditions.Conditions;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.effects.Effects;
import com.willfp.ecoarmor.effects.util.EffectWatcher;
import com.willfp.ecoarmor.sets.ArmorSets;
import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener;
import com.willfp.ecoarmor.sets.util.PotionEffectListener;
import com.willfp.ecoarmor.upgrades.Tiers;
import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener;
import com.willfp.ecoarmor.upgrades.listeners.CrystalListener;
import com.willfp.ecoarmor.upgrades.Tiers;
import com.willfp.ecoarmor.util.DiscoverRecipeListener;
import lombok.Getter;
import org.bukkit.event.Listener;
@@ -48,6 +50,7 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
@Override
public void enable() {
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
Conditions.values().forEach(condition -> this.getEventManager().registerListener(condition));
this.getExtensionLoader().loadExtensions();
@@ -139,7 +142,8 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
new AdvancementShardListener(this),
new PotionEffectListener(this),
new EffectiveDurabilityListener(this),
new DiscoverRecipeListener(this)
new DiscoverRecipeListener(this),
new EffectWatcher(this)
);
}

View File

@@ -0,0 +1,85 @@
package com.willfp.ecoarmor.conditions;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public abstract class Condition<T> implements Listener {
/**
* Instance of EcoArmor.
*/
@Getter(AccessLevel.PROTECTED)
private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance();
/**
* The name of the effect.
*/
@Getter
private final String name;
/**
* The class of the config getter type.
*/
@Getter
private final Class<T> typeClass;
/**
* Create a new condition.
*
* @param name The condition name.
* @param typeClass The class of the config type.
*/
protected Condition(@NotNull final String name,
@NotNull final Class<T> typeClass) {
this.name = name;
this.typeClass = typeClass;
Conditions.addNewCondition(this);
}
/**
* Get if condition is met for a player.
*
* @param player The player.
* @param value The value of the condition.
* @return If met.
*/
public final boolean isMet(@NotNull final Player player,
@NotNull final Object value) {
return isConditionMet(player, typeClass.cast(value));
}
protected abstract boolean isConditionMet(@NotNull Player player,
@NotNull T value);
protected final void evaluateEffects(@NotNull final Player player,
@NotNull final T value,
@NotNull final ArmorSet set) {
this.getPlugin().getScheduler().runLater(() -> {
if (isMet(player, value)) {
for (Effect<?> effect : set.getEffects().keySet()) {
Object strength = set.getEffectStrength(effect);
if (ArmorUtils.isWearingAdvanced(player)) {
Object advancedStrength = set.getAdvancedEffectStrength(effect);
if (advancedStrength != null) {
strength = advancedStrength;
}
}
if (strength != null) {
effect.enable(player, strength);
}
}
} else {
set.getEffects().keySet().forEach(effect -> effect.disable(player));
}
}, 1);
}
}

View File

@@ -0,0 +1,64 @@
package com.willfp.ecoarmor.conditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import com.willfp.ecoarmor.conditions.conditions.ConditionAboveHealthPercent;
import com.willfp.ecoarmor.conditions.conditions.ConditionAboveXPLevel;
import com.willfp.ecoarmor.conditions.conditions.ConditionAboveY;
import com.willfp.ecoarmor.conditions.conditions.ConditionBelowHealthPercent;
import com.willfp.ecoarmor.conditions.conditions.ConditionBelowXPLevel;
import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY;
import com.willfp.ecoarmor.conditions.conditions.ConditionInWater;
import com.willfp.ecoarmor.conditions.conditions.ConditionInWorld;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@UtilityClass
@SuppressWarnings("unused")
public class Conditions {
/**
* All registered effects.
*/
private static final BiMap<String, Condition<?>> BY_NAME = HashBiMap.create();
public static final Condition<?> BELOW_Y = new ConditionBelowY();
public static final Condition<?> ABOVE_Y = new ConditionAboveY();
public static final Condition<?> ABOVE_HEALTH_PERCENT = new ConditionAboveHealthPercent();
public static final Condition<?> BELOW_HEALTH_PERCENT = new ConditionBelowHealthPercent();
public static final Condition<?> IN_WATER = new ConditionInWater();
public static final Condition<?> IN_WORLD = new ConditionInWorld();
public static final Condition<?> ABOVE_XP_LEVEL = new ConditionAboveXPLevel();
public static final Condition<?> BELOW_XP_LEVEL = new ConditionBelowXPLevel();
/**
* Get condition matching name.s
*
* @param name The name to query.
* @return The matching condition, or null if not found.
*/
public static Condition<?> getByName(@NotNull final String name) {
return BY_NAME.get(name);
}
/**
* List of all registered conditions.
*
* @return The conditions.
*/
public static List<Condition<?>> values() {
return ImmutableList.copyOf(BY_NAME.values());
}
/**
* Add new condition to EcoArmor.
*
* @param condition The condition to add.
*/
public static void addNewCondition(@NotNull final Condition<?> condition) {
BY_NAME.remove(condition.getName());
BY_NAME.put(condition.getName(), condition);
}
}

View File

@@ -0,0 +1,79 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionAboveHealthPercent extends Condition<Double> {
public ConditionAboveHealthPercent() {
super("above-health-percent", Double.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final EntityRegainHealthEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Double value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Double value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Double value) {
double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double health = player.getHealth();
return (health / maxHealth) * 100 >= value;
}
}

View File

@@ -0,0 +1,44 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerExpChangeEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionAboveXPLevel extends Condition<Integer> {
public ConditionAboveXPLevel() {
super("above-xp-level", Integer.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final PlayerExpChangeEvent event) {
Player player = event.getPlayer();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Integer value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Integer value) {
return player.getLevel() >= value;
}
}

View File

@@ -0,0 +1,44 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionAboveY extends Condition<Double> {
public ConditionAboveY() {
super("above-y", Double.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final PlayerMoveEvent event) {
Player player = event.getPlayer();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Double value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Double value) {
return player.getLocation().getY() >= value;
}
}

View File

@@ -0,0 +1,79 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionBelowHealthPercent extends Condition<Double> {
public ConditionBelowHealthPercent() {
super("below-health-percent", Double.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final EntityRegainHealthEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Double value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Double value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Double value) {
double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double health = player.getHealth();
return (health / maxHealth) * 100 < value;
}
}

View File

@@ -0,0 +1,44 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerExpChangeEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionBelowXPLevel extends Condition<Integer> {
public ConditionBelowXPLevel() {
super("below-xp-level", Integer.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final PlayerExpChangeEvent event) {
Player player = event.getPlayer();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Integer value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Integer value) {
return player.getLevel() < value;
}
}

View File

@@ -0,0 +1,44 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionBelowY extends Condition<Double> {
public ConditionBelowY() {
super("below-y", Double.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final PlayerMoveEvent event) {
Player player = event.getPlayer();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Double value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Double value) {
return player.getLocation().getY() < value;
}
}

View File

@@ -0,0 +1,45 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import org.jetbrains.annotations.NotNull;
public class ConditionInWater extends Condition<Boolean> {
public ConditionInWater() {
super("in-water", Boolean.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final PlayerMoveEvent event) {
Player player = event.getPlayer();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
Boolean value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Boolean value) {
return (player.getLocation().getBlock().getType() == Material.WATER) == value;
}
}

View File

@@ -0,0 +1,54 @@
package com.willfp.ecoarmor.conditions.conditions;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
public class ConditionInWorld extends Condition<String> {
public ConditionInWorld() {
super("in-world", String.class);
}
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true
)
public void listener(@NotNull final PlayerMoveEvent event) {
Player player = event.getPlayer();
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
if (set == null) {
return;
}
String value = set.getConditionValue(this);
if (value == null) {
return;
}
evaluateEffects(player, value, set);
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final String value) {
List<String> worldNames = Arrays.asList(value.toLowerCase().split(" "));
World world = player.getLocation().getWorld();
if (world == null) {
return false;
}
return worldNames.contains(world.getName().toLowerCase());
}
}

View File

@@ -3,9 +3,13 @@ package com.willfp.ecoarmor.effects;
import com.willfp.ecoarmor.EcoArmorPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public abstract class Effect<T> implements Listener {
@@ -39,6 +43,11 @@ public abstract class Effect<T> implements Listener {
@Getter
private final Class<T> typeClass;
/**
* Players that the effect is currently enabled for.
*/
private final Map<UUID, T> enabledPlayers = new HashMap<>();
/**
* Create a new effect.
*
@@ -55,6 +64,57 @@ public abstract class Effect<T> implements Listener {
Effects.addNewEffect(this);
}
/**
* Get the effect strength for a player.
*
* @param player The player.
* @return The strength.
*/
@Nullable
public final T getStrengthForPlayer(@NotNull final Player player) {
return enabledPlayers.get(player.getUniqueId());
}
/**
* Enable the effect for a player.
*
* @param player The player.
* @param value The strength.
*/
public final void enable(@NotNull final Player player,
@NotNull final Object value) {
if (!this.isEnabled()) {
return;
}
if (enabledPlayers.containsKey(player.getUniqueId())) {
return;
}
enabledPlayers.put(player.getUniqueId(), typeClass.cast(value));
this.onEnable(player);
}
/**
* Disable the effect for a player.
*
* @param player The player.
*/
public final void disable(@NotNull final Player player) {
enabledPlayers.remove(player.getUniqueId());
this.onDisable(player);
}
protected void onEnable(@NotNull final Player player) {
// Empty by default
}
protected void onDisable(@NotNull final Player player) {
// Empty by default
}
/**
* Update if the effect is enabled.
*/

View File

@@ -15,7 +15,7 @@ import com.willfp.ecoarmor.effects.effects.Flight;
import com.willfp.ecoarmor.effects.effects.HungerLossMultiplier;
import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
import com.willfp.ecoarmor.effects.effects.SpeedMutiplier;
import com.willfp.ecoarmor.effects.effects.SpeedMultiplier;
import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.WarpChance;
import lombok.experimental.UtilityClass;
@@ -39,7 +39,7 @@ public class Effects {
public static final Effect<?> MELEE_DAMAGE_MULTIPLIER = new MeleeDamageMultiplier();
public static final Effect<?> TRIDENT_DAMAGE_MULTIPLIER = new TridentDamageMultiplier();
public static final Effect<?> BONUS_HEARTS = new BonusHearts();
public static final Effect<?> SPEED_MULTIPLIER = new SpeedMutiplier();
public static final Effect<?> SPEED_MULTIPLIER = new SpeedMultiplier();
public static final Effect<?> EXPERIENCE_MULTIPLIER = new ExperienceMultiplier();
public static final Effect<?> REGENERATION_MULTIPLIER = new RegenerationMultiplier();
public static final Effect<?> WARP_CHANCE = new WarpChance();

View File

@@ -1,13 +1,10 @@
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 +12,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 attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
assert attackSpeed != null;
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
assert movementSpeed != null;
Double multiplier = this.getStrengthForPlayer(player);
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 (attackSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) {
attackSpeed.addModifier(modifier);
}
}
@Override
protected void onDisable(@NotNull final Player player) {
AttributeInstance attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
assert attackSpeed != null;
attackSpeed.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
}
}

View File

@@ -1,13 +1,10 @@
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 +12,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 = this.getStrengthForPlayer(player);
if (bonus == null) {
return;
}
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", bonus, AttributeModifier.Operation.ADD_NUMBER);
if (maxHealth.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) {
maxHealth.addModifier(modifier);
}
}
@Override
protected void onDisable(@NotNull final Player player) {
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
assert maxHealth != null;
maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER));
}
}

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
@@ -33,7 +32,7 @@ public class BowDamageMultiplier extends Effect<Double> {
Player player = (Player) shooter;
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;
}

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
@@ -38,7 +37,7 @@ public class DamageMultiplier extends Effect<Double> {
return;
}
Double multiplier = ArmorUtils.getEffectStrength(attacker, this);
Double multiplier = this.getStrengthForPlayer(attacker);
if (multiplier == null) {
return;
}

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -24,7 +23,7 @@ public class DamageTakenMultiplier extends Effect<Double> {
Player player = (Player) event.getEntity();
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;
}

View File

@@ -2,7 +2,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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemDamageEvent;
@@ -21,7 +20,7 @@ public class DurabilityMultiplier extends Effect<Double> {
Player player = event.getPlayer();
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;

View File

@@ -2,7 +2,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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -25,7 +24,7 @@ public class EvadeChance extends Effect<Double> {
Player player = (Player) event.getEntity();
Double chance = ArmorUtils.getEffectStrength(player, this);
Double chance = this.getStrengthForPlayer(player);
if (chance == null) {
return;

View File

@@ -2,7 +2,6 @@ package com.willfp.ecoarmor.effects.effects;
import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainEvent;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
@@ -20,7 +19,7 @@ public class ExperienceMultiplier extends Effect<Double> {
return;
}
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -28,7 +27,7 @@ public class FallDamageMultiplier extends Effect<Double> {
Player player = (Player) event.getEntity();
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;
}

View File

@@ -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);
}
}
}

View File

@@ -2,7 +2,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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.FoodLevelChangeEvent;
@@ -21,7 +20,7 @@ public class HungerLossMultiplier extends Effect<Double> {
Player player = (Player) event.getEntity();
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@@ -24,7 +23,8 @@ public class MeleeDamageMultiplier extends Effect<Double> {
Player attacker = (Player) event.getDamager();
Double multiplier = ArmorUtils.getEffectStrength(attacker, this);
Double multiplier = this.getStrengthForPlayer(attacker);
if (multiplier == null) {
return;
}

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityRegainHealthEvent;
@@ -24,7 +23,7 @@ public class RegenerationMultiplier extends Effect<Double> {
Player player = (Player) event.getEntity();
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;

View File

@@ -0,0 +1,39 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SpeedMultiplier extends Effect<Double> {
public SpeedMultiplier() {
super("speed-multiplier", Double.class);
}
@Override
protected void onEnable(@NotNull final Player player) {
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
assert movementSpeed != null;
Double strength = this.getStrengthForPlayer(player);
if (strength == null) {
return;
}
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", strength - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
if (movementSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) {
movementSpeed.addModifier(modifier);
}
}
@Override
protected void onDisable(@NotNull final Player player) {
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
assert movementSpeed != null;
movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
}
}

View File

@@ -1,37 +0,0 @@
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 SpeedMutiplier extends Effect<Double> {
public SpeedMutiplier() {
super("speed-multiplier", Double.class);
}
@EventHandler
public void listener(@NotNull final ArmorEquipEvent event) {
Player player = event.getPlayer();
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
assert movementSpeed != null;
this.getPlugin().getScheduler().runLater(() -> {
Double multiplier = ArmorUtils.getEffectStrength(player, this);
if (multiplier == null) {
movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
} else {
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", multiplier - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
if (!movementSpeed.getModifiers().contains(modifier)) {
movementSpeed.addModifier(modifier);
}
}
}, 1);
}
}

View File

@@ -1,7 +1,6 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Trident;
@@ -33,7 +32,8 @@ public class TridentDamageMultiplier extends Effect<Double> {
Player player = (Player) shooter;
Double multiplier = ArmorUtils.getEffectStrength(player, this);
Double multiplier = this.getStrengthForPlayer(player);
if (multiplier == null) {
return;
}

View File

@@ -2,7 +2,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.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
@@ -34,11 +33,7 @@ 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);
Double chance = this.getStrengthForPlayer(player);
if (chance == null) {
return;

View File

@@ -0,0 +1,70 @@
package com.willfp.ecoarmor.effects.util;
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.effects.Effects;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class EffectWatcher extends PluginDependent implements Listener {
/**
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
*
* @param plugin The plugin to manage.
*/
public EffectWatcher(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Listener for armor equipping.
*
* @param event The event to listen for.
*/
@EventHandler
public void armorEquipListener(@NotNull final ArmorEquipEvent event) {
Player player = event.getPlayer();
this.getPlugin().getScheduler().runLater(() -> {
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
for (Effect<?> effect : Effects.values()) {
boolean enabled = true;
if (set == null) {
effect.disable(player);
continue;
}
Object strength = set.getEffectStrength(effect);
if (ArmorUtils.isWearingAdvanced(player)) {
Object advancedStrength = set.getAdvancedEffectStrength(effect);
if (advancedStrength != null) {
strength = advancedStrength;
}
}
if (strength == null) {
enabled = false;
}
if (!ArmorUtils.areConditionsMet(player)) {
enabled = false;
}
if (enabled) {
effect.enable(player, strength);
} else {
effect.disable(player);
}
}
}, 1);
}
}

View File

@@ -8,6 +8,8 @@ import com.willfp.eco.util.recipe.RecipeParts;
import com.willfp.eco.util.recipe.parts.ComplexRecipePart;
import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.conditions.Conditions;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.effects.Effects;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
@@ -55,6 +57,12 @@ public class ArmorSet {
@Getter(AccessLevel.PRIVATE)
private final AbstractUndefinedConfig config;
/**
* Conditions and their values.
*/
@Getter
private final Map<Condition<?>, Object> conditions = new HashMap<>();
/**
* Effects and their strengths.
*/
@@ -115,6 +123,14 @@ public class ArmorSet {
this.config = config;
this.name = name;
for (String definedKey : this.getConfig().getStrings("conditions")) {
String[] split = definedKey.split(":");
String key = split[0].trim();
String value = split[1].trim();
Condition<?> condition = Conditions.getByName(key);
conditions.put(condition, ArmorUtils.getConditionValue(value, condition));
}
for (String definedKey : this.getConfig().getStrings("set-bonus")) {
String[] split = definedKey.split(":");
String key = split[0].trim();
@@ -324,6 +340,18 @@ public class ArmorSet {
return advancedItems.get(slot);
}
/**
* Get condition value of effect.
*
* @param condition The condition to query.
* @param <T> The type of the condition value.
* @return The value.
*/
@Nullable
public <T> T getConditionValue(@NotNull final Condition<T> condition) {
return (T) conditions.get(condition);
}
/**
* Get effect strength of effect.
*

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoarmor.sets.util;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.conditions.Condition;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.ArmorSets;
@@ -20,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@UtilityClass
@@ -97,40 +99,24 @@ public class ArmorUtils {
}
/**
* Get the strength of an effect on a player's set.
* Get if all conditions are met for a player.
*
* @param player The player to test.
* @param effect The effect to test.
* @param <T> Effect type.
* @return The strength, or null if not found.
* @param player The player.
* @return If conditions are men.
*/
@Nullable
public <T> T getEffectStrength(@NotNull final Player player,
@NotNull final Effect<T> effect) {
public boolean areConditionsMet(@NotNull final Player player) {
ArmorSet set = getSetOnPlayer(player);
if (set == null) {
return null;
return true;
}
T strength = set.getEffectStrength(effect);
if (isWearingAdvanced(player)) {
strength = set.getAdvancedEffectStrength(effect);
for (Map.Entry<Condition<?>, Object> entry : set.getConditions().entrySet()) {
if (!entry.getKey().isMet(player, entry.getValue())) {
return false;
}
}
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;
return true;
}
/**
@@ -184,7 +170,7 @@ public class ArmorUtils {
* Set tier on item.
*
* @param itemStack The item to check.
* @param tier The tier to set.
* @param tier The tier to set.
*/
public static void setTier(@NotNull final ItemStack itemStack,
@NotNull final Tier tier) {
@@ -382,4 +368,30 @@ public class ArmorUtils {
return string;
}
/**
* Get value of condition.
*
* @param string Value as string.
* @param condition Condition.
* @param <T> The type of the condition.
* @return Value.
*/
@NotNull
public static <T> Object getConditionValue(@NotNull final String string,
@NotNull final Condition<T> condition) {
if (condition.getTypeClass().equals(Boolean.class)) {
return Boolean.parseBoolean(string);
}
if (condition.getTypeClass().equals(Integer.class)) {
return Integer.parseInt(string);
}
if (condition.getTypeClass().equals(Double.class)) {
return Double.parseDouble(string);
}
return string;
}
}

View File

@@ -1,4 +1,5 @@
enabled: true
conditions: []
set-bonus:
- "warp-chance: 20"
- "evade-chance: 10"

View File

@@ -1,4 +1,5 @@
enabled: true
conditions: []
set-bonus:
- "experience-multiplier: 1.25"
advanced-set-bonus:

View File

@@ -1,4 +1,5 @@
enabled: true
conditions: []
set-bonus:
- "damage-multiplier: 1.25"
advanced-set-bonus:

View File

@@ -1,4 +1,6 @@
enabled: true
conditions:
- "above-health-percent: 50"
set-bonus:
- "speed-multiplier: 1.25"
advanced-set-bonus:
@@ -10,7 +12,7 @@ advanced-lore:
- "<GRADIENT:f12711>&lADVANCED BONUS</GRADIENT:f5af19>"
- "&8» &bPermanent Jump Boost II"
- "&8» &bMove 50% faster"
- "&8&oRequires full set to be worn"
- "&8&oRequires full set to be worn above 50% health"
advancement-shard-name: "<GRADIENT:f12711>Advancement Shard:</GRADIENT:f5af19> &bYoung"
advancement-shard-lore:
- "&8Drop this onto &bYoung Armor"
@@ -43,7 +45,7 @@ helmet:
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- "&8&oRequires full set to be worn above 50% health"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
@@ -74,7 +76,7 @@ chestplate:
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- "&8&oRequires full set to be worn above 50% health"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
@@ -103,7 +105,7 @@ elytra:
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- "&8&oRequires full set to be worn above 50% health"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
@@ -134,7 +136,7 @@ leggings:
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- "&8&oRequires full set to be worn above 50% health"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"
@@ -166,7 +168,7 @@ boots:
lore:
- "&b&lYOUNG SET BONUS"
- "&8» &bMove 25% faster"
- "&8&oRequires full set to be worn"
- "&8&oRequires full set to be worn above 50% health"
- ""
- "&fTier: %tier%"
- "&8&oUpgrade with an Upgrade Crystal"