This commit is contained in:
YuTian 2024-08-24 01:22:05 +08:00
parent f60b96e601
commit 9bcebaeb68
2 changed files with 99 additions and 18 deletions

View File

@ -32,15 +32,13 @@ public class GuiListener implements Listener {
private void onClick(InventoryClickEvent event) { private void onClick(InventoryClickEvent event) {
if (event.getInventory().getType() == InventoryType.CRAFTING) { if (event.getInventory().getType() == InventoryType.CRAFTING) {
ItemStack cursor = event.getCursor(); ItemStack cursor = event.getCursor();
if (!ItemStackUtil.isRemoveRefineItem(cursor)) {
return;
}
ItemStack current = event.getCurrentItem(); ItemStack current = event.getCurrentItem();
if (current == null || current.getType() == Material.AIR) { if (current == null || current.getType() == Material.AIR) {
return; return;
} }
event.setCancelled(true);
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (ItemStackUtil.isRemoveRefineItem(cursor)) {
event.setCancelled(true);
if (!ItemStackUtil.isRefined(current)) { if (!ItemStackUtil.isRefined(current)) {
player.sendMessage("§8§l[§c§l!§8§l] §7该物品无法重置洗练"); player.sendMessage("§8§l[§c§l!§8§l] §7该物品无法重置洗练");
player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1.6F, 1.8F); player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1.6F, 1.8F);
@ -55,6 +53,23 @@ public class GuiListener implements Listener {
event.setCurrentItem(newItemStack); event.setCurrentItem(newItemStack);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
player.sendMessage("§8§l[§a§l!§8§l] §7成功重置洗练"); 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成功使用极致技能冷却符");
}
} }
} }

View File

@ -52,6 +52,17 @@ public class ItemStackUtil {
return false; 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) { public static String getRefineType(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) { if (itemStack == null || itemStack.getType() == Material.AIR) {
return null; return null;
@ -99,6 +110,61 @@ public class ItemStackUtil {
return false; 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<String> 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<String> 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<String> 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) { public static ItemStack replaceAllLore(ItemStack itemStack, String newLore) {
if (itemStack == null || itemStack.getType() == Material.AIR) { if (itemStack == null || itemStack.getType() == Material.AIR) {
return itemStack; return itemStack;