mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-28 03:19:25 +00:00
Began libreforge change
This commit is contained in:
11
build.gradle
11
build.gradle
@@ -45,10 +45,15 @@ allprojects {
|
||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:6.8.1'
|
||||
shadowJar {
|
||||
relocate('com.willfp.libreforge', 'com.willfp.ecoarmor.libreforge')
|
||||
}
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:6.13.10'
|
||||
compileOnly 'com.willfp:libreforge:0.1.2'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.20'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
|
||||
@@ -3,14 +3,10 @@ package com.willfp.ecoarmor;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.ecoarmor.commands.CommandEcoarmor;
|
||||
import com.willfp.ecoarmor.conditions.Conditions;
|
||||
import com.willfp.ecoarmor.conditions.util.MovementConditionListener;
|
||||
import com.willfp.ecoarmor.config.EcoArmorJson;
|
||||
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.PreventSkullPlaceListener;
|
||||
@@ -18,6 +14,7 @@ import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener;
|
||||
import com.willfp.ecoarmor.upgrades.listeners.CrystalListener;
|
||||
import com.willfp.ecoarmor.util.DiscoverRecipeListener;
|
||||
import com.willfp.libreforge.api.LibReforge;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -47,21 +44,19 @@ public class EcoArmorPlugin extends EcoPlugin {
|
||||
instance = this;
|
||||
|
||||
this.ecoArmorJson = new EcoArmorJson(this);
|
||||
|
||||
LibReforge.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleEnable() {
|
||||
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
|
||||
Conditions.values().forEach(condition -> this.getEventManager().registerListener(condition));
|
||||
LibReforge.enable(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleReload() {
|
||||
Effects.values().forEach(effect -> this.getEventManager().unregisterListener(effect));
|
||||
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
|
||||
this.getLogger().info(Tiers.values().size() + " Tiers Loaded");
|
||||
this.getLogger().info(ArmorSets.values().size() + " Sets Loaded");
|
||||
this.getScheduler().runTimer((Runnable) Conditions.HAS_PERMISSION, 100, 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,12 +73,15 @@ public class EcoArmorPlugin extends EcoPlugin {
|
||||
new AdvancementShardListener(this),
|
||||
new EffectiveDurabilityListener(this),
|
||||
new DiscoverRecipeListener(this),
|
||||
new EffectWatcher(this),
|
||||
new MovementConditionListener(this),
|
||||
new PreventSkullPlaceListener()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IntegrationLoader> loadIntegrationLoaders() {
|
||||
return LibReforge.getIntegrationLoaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable DisplayModule createDisplayModule() {
|
||||
return new ArmorDisplay(this);
|
||||
|
||||
@@ -7,10 +7,10 @@ import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.web.Paste;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
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.libreforge.api.conditions.Condition;
|
||||
import com.willfp.libreforge.api.conditions.Conditions;
|
||||
import com.willfp.libreforge.api.effects.Effect;
|
||||
import com.willfp.libreforge.api.effects.Effects;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@@ -44,10 +44,10 @@ public class CommandEditor extends Subcommand {
|
||||
List<String> potionEffects = Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName).collect(Collectors.toList());
|
||||
meta.put("potion-effects", potionEffects);
|
||||
|
||||
List<String> effects = Effects.values().stream().map(Effect::getName).collect(Collectors.toList());
|
||||
List<String> effects = Effects.INSTANCE.values().stream().map(Effect::getId).collect(Collectors.toList());
|
||||
meta.put("effects", effects);
|
||||
|
||||
List<String> conditions = Conditions.values().stream().map(Condition::getName).collect(Collectors.toList());
|
||||
List<String> conditions = Conditions.INSTANCE.values().stream().map(Condition::getId).collect(Collectors.toList());
|
||||
meta.put("conditions", conditions);
|
||||
|
||||
config.set("meta", meta);
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
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.bukkit.potion.PotionEffect;
|
||||
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);
|
||||
|
||||
public final void evaluateEffects(@NotNull final Player player,
|
||||
@NotNull final Object 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);
|
||||
}
|
||||
}
|
||||
|
||||
set.getPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true));
|
||||
});
|
||||
|
||||
if (ArmorUtils.isWearingAdvanced(player)) {
|
||||
set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getDuration() >= 0x5ffffff && effect.getDuration() <= 0x6ffffff) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
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.ConditionAboveHungerPercent;
|
||||
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.ConditionBelowHungerPercent;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionBelowXPLevel;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionHasPermission;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionInBiome;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionInWater;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionInWorld;
|
||||
import com.willfp.ecoarmor.conditions.conditions.ConditionIsSneaking;
|
||||
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();
|
||||
public static final Condition<?> ABOVE_HUNGER_PERCENT = new ConditionAboveHungerPercent();
|
||||
public static final Condition<?> BELOW_HUNGER_PERCENT = new ConditionBelowHungerPercent();
|
||||
public static final Condition<?> IN_BIOME = new ConditionInBiome();
|
||||
public static final Condition<?> HAS_PERMISSION = new ConditionHasPermission();
|
||||
public static final Condition<?> IS_SNEAKING = new ConditionIsSneaking();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
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.entity.FoodLevelChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionAboveHungerPercent extends Condition<Double> {
|
||||
public ConditionAboveHungerPercent() {
|
||||
super("above-hunger-percent", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.MONITOR,
|
||||
ignoreCancelled = true
|
||||
)
|
||||
public void listener(@NotNull final FoodLevelChangeEvent event) {
|
||||
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 maxFood = 20;
|
||||
double food = player.getFoodLevel();
|
||||
|
||||
return (food / maxFood) * 100 >= value;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Double value) {
|
||||
return player.getLocation().getY() >= value;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
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.entity.FoodLevelChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionBelowHungerPercent extends Condition<Double> {
|
||||
public ConditionBelowHungerPercent() {
|
||||
super("below-hunger-percent", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.MONITOR,
|
||||
ignoreCancelled = true
|
||||
)
|
||||
public void listener(@NotNull final FoodLevelChangeEvent event) {
|
||||
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 maxFood = 20;
|
||||
double food = player.getFoodLevel();
|
||||
|
||||
return (food / maxFood) * 100 < value;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Double value) {
|
||||
return player.getLocation().getY() < value;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionHasPermission extends Condition<String> implements Runnable {
|
||||
public ConditionHasPermission() {
|
||||
super("has-permission", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
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) {
|
||||
return player.hasPermission(value);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
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.block.Biome;
|
||||
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 ConditionInBiome extends Condition<String> {
|
||||
public ConditionInBiome() {
|
||||
super("in-biome", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final String value) {
|
||||
List<String> biomeNames = Arrays.asList(value.toLowerCase().split(" "));
|
||||
Biome biome = player.getLocation().getWorld().getBiome(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
return biomeNames.contains(biome.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Boolean value) {
|
||||
return (player.getLocation().getBlock().getType() == Material.WATER) == value;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
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.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionIsSneaking extends Condition<Boolean> {
|
||||
public ConditionIsSneaking() {
|
||||
super("is-sneaking", Boolean.class);
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.MONITOR,
|
||||
ignoreCancelled = true
|
||||
)
|
||||
public void listener(@NotNull final PlayerToggleSneakEvent 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.isSneaking();
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.willfp.ecoarmor.conditions.util;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import com.willfp.ecoarmor.conditions.Condition;
|
||||
import com.willfp.ecoarmor.conditions.Conditions;
|
||||
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.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementConditionListener extends PluginDependent<EcoArmorPlugin> implements Listener {
|
||||
/**
|
||||
* Pass an {@link EcoArmorPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public MovementConditionListener(@NotNull EcoArmorPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
private static final Set<Condition<?>> CONDITIONS = ImmutableSet.of(
|
||||
Conditions.ABOVE_Y,
|
||||
Conditions.IN_BIOME,
|
||||
Conditions.BELOW_Y,
|
||||
Conditions.IN_WATER,
|
||||
Conditions.IN_WORLD
|
||||
);
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
for (Condition<?> condition : CONDITIONS) {
|
||||
Object value = set.getConditionValue(condition);
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
condition.evaluateEffects(player, value, set);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
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.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class Effect<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;
|
||||
|
||||
/**
|
||||
* UUID of the effect, used in attribute modifiers.
|
||||
*/
|
||||
@Getter
|
||||
private final UUID uuid;
|
||||
|
||||
/**
|
||||
* If the effect is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* The class of the config getter type.
|
||||
*/
|
||||
@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.
|
||||
*
|
||||
* @param name The effect name.
|
||||
* @param typeClass The class of the config type.
|
||||
*/
|
||||
protected Effect(@NotNull final String name,
|
||||
@NotNull final Class<T> typeClass) {
|
||||
this.name = name;
|
||||
this.typeClass = typeClass;
|
||||
this.uuid = UUID.nameUUIDFromBytes(name.getBytes());
|
||||
|
||||
update();
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply effect if enabled for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param consumer The effect function.
|
||||
*/
|
||||
public void applyIfEnabled(@NotNull final Player player,
|
||||
@NotNull final Consumer<T> consumer) {
|
||||
T strength = getStrengthForPlayer(player);
|
||||
if (strength == null) {
|
||||
return;
|
||||
} else {
|
||||
consumer.accept(strength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
Object val;
|
||||
|
||||
if (value instanceof Double && typeClass.equals(Integer.class)) {
|
||||
val = (int) Math.round((double) value);
|
||||
} else {
|
||||
val = value;
|
||||
}
|
||||
|
||||
enabledPlayers.put(player.getUniqueId(), typeClass.cast(val));
|
||||
|
||||
this.onEnable(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the effect for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
public final void disable(@NotNull final Player player) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
public void update() {
|
||||
enabled = this.getPlugin().getConfigYml().getBool("effects." + name + ".enabled");
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.ecoarmor.effects.effects.AttackSpeedMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.BonusHearts;
|
||||
import com.willfp.ecoarmor.effects.effects.BossDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.BowDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.DamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.DamageTakenMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.EvadeChance;
|
||||
import com.willfp.ecoarmor.effects.effects.ExperienceMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.FallDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.Flight;
|
||||
import com.willfp.ecoarmor.effects.effects.HungerLossMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.KnockbackMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.SpeedMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.Telekinesis;
|
||||
import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.WarpChance;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("unused")
|
||||
public class Effects {
|
||||
/**
|
||||
* All registered effects.
|
||||
*/
|
||||
private static final BiMap<String, Effect<?>> BY_NAME = HashBiMap.create();
|
||||
|
||||
public static final Effect<?> BOW_DAMAGE_MULTIPLIER = new BowDamageMultiplier();
|
||||
public static final Effect<?> DAMAGE_MULTIPLIER = new DamageMultiplier();
|
||||
public static final Effect<?> DAMAGE_TAKEN_MULTIPLIER = new DamageTakenMultiplier();
|
||||
public static final Effect<?> EVADE_CHANCE = new EvadeChance();
|
||||
public static final Effect<?> FALL_DAMAGE_MULTIPLIER = new FallDamageMultiplier();
|
||||
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 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();
|
||||
public static final Effect<?> ATTACK_SPEED_MULTIPLIER = new AttackSpeedMultiplier();
|
||||
public static final Effect<?> FLIGHT = new Flight();
|
||||
public static final Effect<?> HUNGER_LOSS_MULTIPLIER = new HungerLossMultiplier();
|
||||
public static final Effect<?> BOSS_DAMAGE_MULTIPLIER = new BossDamageMultiplier();
|
||||
public static final Effect<?> KNOCKBACK_MULTIPLIER = new KnockbackMultiplier();
|
||||
public static final Effect<?> TELEKINESIS = new Telekinesis();
|
||||
|
||||
/**
|
||||
* Get effect matching name.
|
||||
*
|
||||
* @param name The name to query.
|
||||
* @return The matching effect, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static Effect<?> getByName(@NotNull final String name) {
|
||||
return BY_NAME.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of all registered effects.
|
||||
*
|
||||
* @return The effects.
|
||||
*/
|
||||
public static List<Effect<?>> values() {
|
||||
return ImmutableList.copyOf(BY_NAME.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new effect to EcoArmor.
|
||||
*
|
||||
* @param effect The effect to add.
|
||||
*/
|
||||
public static void addNewEffect(@NotNull final Effect<?> effect) {
|
||||
BY_NAME.remove(effect.getName());
|
||||
BY_NAME.put(effect.getName(), effect);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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 AttackSpeedMultiplier extends Effect<Double> {
|
||||
public AttackSpeedMultiplier() {
|
||||
super("attack-speed-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
AttributeInstance attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
assert attackSpeed != null;
|
||||
|
||||
Double multiplier = this.getStrengthForPlayer(player);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
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 BonusHearts extends Effect<Integer> {
|
||||
public BonusHearts() {
|
||||
super("bonus-hearts", Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
assert maxHealth != null;
|
||||
|
||||
Integer bonus = this.getStrengthForPlayer(player);
|
||||
|
||||
if (bonus == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bonus *= 2;
|
||||
|
||||
if (player.getHealth() >= maxHealth.getValue()) {
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
}, 1);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Boss;
|
||||
import org.bukkit.entity.ElderGuardian;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BossDamageMultiplier extends Effect<Double> {
|
||||
public BossDamageMultiplier() {
|
||||
super("boss-damage-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity victim = event.getEntity();
|
||||
|
||||
if (!(victim instanceof Boss || victim instanceof ElderGuardian) && !victim.getPersistentDataContainer().has(new NamespacedKey("ecobosses", "boss"), PersistentDataType.STRING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = null;
|
||||
if (event.getDamager() instanceof Projectile) {
|
||||
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
|
||||
if (shooter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shooter instanceof Player) {
|
||||
attacker = (Player) shooter;
|
||||
}
|
||||
} else if (event.getDamager() instanceof Player) {
|
||||
attacker = (Player) event.getDamager();
|
||||
}
|
||||
|
||||
if (attacker == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.applyIfEnabled(attacker, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BowDamageMultiplier extends Effect<Double> {
|
||||
public BowDamageMultiplier() {
|
||||
super("bow-damage-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
|
||||
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) shooter;
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DamageMultiplier extends Effect<Double> {
|
||||
public DamageMultiplier() {
|
||||
super("damage-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = null;
|
||||
if (event.getDamager() instanceof Projectile) {
|
||||
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
|
||||
if (shooter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shooter instanceof Player) {
|
||||
attacker = (Player) shooter;
|
||||
}
|
||||
} else if (event.getDamager() instanceof Player) {
|
||||
attacker = (Player) event.getDamager();
|
||||
}
|
||||
|
||||
if (attacker == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.applyIfEnabled(attacker, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DamageTakenMultiplier extends Effect<Double> {
|
||||
public DamageTakenMultiplier() {
|
||||
super("damage-taken-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DurabilityMultiplier extends Effect<Double> {
|
||||
public DurabilityMultiplier() {
|
||||
super("durability-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final PlayerItemDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> {
|
||||
if (NumberUtils.randFloat(0, 100) < 1 - (1 / multiplier)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EvadeChance extends Effect<Double> {
|
||||
public EvadeChance() {
|
||||
super("evade-chance", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
this.applyIfEnabled(player, chance -> {
|
||||
if (NumberUtils.randFloat(0, 100) < chance) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.core.events.NaturalExpGainEvent;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExperienceMultiplier extends Effect<Double> {
|
||||
public ExperienceMultiplier() {
|
||||
super("experience-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final NaturalExpGainEvent event) {
|
||||
Player player = event.getExpChangeEvent().getPlayer();
|
||||
|
||||
if (event.getExpChangeEvent().getAmount() < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> event.getExpChangeEvent().setAmount((int) Math.ceil(event.getExpChangeEvent().getAmount() * multiplier)));
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FallDamageMultiplier extends Effect<Double> {
|
||||
public FallDamageMultiplier() {
|
||||
super("fall-damage-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getCause() != EntityDamageEvent.DamageCause.FALL) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Flight extends Effect<Boolean> {
|
||||
public Flight() {
|
||||
super("flight", Boolean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable(@NotNull final Player player) {
|
||||
if (player.hasPermission("ecoarmor.noflydisable")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
player.setAllowFlight(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HungerLossMultiplier extends Effect<Double> {
|
||||
public HungerLossMultiplier() {
|
||||
super("hunger-loss-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final FoodLevelChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
Double multiplier = this.getStrengthForPlayer(player);
|
||||
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getFoodLevel() > player.getFoodLevel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (multiplier < 1) {
|
||||
if (NumberUtils.randFloat(0, 1) > multiplier) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
int difference = player.getFoodLevel() - event.getFoodLevel();
|
||||
difference = (int) Math.ceil(difference * multiplier);
|
||||
event.setFoodLevel(player.getFoodLevel() - difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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 KnockbackMultiplier extends Effect<Double> {
|
||||
public KnockbackMultiplier() {
|
||||
super("knockback-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable(@NotNull final Player player) {
|
||||
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_KNOCKBACK);
|
||||
assert movementSpeed != null;
|
||||
|
||||
Double strength = this.getStrengthForPlayer(player);
|
||||
|
||||
if (strength == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeModifier modifier = new AttributeModifier(this.getUuid(), "kb-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(), "kb-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MeleeDamageMultiplier extends Effect<Double> {
|
||||
public MeleeDamageMultiplier() {
|
||||
super("melee-damage-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
|
||||
this.applyIfEnabled(attacker, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RegenerationMultiplier extends Effect<Double> {
|
||||
public RegenerationMultiplier() {
|
||||
super("regeneration-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityRegainHealthEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> event.setAmount(event.getAmount() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.TelekinesisUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Telekinesis extends Effect<Boolean> {
|
||||
public Telekinesis() {
|
||||
super("telekinesis", Boolean.class);
|
||||
TelekinesisUtils.registerTest(player -> this.getStrengthForPlayer(player) != null);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TridentDamageMultiplier extends Effect<Double> {
|
||||
public TridentDamageMultiplier() {
|
||||
super("trident-damage-multiplier", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof Trident)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
|
||||
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) shooter;
|
||||
|
||||
this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier));
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WarpChance extends Effect<Double> {
|
||||
public WarpChance() {
|
||||
super("warp-chance", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getDamager();
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
Double chance = this.getStrengthForPlayer(player);
|
||||
|
||||
if (chance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NumberUtils.randFloat(0, 100) > chance) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector between = victim.getLocation().subtract(player.getLocation()).toVector();
|
||||
Location behind = victim.getLocation().add(between);
|
||||
|
||||
behind.setYaw(player.getLocation().getYaw() + 180);
|
||||
|
||||
Block head = behind.add(0, 1.4, 0).getBlock();
|
||||
|
||||
if (!head.getType().isAir()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.getLocation().setYaw(player.getLocation().getYaw() + 180);
|
||||
player.teleport(behind);
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.willfp.ecoarmor.effects.util;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
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.bukkit.potion.PotionEffect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EffectWatcher extends PluginDependent<EcoPlugin> implements Listener {
|
||||
/**
|
||||
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public EffectWatcher(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for armor equipping.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void armorEquipListener(@NotNull final ArmorChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
|
||||
|
||||
boolean conditionsMet = ArmorUtils.areConditionsMet(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 (!conditionsMet) {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
effect.enable(player, strength);
|
||||
} else {
|
||||
effect.disable(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (set == null || !conditionsMet) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getDuration() >= 0x5ffffff && effect.getDuration() <= 0x6ffffff) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set.getPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true));
|
||||
});
|
||||
|
||||
if (ArmorUtils.isWearingAdvanced(player)) {
|
||||
set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.items.CustomItem;
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import com.willfp.eco.core.items.builder.ItemBuilder;
|
||||
@@ -12,15 +11,17 @@ import com.willfp.eco.core.items.builder.ItemStackBuilder;
|
||||
import com.willfp.eco.core.items.builder.LeatherArmorBuilder;
|
||||
import com.willfp.eco.core.items.builder.SkullBuilder;
|
||||
import com.willfp.eco.core.recipe.Recipes;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
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;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import com.willfp.ecoarmor.upgrades.Tier;
|
||||
import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
import com.willfp.libreforge.api.conditions.Condition;
|
||||
import com.willfp.libreforge.api.conditions.Conditions;
|
||||
import com.willfp.libreforge.api.conditions.ConfiguredCondition;
|
||||
import com.willfp.libreforge.api.effects.ConfiguredEffect;
|
||||
import com.willfp.libreforge.api.effects.Effect;
|
||||
import com.willfp.libreforge.api.effects.Effects;
|
||||
import com.willfp.libreforge.api.provider.Holder;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -37,14 +38,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ArmorSet {
|
||||
/*
|
||||
TODO: Split off ArmorSet between two separate armorset objects (one advanced, one not)
|
||||
*/
|
||||
public class ArmorSet implements Holder {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
@@ -67,19 +71,19 @@ public class ArmorSet {
|
||||
* Conditions and their values.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<Condition<?>, Object> conditions = new HashMap<>();
|
||||
private final Set<ConfiguredCondition> conditions = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Effects and their strengths.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<Effect<?>, Object> effects = new HashMap<>();
|
||||
private final Set<ConfiguredEffect> effects = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Effects and their strengths on advanced armor.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<Effect<?>, Object> advancedEffects = new HashMap<>();
|
||||
private final Set<ConfiguredEffect> advancedEffects = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Potion effects to be applied on equip.
|
||||
@@ -131,21 +135,18 @@ public class ArmorSet {
|
||||
this.name = config.getString("name");
|
||||
|
||||
for (JSONConfig cfg : this.getConfig().getSubsections("conditions")) {
|
||||
Condition<?> effect = Conditions.getByName(cfg.getString("id"));
|
||||
Object value = cfg.get("args");
|
||||
conditions.put(effect, value);
|
||||
Condition effect = Conditions.INSTANCE.getByID(cfg.getString("id"));
|
||||
conditions.add(new ConfiguredCondition(effect, cfg.getSubsection("args")));
|
||||
}
|
||||
|
||||
for (JSONConfig cfg : this.getConfig().getSubsections("effects")) {
|
||||
Effect<?> effect = Effects.getByName(cfg.getString("id"));
|
||||
Object value = cfg.get("args");
|
||||
effects.put(effect, value);
|
||||
Effect effect = Effects.INSTANCE.getByID(cfg.getString("id"));
|
||||
effects.add(new ConfiguredEffect(effect, cfg.getSubsection("args")));
|
||||
}
|
||||
|
||||
for (JSONConfig cfg : this.getConfig().getSubsections("advancedEffects")) {
|
||||
Effect<?> effect = Effects.getByName(cfg.getString("id"));
|
||||
Object value = cfg.get("args");
|
||||
advancedEffects.put(effect, value);
|
||||
Effect effect = Effects.INSTANCE.getByID(cfg.getString("id"));
|
||||
advancedEffects.add(new ConfiguredEffect(effect, cfg.getSubsection("args")));
|
||||
}
|
||||
|
||||
for (JSONConfig cfg : this.getConfig().getSubsections("potionEffects")) {
|
||||
@@ -367,49 +368,6 @@ 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.
|
||||
*
|
||||
* @param effect The effect to query.
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get effect strength of effect on advanced armor.
|
||||
*
|
||||
* @param effect The effect to query.
|
||||
* @param <T> The type of the effect value.
|
||||
* @return The strength.
|
||||
*/
|
||||
@Nullable
|
||||
public <T> T getAdvancedEffectStrength(@NotNull final Effect<T> effect) {
|
||||
Object strength = advancedEffects.get(effect);
|
||||
if (strength instanceof Integer) {
|
||||
if (effect.getTypeClass().equals(Double.class)) {
|
||||
strength = (double) (int) strength;
|
||||
}
|
||||
}
|
||||
|
||||
return (T) strength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.willfp.ecoarmor.sets.util;
|
||||
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import com.willfp.ecoarmor.conditions.Condition;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
|
||||
import com.willfp.ecoarmor.upgrades.Tier;
|
||||
import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,7 +19,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
@@ -109,27 +106,6 @@ public class ArmorUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if all conditions are met for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If conditions are men.
|
||||
*/
|
||||
public boolean areConditionsMet(@NotNull final Player player) {
|
||||
ArmorSet set = getSetOnPlayer(player);
|
||||
if (set == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Map.Entry<Condition<?>, Object> entry : set.getConditions().entrySet()) {
|
||||
if (!entry.getKey().isMet(player, entry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tier on upgrade crystal.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user