Skip to content

Commit 9ce1158

Browse files
committed
Add support for vanilla JSON metadata syntax (/give, /i, /kit, etc.)
1 parent 839bfe0 commit 9ce1158

22 files changed

+53
-13
lines changed

Essentials/src/com/earth2me/essentials/MetaItemStack.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.earth2me.essentials.utils.NumberUtil;
99
import java.util.*;
1010
import java.util.regex.Pattern;
11+
12+
import com.google.common.base.Joiner;
1113
import net.ess3.api.IEssentials;
1214
import org.bukkit.Color;
1315
import org.bukkit.DyeColor;
@@ -36,7 +38,7 @@ public class MetaItemStack
3638
}
3739
}
3840
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
39-
private final ItemStack stack;
41+
private ItemStack stack;
4042
private FireworkEffect.Builder builder = FireworkEffect.builder();
4143
private PotionEffectType pEffectType;
4244
private PotionEffect pEffect;
@@ -95,25 +97,42 @@ private void resetPotionMeta()
9597

9698
public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception
9799
{
98-
99-
for (int i = fromArg; i < string.length; i++)
100+
if (string[fromArg].startsWith("{"))
100101
{
101-
addStringMeta(sender, allowUnsafe, string[i], ess);
102+
try
103+
{
104+
stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length)));
105+
}
106+
catch (NoSuchMethodError nsme)
107+
{
108+
throw new Exception(_("noMetaJson"), nsme);
109+
}
110+
catch (Throwable throwable)
111+
{
112+
throw new Exception(throwable.getMessage(), throwable);
113+
}
102114
}
103-
if (validFirework)
115+
else
104116
{
105-
if (!hasMetaPermission(sender, "firework", true, true, ess))
117+
for (int i = fromArg; i < string.length; i++)
106118
{
107-
throw new Exception(_("noMetaFirework"));
119+
addStringMeta(sender, allowUnsafe, string[i], ess);
108120
}
109-
FireworkEffect effect = builder.build();
110-
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
111-
fmeta.addEffect(effect);
112-
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess))
121+
if (validFirework)
113122
{
114-
throw new Exception(_("multipleCharges"));
123+
if (!hasMetaPermission(sender, "firework", true, true, ess))
124+
{
125+
throw new Exception(_("noMetaFirework"));
126+
}
127+
FireworkEffect effect = builder.build();
128+
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
129+
fmeta.addEffect(effect);
130+
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess))
131+
{
132+
throw new Exception(_("multipleCharges"));
133+
}
134+
stack.setItemMeta(fmeta);
115135
}
116-
stack.setItemMeta(fmeta);
117136
}
118137
}
119138

Essentials/src/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,4 @@ mayNotJailOffline=\u00a74You may not jail offline players.
533533
muteExemptOffline=\u00a74You may not mute offline players.
534534
ignoreExempt=\u00a74You can not ignore that player.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit

Essentials/src/messages_cs.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a7Nemuzes uveznit hrace, kteri nejsou pripojeni.
533533
muteExemptOffline=\u00a7Nemuzes umlcet hrace, kteri nejsou pripojeni.
534534
ignoreExempt=\u00a74Nemuzes ignorovat tohoto hrace.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_da.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Du kan ikke s\u00e6tte offline spillere i f\u00e6ngsel.
533533
muteExemptOffline=\u00a74Du kan ikke g\u00f8re offline spillere tavse.
534534
ignoreExempt=\u00a74Du kan ikke ignorere den spiller.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_de.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Du darfst abgemeldete Spieler nicht einsperren.
533533
muteExemptOffline=\u00a74Du darfst abgemeldete Spieler nicht stummschalten.
534534
ignoreExempt=\u00a74Du kannst diesen Spieler nicht ignorieren.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players.
533533
muteExemptOffline=\u00a74You may not mute offline players.
534534
ignoreExempt=\u00a74You may not ignore that player.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_es.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74No puedes encarcelar a jugadores que no est\u00e1n cone
533533
muteExemptOffline=\u00a74No puedes silenciar a jugadores que no est\u00e1n conectados.
534534
ignoreExempt=\u00a74No puedes ignorar a este jugador.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_fi.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players.
533533
muteExemptOffline=\u00a74You may not mute offline players.
534534
ignoreExempt=\u00a74You can not ignore that player.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Vous ne pouvez pas emprisonner les joueurs d\u00e9conne
533533
muteExemptOffline=\u00a74Vous ne pouvez pas rendre muets les joueurs d\u00e9connect\u00e9s.
534534
ignoreExempt=\u00a74Vous ne pouvez pas ignorer ce joueur.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

Essentials/src/messages_hu.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Nem b\u00f6rt\u00f6n\u00f6zhetsz be Offline j\u00e1t\u0
533533
muteExemptOffline=\u00a74Nem n\u00e9m\u00edthatsz le Offline j\u00e1t\u00e9kost.
534534
ignoreExempt=\u00a74Nem hagyhatod figyelmen k\u00edv\u0171l ezt a j\u00e1t\u00e9kost.
535535
unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled.
536+
noMetaJson=JSON Metadata is not supported in this version of Bukkit
536537

0 commit comments

Comments
 (0)