diff --git a/CHANGELOG.md b/CHANGELOG.md index a0855ad0a..53851bfbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ * Fixed some issues with ChestTerminal * Fixed #2325 * Fixed Climbing Pick having no animation in creative mode +* Fixed #2322 ## Release Candidate 16 (07 Sep 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java index 8e14f1ed1..5c72e5ceb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java @@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical; import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -40,10 +43,12 @@ public class StormStaff extends SimpleSlimefunItem { private static final NamespacedKey usageKey = new NamespacedKey(SlimefunPlugin.instance(), "stormstaff_usage"); public static final int MAX_USES = 8; + @ParametersAreNonnullByDefault public StormStaff(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe, getCraftedOutput()); } + @Nonnull private static ItemStack getCraftedOutput() { ItemStack item = SlimefunItems.STAFF_STORM.clone(); ItemMeta im = item.getItemMeta(); @@ -82,10 +87,11 @@ public class StormStaff extends SimpleSlimefunItem { }; } + @ParametersAreNonnullByDefault private void useItem(Player p, ItemStack item, Location loc) { loc.getWorld().strikeLightning(loc); - if (p.getInventory().getItemInMainHand().getType() == Material.SHEARS) { + if (item.getType() == Material.SHEARS) { return; } @@ -98,22 +104,43 @@ public class StormStaff extends SimpleSlimefunItem { } } - ItemMeta meta = item.getItemMeta(); - int usesLeft = meta.getPersistentDataContainer().getOrDefault(usageKey, PersistentDataType.INTEGER, MAX_USES); + damageItem(p, item); + } - if (usesLeft == 1) { - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1); - item.setAmount(0); + @ParametersAreNonnullByDefault + private void damageItem(Player p, ItemStack item) { + if (item.getAmount() > 1) { + item.setAmount(item.getAmount() - 1); + + // Seperate one item from the stack and damage it + ItemStack seperateItem = item.clone(); + seperateItem.setAmount(1); + damageItem(p, seperateItem); + + // Try to give the Player the new item + if (!p.getInventory().addItem(seperateItem).isEmpty()) { + // or throw it on the ground + p.getWorld().dropItemNaturally(p.getLocation(), seperateItem); + } } else { - usesLeft--; - meta.getPersistentDataContainer().set(usageKey, PersistentDataType.INTEGER, usesLeft); + ItemMeta meta = item.getItemMeta(); + int usesLeft = meta.getPersistentDataContainer().getOrDefault(usageKey, PersistentDataType.INTEGER, MAX_USES); - List lore = meta.getLore(); - lore.set(4, ChatColors.color("&e" + usesLeft + ' ' + (usesLeft > 1 ? "Uses" : "Use") + " &7left")); - meta.setLore(lore); + if (usesLeft == 1) { + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1); + item.setAmount(0); + } + else { + usesLeft--; + meta.getPersistentDataContainer().set(usageKey, PersistentDataType.INTEGER, usesLeft); - item.setItemMeta(meta); + List lore = meta.getLore(); + lore.set(4, ChatColors.color("&e" + usesLeft + ' ' + (usesLeft > 1 ? "Uses" : "Use") + " &7left")); + meta.setLore(lore); + + item.setItemMeta(meta); + } } }