mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Merge pull request #1117 from WalshyDev/fix/fix-storm-staff-usages
Improve storm staff usages
This commit is contained in:
commit
25ee04bb89
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.StormStaff;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.FireworkEffect;
|
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_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_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_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 {
|
static {
|
||||||
STAFF_WIND.addUnsafeEnchantment(Enchantment.LUCK, 1);
|
STAFF_WIND.addUnsafeEnchantment(Enchantment.LUCK, 1);
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -21,11 +22,14 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
|
|||||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
|
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
|
||||||
import me.mrCookieSlime.Slimefun.Setup.Messages;
|
import me.mrCookieSlime.Slimefun.Setup.Messages;
|
||||||
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
|
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) {
|
public StormStaff(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, id, recipeType, recipe, getCraftedOutput());
|
super(category, item, id, recipeType, recipe, getCraftedOutput());
|
||||||
}
|
}
|
||||||
@ -56,13 +60,13 @@ public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
|
|||||||
ItemStack sfItem = getItem();
|
ItemStack sfItem = getItem();
|
||||||
ItemMeta sfItemMeta = sfItem.getItemMeta();
|
ItemMeta sfItemMeta = sfItem.getItemMeta();
|
||||||
List<String> sfItemLore = sfItemMeta.getLore();
|
List<String> sfItemLore = sfItemMeta.getLore();
|
||||||
|
|
||||||
// Index 1 and 3 in SlimefunItems.STAFF_STORM has lores with words and stuff so we check for them.
|
// Index 1 and 3 in SlimefunItems.STAFF_STORM has lores with words and stuff so we check for them.
|
||||||
if (itemLore.size() < 6 && itemLore.get(1).equals(sfItemLore.get(1)) && itemLore.get(3).equals(sfItemLore.get(3))) {
|
if (itemLore.size() < 6 && itemLore.get(1).equals(sfItemLore.get(1)) && itemLore.get(3).equals(sfItemLore.get(3))) {
|
||||||
if (p.getFoodLevel() >= 4 || p.getGameMode() == GameMode.CREATIVE) {
|
if (p.getFoodLevel() >= 4 || p.getGameMode() == GameMode.CREATIVE) {
|
||||||
// Get a target block with max. 30 blocks of distance
|
// Get a target block with max. 30 blocks of distance
|
||||||
Location loc = p.getTargetBlock(null, 30).getLocation();
|
Location loc = p.getTargetBlock(null, 30).getLocation();
|
||||||
|
|
||||||
if (loc.getWorld() != null && loc.getChunk().isLoaded()) {
|
if (loc.getWorld() != null && loc.getChunk().isLoaded()) {
|
||||||
if (loc.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, loc, ProtectableAction.PVP)) {
|
if (loc.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, loc, ProtectableAction.PVP)) {
|
||||||
loc.getWorld().strikeLightning(loc);
|
loc.getWorld().strikeLightning(loc);
|
||||||
@ -72,33 +76,30 @@ public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
p.setFoodLevel(event.getFoodLevel());
|
p.setFoodLevel(event.getFoodLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = MAX_USES; i > 0; i--) {
|
int currentUses = itemMeta.getPersistentDataContainer()
|
||||||
if (i == 1 && ChatColor.translateAlternateColorCodes('&', "&e1 Use &7left").equals(itemLore.get(4))) {
|
.getOrDefault(usageKey, PersistentDataType.INTEGER, MAX_USES);
|
||||||
e.setCancelled(true);
|
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
e.setCancelled(true);
|
||||||
item.setAmount(0);
|
if (currentUses == 1) {
|
||||||
return true;
|
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||||
}
|
item.setAmount(0);
|
||||||
else if (ChatColor.translateAlternateColorCodes('&', "&e" + i + " Uses &7left").equals(itemLore.get(4))) {
|
} else {
|
||||||
itemLore.set(4, ChatColor.translateAlternateColorCodes('&', "&e" + (i - 1) + ' ' + (i > 2 ? "Uses": "Use") + " &7left"));
|
itemMeta.getPersistentDataContainer().set(
|
||||||
e.setCancelled(true);
|
usageKey, PersistentDataType.INTEGER, --currentUses
|
||||||
|
);
|
||||||
// Saving the changes to lore and item.
|
itemLore.set(4, ChatColor.translateAlternateColorCodes('&',
|
||||||
itemMeta.setLore(itemLore);
|
"&e" + currentUses + ' ' + (currentUses > 1 ? "Uses": "Use") + " &7left"));
|
||||||
item.setItemMeta(itemMeta);
|
itemMeta.setLore(itemLore);
|
||||||
|
item.setItemMeta(itemMeta);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
Messages.local.sendTranslation(p, "messages.no-pvp", true);
|
Messages.local.sendTranslation(p, "messages.no-pvp", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Messages.local.sendTranslation(p, "messages.hungry", true);
|
Messages.local.sendTranslation(p, "messages.hungry", true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user