mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-28 11:29:18 +00:00
Added more conditions
This commit is contained in:
@@ -3,7 +3,14 @@ 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;
|
||||
|
||||
@@ -18,9 +25,16 @@ public class Conditions {
|
||||
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.
|
||||
* Get condition matching name.s
|
||||
*
|
||||
* @param name The name to query.
|
||||
* @return The matching condition, or null if not found.
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
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.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
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -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.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionAboveXPLevel extends Condition<Integer> {
|
||||
public ConditionAboveXPLevel() {
|
||||
super("above-xp-level", Integer.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Integer value) {
|
||||
return player.getLevel() >= value;
|
||||
}
|
||||
}
|
||||
@@ -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.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionAboveY extends Condition<Double> {
|
||||
public ConditionAboveY() {
|
||||
super("above-y", Double.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Double value) {
|
||||
return player.getLocation().getY() >= value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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.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
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -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.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionBelowXPLevel extends Condition<Integer> {
|
||||
public ConditionBelowXPLevel() {
|
||||
super("below-xp-level", Integer.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Integer value) {
|
||||
return player.getLevel() < value;
|
||||
}
|
||||
}
|
||||
@@ -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.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionInWater extends Condition<Boolean> {
|
||||
public ConditionInWater() {
|
||||
super("in-water", Boolean.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(@NotNull final Player player,
|
||||
@NotNull final Boolean value) {
|
||||
return (player.getLocation().getBlock().getType() == Material.WATER) == value;
|
||||
}
|
||||
}
|
||||
@@ -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.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
|
||||
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;
|
||||
}
|
||||
|
||||
if (isMet(player, value)) {
|
||||
set.getEffects().keySet().forEach(effect -> effect.enable(player, value));
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
}
|
||||
}
|
||||
|
||||
@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,6 +1,6 @@
|
||||
enabled: true
|
||||
conditions:
|
||||
- "below-y: 40"
|
||||
- "above-health-percent: 50"
|
||||
set-bonus:
|
||||
- "speed-multiplier: 1.25"
|
||||
advanced-set-bonus:
|
||||
|
||||
Reference in New Issue
Block a user