mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-27 10:59:22 +00:00
Added is-sneaking condition
This commit is contained in:
@@ -15,6 +15,7 @@ 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;
|
||||
|
||||
@@ -40,6 +41,7 @@ public class Conditions {
|
||||
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
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user