From 353f97a5e881a1e529336c51e83196e4f22da59f Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sat, 3 Jul 2021 03:08:36 +0200 Subject: [PATCH] Implement configurable hunger penalty for capitator axe --- res/config.yml | 3 ++- src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java | 5 ++++- .../w1zzrd/invtweaks/listener/TreeCapitatorListener.java | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/res/config.yml b/res/config.yml index c1c1788..11a3a21 100644 --- a/res/config.yml +++ b/res/config.yml @@ -9,4 +9,5 @@ search: searchRadiusY: 8 searchRadiusZ: 8 ghostClick: true -capitator: true \ No newline at end of file +capitator: true +capitatorHungerPerBlock: 0.03125 \ No newline at end of file diff --git a/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java b/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java index d67039f..8d58266 100644 --- a/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java +++ b/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java @@ -121,7 +121,10 @@ public final class InvTweaksPlugin extends JavaPlugin { pluginManager.registerEvents(new SortListener(), this); pluginManager.registerEvents(new MagnetismListener(magnetCommandExecutor), this); pluginManager.registerEvents(new TabCompletionListener(), this); - pluginManager.registerEvents(new TreeCapitatorListener(activateCapitator ? capitatorEnchantment.getEnchantment() : null), this); + pluginManager.registerEvents(new TreeCapitatorListener( + activateCapitator ? capitatorEnchantment.getEnchantment() : null, + getConfig().getDouble("capitatorHungerPerBlock") + ), 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 038ca47..a036a55 100644 --- a/src/dev/w1zzrd/invtweaks/listener/TreeCapitatorListener.java +++ b/src/dev/w1zzrd/invtweaks/listener/TreeCapitatorListener.java @@ -46,9 +46,11 @@ public class TreeCapitatorListener implements Listener { ); private final Enchantment capitatorEnchantment; + private final double hungerPerBlock; - public TreeCapitatorListener(final Enchantment capitatorEnchantment) { + public TreeCapitatorListener(final Enchantment capitatorEnchantment, final double hungerPerBlock) { this.capitatorEnchantment = capitatorEnchantment; + this.hungerPerBlock = hungerPerBlock; } @EventHandler @@ -76,6 +78,11 @@ public class TreeCapitatorListener implements Listener { event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0f, 1.0f); } + if (event.getPlayer().getGameMode() == GameMode.ADVENTURE || event.getPlayer().getGameMode() == GameMode.SURVIVAL) { + final int hunger = (int) Math.round(hungerPerBlock * logBreakCount); + event.getPlayer().setFoodLevel(Math.max(0, event.getPlayer().getFoodLevel() - hunger)); + } + event.setCancelled(true); } }