From 9e92f6422258b7c1efc2ad74cffde612c3762f89 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 24 Aug 2020 20:35:35 +0200 Subject: [PATCH] Added damageable setting --- .../items/tools/ClimbingPick.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java index c4ae4ce1f..76915c11b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java @@ -50,12 +50,13 @@ public class ClimbingPick extends SimpleSlimefunItem implements private static final double BASE_POWER = 0.9; private final ItemSetting dualWielding = new ItemSetting<>("dual-wielding", true); + private final ItemSetting damageOnUse = new ItemSetting<>("damage-on-use", true); private final Map materialSpeeds; private final Set users = new HashSet<>(); public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); - addItemSetting(dualWielding); + addItemSetting(dualWielding, damageOnUse); String cfgKey = getID() + ".launch-amounts."; Config itemCfg = SlimefunPlugin.getItemCfg(); @@ -101,23 +102,22 @@ public class ClimbingPick extends SimpleSlimefunItem implements Player p = e.getPlayer(); // Check if the Player is standing close to the wall - if (p.getLocation().distanceSquared(block.getLocation().add(0.5, 0.5, 0.5)) > 3.5) { + if (p.getLocation().distanceSquared(block.getLocation().add(0.5, 0.5, 0.5)) > 4) { return; } + // Check for dual wielding if (isDualWieldingEnabled() && !isItem(getOtherHandItem(p, e.getHand()))) { SlimefunPlugin.getLocalization().sendMessage(p, "messages.climbing-pick.dual-wielding"); return; } + // Top and bottom faces won't be allowed if (e.getClickedFace() == BlockFace.DOWN || e.getClickedFace() == BlockFace.UP) { return; } - // Prevent players from spamming this - if (users.add(p.getUniqueId())) { - climb(p, e.getHand(), e.getItem(), block); - } + climb(p, e.getHand(), e.getItem(), block); }; } @@ -133,24 +133,25 @@ public class ClimbingPick extends SimpleSlimefunItem implements private void climb(Player p, EquipmentSlot hand, ItemStack item, Block block) { double power = materialSpeeds.getOrDefault(block.getType(), 0.0); - Vector velocity = new Vector(0, 0, 0); if (power > 0.05) { - int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED); + // Prevent players from spamming this + if (users.add(p.getUniqueId())) { + int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED); - if (efficiencyLevel != 0) { - power += efficiencyLevel * 0.1; - } + if (efficiencyLevel != 0) { + power += efficiencyLevel * 0.1; + } - velocity.setY(power * BASE_POWER); + Vector velocity = new Vector(0, power * BASE_POWER, 0); + ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block); + Bukkit.getPluginManager().callEvent(event); - ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - Slimefun.runSync(() -> users.remove(p.getUniqueId()), 3L); - p.setVelocity(event.getVelocity()); - p.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); - swing(p, hand, item); + if (!event.isCancelled()) { + Slimefun.runSync(() -> users.remove(p.getUniqueId()), 3L); + p.setVelocity(event.getVelocity()); + p.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); + swing(p, hand, item); + } } } else { @@ -190,7 +191,7 @@ public class ClimbingPick extends SimpleSlimefunItem implements @Override public boolean isDamageable() { - return true; + return damageOnUse.getValue(); } @Override