From 8acef93d7d54e1f30d00d33f7cb6b0e92b8412bf Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sat, 3 Jul 2021 03:22:14 +0200 Subject: [PATCH] Implement minimum food level option for capitator functionality --- res/config.yml | 3 ++- src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java | 3 ++- .../invtweaks/listener/TreeCapitatorListener.java | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/res/config.yml b/res/config.yml index 11a3a21..8ae6162 100644 --- a/res/config.yml +++ b/res/config.yml @@ -10,4 +10,5 @@ search: searchRadiusZ: 8 ghostClick: true capitator: true -capitatorHungerPerBlock: 0.03125 \ No newline at end of file +capitatorHungerPerBlock: 0.03125 +capitatorMinHunger: 3 \ No newline at end of file diff --git a/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java b/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java index 8d58266..4c600e6 100644 --- a/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java +++ b/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java @@ -123,7 +123,8 @@ public final class InvTweaksPlugin extends JavaPlugin { pluginManager.registerEvents(new TabCompletionListener(), this); pluginManager.registerEvents(new TreeCapitatorListener( activateCapitator ? capitatorEnchantment.getEnchantment() : null, - getConfig().getDouble("capitatorHungerPerBlock") + getConfig().getDouble("capitatorHungerPerBlock"), + getConfig().getInt("capitatorMinHunger") ), this); pluginManager.registerEvents(new PlayerMoveRenderListener(chestManager), this); pluginManager.registerEvents(new ChestBreakListener(chestManager), this); diff --git a/src/dev/w1zzrd/invtweaks/listener/TreeCapitatorListener.java b/src/dev/w1zzrd/invtweaks/listener/TreeCapitatorListener.java index a036a55..b223e8d 100644 --- a/src/dev/w1zzrd/invtweaks/listener/TreeCapitatorListener.java +++ b/src/dev/w1zzrd/invtweaks/listener/TreeCapitatorListener.java @@ -15,6 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.*; +import static dev.w1zzrd.spigot.wizcompat.command.CommandUtils.errorMessage; import static org.bukkit.Material.*; public class TreeCapitatorListener implements Listener { @@ -47,10 +48,12 @@ public class TreeCapitatorListener implements Listener { private final Enchantment capitatorEnchantment; private final double hungerPerBlock; + private final int minHunger; - public TreeCapitatorListener(final Enchantment capitatorEnchantment, final double hungerPerBlock) { + public TreeCapitatorListener(final Enchantment capitatorEnchantment, final double hungerPerBlock, final int minHunger) { this.capitatorEnchantment = capitatorEnchantment; this.hungerPerBlock = hungerPerBlock; + this.minHunger = minHunger; } @EventHandler @@ -59,6 +62,12 @@ public class TreeCapitatorListener implements Listener { if (event.isCancelled() || !handTool.containsEnchantment(capitatorEnchantment)) return; + // Check if capitator functionality is prevented by hunger + if (event.getPlayer().getFoodLevel() < minHunger) { + event.getPlayer().spigot().sendMessage(errorMessage("You are too tired to fell the tree")); + return; + } + if (handTool.getItemMeta() instanceof final Damageable tool) { if (!leaves.contains(event.getBlock().getType()) && targetMaterials.contains(event.getBlock().getType())) { int logBreakCount = 0;