1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2020-09-21 13:23:14 +02:00
parent 9dfd43fda6
commit 5cd1d99b70
2 changed files with 40 additions and 12 deletions

View File

@ -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

View File

@ -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<ItemUseHandler> {
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<ItemUseHandler> {
};
}
@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<ItemUseHandler> {
}
}
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<String> 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<String> lore = meta.getLore();
lore.set(4, ChatColors.color("&e" + usesLeft + ' ' + (usesLeft > 1 ? "Uses" : "Use") + " &7left"));
meta.setLore(lore);
item.setItemMeta(meta);
}
}
}