mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Fix storm staff usage bug
Also improve the way it is done, there was no way to go through all possible usages checking the lore on each one... Downside: It will reset the usage on current items due to it being saved/loaded in a different way
This commit is contained in:
parent
75a2a9611d
commit
d3b13e62f5
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.StormStaff;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
@ -460,7 +461,9 @@ public final class SlimefunItems {
|
||||
public static final ItemStack STAFF_WIND = new CustomItem(Material.STICK, "&6Elemental Staff &7- &b&oWind", "", "&7Element: &b&oWind", "", "&eRight Click&7 to launch yourself forward");
|
||||
public static final ItemStack STAFF_FIRE = new CustomItem(Material.STICK, "&6Elemental Staff &7- &c&oFire", "", "&7Element: &c&oFire");
|
||||
public static final ItemStack STAFF_WATER = new CustomItem(Material.STICK, "&6Elemental Staff &7- &1&oWater", "", "&7Element: &1&oWater", "", "&eRight Click&7 to extinguish yourself");
|
||||
public static final ItemStack STAFF_STORM = new CustomItem(Material.STICK, "&6Elemental Staff &7- &8&oStorm", "", "&7Element: &8&oStorm", "", "&eRight Click&7 to summon a lightning", "&eX Uses &7left");
|
||||
public static final ItemStack STAFF_STORM = new CustomItem(Material.STICK, "&6Elemental Staff &7- &8&oStorm", "",
|
||||
"&7Element: &8&oStorm", "", "&eRight Click&7 to summon a lightning",
|
||||
"&e" + StormStaff.MAX_USES + " Uses &7left");
|
||||
|
||||
static {
|
||||
STAFF_WIND.addUnsafeEnchantment(Enchantment.LUCK, 1);
|
||||
|
@ -1,12 +1,14 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,10 +23,13 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
|
||||
import me.mrCookieSlime.Slimefun.Setup.Messages;
|
||||
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
|
||||
|
||||
private static final int MAX_USES = 8;
|
||||
public static final int MAX_USES = 8;
|
||||
|
||||
private static final NamespacedKey usageKey = new NamespacedKey(SlimefunPlugin.instance, "stormstaff_usage");
|
||||
|
||||
public StormStaff(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, id, recipeType, recipe, getCraftedOutput());
|
||||
@ -73,26 +78,23 @@ public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
|
||||
p.setFoodLevel(event.getFoodLevel());
|
||||
}
|
||||
|
||||
for (int i = MAX_USES; i > 0; i--) {
|
||||
if (i == 1 && ChatColor.translateAlternateColorCodes('&', "&e1 Use &7left").equals(itemLore.get(4))) {
|
||||
e.setCancelled(true);
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
item.setAmount(0);
|
||||
return true;
|
||||
}
|
||||
else if (ChatColor.translateAlternateColorCodes('&', "&e" + i + " Uses &7left").equals(itemLore.get(4))) {
|
||||
itemLore.set(4, ChatColor.translateAlternateColorCodes('&', "&e" + (i - 1) + ' ' + (i > 2 ? "Uses": "Use") + " &7left"));
|
||||
e.setCancelled(true);
|
||||
int currentUses = itemMeta.getPersistentDataContainer()
|
||||
.getOrDefault(usageKey, PersistentDataType.INTEGER, MAX_USES);
|
||||
|
||||
// Saving the changes to lore and item.
|
||||
itemMeta.setLore(itemLore);
|
||||
item.setItemMeta(itemMeta);
|
||||
|
||||
return true;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
if (currentUses == 1) {
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
item.setAmount(0);
|
||||
} else {
|
||||
itemMeta.getPersistentDataContainer().set(
|
||||
usageKey, PersistentDataType.INTEGER, --currentUses
|
||||
);
|
||||
itemLore.set(4, ChatColor.translateAlternateColorCodes('&',
|
||||
"&e" + currentUses + ' ' + (currentUses == 1 ? "Uses": "Use") + " &7left"));
|
||||
itemMeta.setLore(itemLore);
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Messages.local.sendTranslation(p, "messages.no-pvp", true);
|
||||
|
Loading…
Reference in New Issue
Block a user