This commit is contained in:
YuTian 2024-08-23 00:15:52 +08:00
parent 58b473aa1a
commit a9643a51b6
4 changed files with 106 additions and 1 deletions

View File

@ -65,6 +65,13 @@ public final class RefineSystem extends JavaPlugin {
NBTItem item = new NBTItem(itemStack1);
item.setString("refineType", "雨天洗炼符");
player.getInventory().addItem(item.getItem());
ItemStack itemStack2 = new ItemStack(Material.EMERALD);
ItemMeta itemMeta2 = itemStack2.getItemMeta();
itemMeta2.setDisplayName("§f雨天去除洗炼符");
itemStack2.setItemMeta(itemMeta1);
NBTItem item2 = new NBTItem(itemStack2);
item2.setString("removeRefine", "true");
player.getInventory().addItem(item2.getItem());
sender.sendMessage("§8§l[§a§l!§8§l] §7获取物品成功");
return true;
}

View File

@ -1,12 +1,19 @@
package com.io.yutian.refinesystem.listener;
import com.io.yutian.refinesystem.RefineSystemSetting;
import com.io.yutian.refinesystem.gui.GuiHolder;
import com.io.yutian.refinesystem.util.ItemStackUtil;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
public class GuiListener implements Listener {
@ -17,6 +24,37 @@ public class GuiListener implements Listener {
if (holder != null && holder instanceof GuiHolder) {
GuiHolder guiHolder = (GuiHolder) holder;
guiHolder.onClick(event);
return;
}
onClick(event);
}
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 (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成功重置洗练");
}
}

View File

@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -40,6 +41,17 @@ public class ItemStackUtil {
return false;
}
public static boolean isRemoveRefineItem(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) {
return false;
}
NBTItem nbtItem = new NBTItem(itemStack);
if (nbtItem.hasKey("removeRefine")) {
return true;
}
return false;
}
public static String getRefineType(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) {
return null;
@ -70,6 +82,54 @@ public class ItemStackUtil {
return -1;
}
public static boolean isRefined(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 replaceAllLore(ItemStack itemStack, String newLore) {
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("§7(被动技)")) {
if (index == -1) {
index = i;
}
}
}
Iterator<String> iterator = lore.iterator();
while (iterator.hasNext()) {
String s = iterator.next();
if (s.contains("§7(被动技)")) {
iterator.remove();
}
}
lore.add(newLore);
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack replaceLore(ItemStack itemStack, String oldLore, List<String> newLores) {
ItemStack itemStack1 = itemStack.clone();
ItemMeta itemMeta = itemStack1.getItemMeta();

View File

@ -10,7 +10,7 @@ options:
# NbtKey
雨天洗炼符:
# 洗炼成功率
chance: 1.0
chance: 0.5
# 武器需要达到什么品质
needQuality: 1
# 可随机添加多少个词条