mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-29 03:49:16 +00:00
Added above hunger and below hunger percent conditions
This commit is contained in:
@@ -4,9 +4,11 @@ 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.ConditionInWater;
|
||||
@@ -32,6 +34,8 @@ public class Conditions {
|
||||
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();
|
||||
|
||||
/**
|
||||
* Get condition matching name.s
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user