Implement configurable hunger penalty for capitator axe

This commit is contained in:
Gabriel Tofvesson 2021-07-03 03:08:36 +02:00
parent a3f0fcf5aa
commit 353f97a5e8
3 changed files with 14 additions and 3 deletions

View File

@ -9,4 +9,5 @@ search:
searchRadiusY: 8
searchRadiusZ: 8
ghostClick: true
capitator: true
capitator: true
capitatorHungerPerBlock: 0.03125

View File

@ -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);
}

View File

@ -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);
}
}