2.0
This commit is contained in:
parent
f60b96e601
commit
9bcebaeb68
|
@ -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成功重置洗练");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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) {
|
||||
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<String> iterator = lore.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String s = iterator.next();
|
||||
|
|
Loading…
Reference in New Issue
Block a user