Edit itemstack parsing to pass the whole string to modifyItemStack since implementation has changed recently

This commit is contained in:
fullwall 2024-09-16 01:40:17 +08:00
parent 17eeac29cf
commit 15d31aa357
2 changed files with 21 additions and 14 deletions

View File

@ -662,14 +662,16 @@ public class HologramTrait extends Trait {
NPC npc = registry().createNPCUsingItem(EntityType.ITEM_DISPLAY, "", itemStack);
npc.data().setPersistent(NPC.Metadata.NAMEPLATE_VISIBLE, false);
if (itemMatcher.group(2) != null) {
if (itemMatcher.group(2).charAt(1) == '{') {
Bukkit.getUnsafe().modifyItemStack(itemStack, itemMatcher.group(2).substring(1));
npc.setItemProvider(() -> itemStack);
} else {
for (ChatColor color : ChatColor.values()) {
if (itemMatcher.group(2).equalsIgnoreCase(color.name())) {
npc.getOrAddTrait(ScoreboardTrait.class)
.setColor(Util.matchEnum(ChatColor.values(), itemMatcher.group(2).substring(1)));
.setColor(Util.matchEnum(ChatColor.values(), itemMatcher.group(2)));
return npc;
}
}
Bukkit.getUnsafe().modifyItemStack(itemStack, itemMatcher.group(2));
npc.setItemProvider(() -> itemStack.clone());
}
return npc;
}
@ -705,12 +707,18 @@ public class HologramTrait extends Trait {
itemNPC = registry().createNPCUsingItem(Util.getFallbackEntityType("ITEM", "DROPPED_ITEM"), "", itemStack);
itemNPC.data().setPersistent(NPC.Metadata.NAMEPLATE_VISIBLE, false);
if (itemMatcher.group(2) != null) {
if (itemMatcher.group(2).charAt(1) == '{') {
Bukkit.getUnsafe().modifyItemStack(itemStack, itemMatcher.group(2).substring(1));
itemNPC.setItemProvider(() -> itemStack);
} else {
ChatColor matched = null;
for (ChatColor color : ChatColor.values()) {
if (itemMatcher.group(2).equalsIgnoreCase(color.name())) {
itemNPC.getOrAddTrait(ScoreboardTrait.class)
.setColor(Util.matchEnum(ChatColor.values(), itemMatcher.group(2).substring(1)));
.setColor(Util.matchEnum(ChatColor.values(), itemMatcher.group(2)));
matched = color;
break;
}
}
if (matched == null) {
Bukkit.getUnsafe().modifyItemStack(itemStack, itemMatcher.group(2));
itemNPC.setItemProvider(() -> itemStack.clone());
}
}
itemNPC.spawn(base.getLocation());

View File

@ -344,7 +344,6 @@ public class Util {
if (toMatch.equalsIgnoreCase(check.name())
|| toMatch.equalsIgnoreCase("item") && check.name().equals("DROPPED_ITEM"))
return check; // check for an exact match first
}
for (T check : values) {
String name = check.name().toLowerCase(Locale.ROOT);
@ -395,7 +394,7 @@ public class Util {
if (stack == null || stack.getType() == Material.AIR) {
stack = new ItemStack(Material.STONE, 1);
}
if (item.charAt(0) == '{') {
if (item.contains("{")) {
try {
Bukkit.getUnsafe().modifyItemStack(stack, item);
} catch (Throwable t) {