diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index 7926a31c851..7aa45627ea1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -146,7 +146,13 @@ public boolean canSpawn(final IEssentials ess) { } public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, final String[] string, final int fromArg, final IEssentials ess) throws Exception { + final boolean nbtIsKill = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01); + if (string[fromArg].startsWith("{") && hasMetaPermission(sender, "vanilla", false, true, ess)) { + if (nbtIsKill) { + throw new TranslatableException("noMetaNbtKill"); + } + try { stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length))); } catch (final NullPointerException npe) { @@ -158,6 +164,22 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf } catch (final Throwable throwable) { throw new Exception(throwable.getMessage(), throwable); } + } else if (string[fromArg].startsWith("[") && hasMetaPermission(sender, "vanilla", false, true, ess)) { + if (!nbtIsKill) { + throw new TranslatableException("noMetaComponents"); + } + + try { + final String components = Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length)); + // modifyItemStack requires that the item namespaced key is prepended to the components for some reason + stack = ess.getServer().getUnsafe().modifyItemStack(stack, stack.getType().getKey() + components); + } catch (final NullPointerException npe) { + if (ess.getSettings().isDebug()) { + ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe); + } + } catch (final Throwable throwable) { + throw new Exception(throwable.getMessage(), throwable); + } } else { for (int i = fromArg; i < string.length; i++) { addStringMeta(sender, allowUnsafe, string[i], ess); diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index c1d1bf84381..d2d07e06d08 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -863,8 +863,10 @@ noLocationFound=No valid location found. noMail=You do not have any mail. noMailOther={0} does not have any mail. noMatchingPlayers=No matching players found. +noMetaComponents=Data Components are not supported in this version of Bukkit. Please use JSON NBT metadata. noMetaFirework=You do not have permission to apply firework meta. noMetaJson=JSON Metadata is not supported in this version of Bukkit. +noMetaNbtKill=JSON NBT metadata is no longer supported. You must manually convert your defined items to data components. You can convert JSON NBT to data components here: https://docs.papermc.io/misc/tools/item-command-converter noMetaPerm=You do not have permission to apply {0} meta to this item. none=none noNewMail=You have no new mail.