From 9bcebaeb687b54e1db1254dc522add8c689deefe Mon Sep 17 00:00:00 2001 From: YuTian <2953516620@qq.com> Date: Sat, 24 Aug 2024 01:22:05 +0800 Subject: [PATCH] 2.0 --- .../refinesystem/listener/GuiListener.java | 49 ++++++++----- .../refinesystem/util/ItemStackUtil.java | 68 ++++++++++++++++++- 2 files changed, 99 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/io/yutian/refinesystem/listener/GuiListener.java b/src/main/java/com/io/yutian/refinesystem/listener/GuiListener.java index 9d66f28..14ad5b6 100644 --- a/src/main/java/com/io/yutian/refinesystem/listener/GuiListener.java +++ b/src/main/java/com/io/yutian/refinesystem/listener/GuiListener.java @@ -32,29 +32,44 @@ public class GuiListener implements Listener { private void onClick(InventoryClickEvent event) { if (event.getInventory().getType() == InventoryType.CRAFTING) { ItemStack cursor = event.getCursor(); - if (!ItemStackUtil.isRemoveRefineItem(cursor)) { - return; - } ItemStack current = event.getCurrentItem(); if (current == null || current.getType() == Material.AIR) { return; } - event.setCancelled(true); Player player = (Player) event.getWhoClicked(); - if (!ItemStackUtil.isRefined(current)) { - player.sendMessage("§8§l[§c§l!§8§l] §7该物品无法重置洗练"); - player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1.6F, 1.8F); - return; + if (ItemStackUtil.isRemoveRefineItem(cursor)) { + event.setCancelled(true); + if (!ItemStackUtil.isRefined(current)) { + player.sendMessage("§8§l[§c§l!§8§l] §7该物品无法重置洗练"); + player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1.6F, 1.8F); + return; + } + if (cursor.getAmount() == 1) { + event.getWhoClicked().setItemOnCursor(null); + } else { + cursor.setAmount(cursor.getAmount() - 1); + } + ItemStack newItemStack = ItemStackUtil.replaceAllLore(current, RefineSystemSetting.getDetectionLore()); + event.setCurrentItem(newItemStack); + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + player.sendMessage("§8§l[§a§l!§8§l] §7成功重置洗练"); + } else if (ItemStackUtil.isCDItem(cursor)) { + event.setCancelled(true); + if (!ItemStackUtil.isCanUseCDItem(current)) { + player.sendMessage("§8§l[§c§l!§8§l] §7该物品无法使用极致技能冷却符"); + player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1.6F, 1.8F); + return; + } + if (cursor.getAmount() == 1) { + event.getWhoClicked().setItemOnCursor(null); + } else { + cursor.setAmount(cursor.getAmount() - 1); + } + ItemStack newItemStack = ItemStackUtil.replaceAllLoreToCD(current); + event.setCurrentItem(newItemStack); + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + player.sendMessage("§8§l[§a§l!§8§l] §7成功使用极致技能冷却符"); } - if (cursor.getAmount() == 1) { - event.getWhoClicked().setItemOnCursor(null); - } else { - cursor.setAmount(cursor.getAmount() - 1); - } - ItemStack newItemStack = ItemStackUtil.replaceAllLore(current, RefineSystemSetting.getDetectionLore()); - event.setCurrentItem(newItemStack); - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); - player.sendMessage("§8§l[§a§l!§8§l] §7成功重置洗练"); } } diff --git a/src/main/java/com/io/yutian/refinesystem/util/ItemStackUtil.java b/src/main/java/com/io/yutian/refinesystem/util/ItemStackUtil.java index 7ffa7da..bebaf34 100644 --- a/src/main/java/com/io/yutian/refinesystem/util/ItemStackUtil.java +++ b/src/main/java/com/io/yutian/refinesystem/util/ItemStackUtil.java @@ -52,6 +52,17 @@ public class ItemStackUtil { return false; } + public static boolean isCDItem(ItemStack itemStack) { + if (itemStack == null || itemStack.getType() == Material.AIR) { + return false; + } + NBTItem nbtItem = new NBTItem(itemStack); + if (nbtItem.hasKey("skillcd02")) { + return true; + } + return false; + } + public static String getRefineType(ItemStack itemStack) { if (itemStack == null || itemStack.getType() == Material.AIR) { return null; @@ -99,6 +110,61 @@ public class ItemStackUtil { return false; } + public static boolean isCanUseCDItem(ItemStack itemStack) { + if (itemStack == null || itemStack.getType() == Material.AIR) { + return false; + } + ItemMeta itemMeta = itemStack.getItemMeta(); + if (!itemMeta.hasLore()) { + return false; + } + List lore = itemMeta.getLore(); + for (String s : lore) { + if (s.contains("§7(被动技)")) { + return true; + } + } + return false; + } + + public static ItemStack replaceAllLoreToCD(ItemStack itemStack) { + ItemStack itemStack1 = itemStack.clone(); + itemStack1 = replaceAllLoreToCD(itemStack1, "§6§0§6§r§6右键§0§6§r§6§f§l: §f§0§8§r§f凋零头§0§8§r§f", "§6§0§6§r§6右键§0§6§r§6§f§l: §f§0§8§r§f凋零头§0§8§r§f §8§l[§c§1§2§r§c0.2§1§2§r§c秒§8§l]"); + itemStack1 = replaceAllLoreToCD(itemStack1, "§6§0§6§r§6右键§0§6§r§6§f§l: §f§0§8§r§f火焰箭§0§8§r§f", "§6§0§6§r§6右键§0§6§r§6§f§l: §f§0§8§r§f火焰箭§0§8§r§f §8§l[§c§1§2§r§c0.2§1§2§r§c秒§8§l]"); + return itemStack1; + } + + public static ItemStack replaceAllLoreToCD(ItemStack itemStack, String arg0, String arg1) { + if (itemStack == null || itemStack.getType() == Material.AIR) { + return itemStack; + } + ItemMeta itemMeta = itemStack.getItemMeta(); + if (!itemMeta.hasLore()) { + return itemStack; + } + List lore = itemMeta.getLore(); + int index = -1; + for (int i = 0; i < lore.size(); i++) { + String s = lore.get(i); + if (s.contains(arg0)) { + if (index == -1) { + index = i; + } + } + } + lore.set(index, arg1); + Iterator iterator = lore.iterator(); + while (iterator.hasNext()) { + String s = iterator.next(); + if (s.contains(arg0)) { + iterator.remove(); + } + } + itemMeta.setLore(lore); + itemStack.setItemMeta(itemMeta); + return itemStack; + } + public static ItemStack replaceAllLore(ItemStack itemStack, String newLore) { if (itemStack == null || itemStack.getType() == Material.AIR) { return itemStack; @@ -117,7 +183,7 @@ public class ItemStackUtil { } } } - lore.set(index,newLore); + lore.set(index, newLore); Iterator iterator = lore.iterator(); while (iterator.hasNext()) { String s = iterator.next();