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

View File

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