mirror of
https://e.coding.net/circlecloud/Soulbound.git
synced 2024-11-21 01:39:10 +00:00
Remove UUID Check Model...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
11a919e8c1
commit
b1d259bf7c
@ -2,7 +2,6 @@ package com.me.tft_02.soulbound.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -222,69 +221,11 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static boolean isBindedPlayer(Player player, ItemStack itemStack) {
|
||||
updateOldLore(player, itemStack);
|
||||
checkNameChange(player, itemStack);
|
||||
List<String> itemLore = itemStack.getItemMeta().getLore();
|
||||
|
||||
return itemLore.contains(player.getName());
|
||||
}
|
||||
|
||||
private static ItemStack updateOldLore(Player player, ItemStack itemStack) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta != null) {
|
||||
if (!itemMeta.hasLore()) {
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
List<String> itemLore = itemMeta.getLore();
|
||||
|
||||
if (itemLore.size() - 1 < StringUtils.getIndexOfSoulbound(itemLore) + 2) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
int indexOfSoulbound = StringUtils.getIndexOfSoulbound(itemLore);
|
||||
int indexOfUniqueId = indexOfSoulbound + 2;
|
||||
UUID uuid = null;
|
||||
|
||||
if (itemLore.get(indexOfUniqueId).contains(player.getUniqueId().toString())) {
|
||||
uuid = UUID.fromString(ChatColor.stripColor(itemLore.get(indexOfUniqueId)));
|
||||
itemLore.remove(indexOfUniqueId);
|
||||
}
|
||||
|
||||
if (StringUtils.readUUIDFromLore(itemLore) == null && uuid != null) {
|
||||
itemLore.set(indexOfSoulbound, Misc.SOULBOUND_TAG + StringUtils.hideUUID(uuid));
|
||||
}
|
||||
|
||||
itemMeta.setLore(itemLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private static ItemStack checkNameChange(Player player, ItemStack itemStack) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
List<String> itemLore = itemMeta.getLore();
|
||||
|
||||
int indexName = StringUtils.getIndexOfSoulbound(itemLore) + 1;
|
||||
|
||||
if (itemLore.size() >= 2 && itemLore.contains(player.getName()) && !Config.getInstance().getShowNameInLore()) {
|
||||
Soulbound.p.debug("Item lore has a player name but that's disabled in config");
|
||||
Soulbound.p.debug("Going to remove what is at indexName " + indexName + " which is: " + itemLore.get(indexName));
|
||||
itemLore.remove(indexName);
|
||||
itemMeta.setLore(itemLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getShowNameInLore() && !itemLore.contains(player.getName()) && player.getUniqueId().equals(StringUtils.readUUIDFromLore(itemLore))) {
|
||||
Soulbound.p.debug("Item lore doesn't have (correct) player name but it should and the UUIDs match");
|
||||
itemLore.add(indexName, player.getName());
|
||||
}
|
||||
|
||||
itemMeta.setLore(itemLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static boolean isNormalItem(ItemStack itemStack) {
|
||||
return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL;
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.me.tft_02.soulbound.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
@ -17,33 +14,4 @@ public class StringUtils {
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public static UUID readUUIDFromLore(List<String> itemLore) {
|
||||
int index = getIndexOfSoulbound(itemLore);
|
||||
|
||||
if (index == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String line = itemLore.get(index);
|
||||
line = line.substring(11);
|
||||
|
||||
return readUUID(line);
|
||||
}
|
||||
|
||||
public static String hideUUID(UUID uuid) {
|
||||
String string = uuid.toString();
|
||||
string = string.replaceAll("-", ChatColor.MAGIC.toString());
|
||||
StringBuilder formattedString = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
formattedString.append(ChatColor.COLOR_CHAR).append(string.charAt(i));
|
||||
}
|
||||
|
||||
return formattedString.toString();
|
||||
}
|
||||
|
||||
public static UUID readUUID(String string) {
|
||||
return UUID.fromString(string.replaceAll(ChatColor.MAGIC.toString(), "-").replaceAll("§", ""));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user