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

+32-13
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

Essentials/src/messages_it.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Non puoi imprigionare un giocatore che e'' offline.
533533
muteExemptOffline=\u00a74Non puoi silenziare un giocatore che e'' offline.
534534
ignoreExempt=\u00a74Non puoi ignorare quel giocatore.
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_lt.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Tu negali pasodinti i kalejima neprisijungusiu zaideju.
533533
muteExemptOffline=\u00a74Tu negali uztildyti neprisijungusiu zaideju.
534534
ignoreExempt=\u00a74Tu negali ignoruoti sio zaidejo.
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_nl.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Je mag geen offline spelers in de gevangenis zetten.
533533
muteExemptOffline=\u00a74Je mag geen offline players dempen
534534
ignoreExempt=\u00a74Je kan die speler niet negeren.
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_pl.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Nie mozesz wrzucic do wiezienia graczy offline.
533533
muteExemptOffline=\u00a74Nie mozesz wyciszyc graczy offline.
534534
ignoreExempt=\u00a74Nie mozesz ignorowac tego gracza.
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_pt.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Voce nao pode prender jogadores desconectados.
533533
muteExemptOffline=\u00a74Voce nao pode silenciar jogadores desconectados.
534534
ignoreExempt=\u00a74Voce nao pode ignorar aquele jogador.
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_ro.properties

+1
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_ru.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,4 @@ mayNotJailOffline=\u00a74\u0412\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u044
533533
muteExemptOffline=\u00a74\u0412\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0442\u043a\u043d\u0443\u0442\u044c \u0438\u0433\u0440\u043e\u043a\u0430 \u0432 \u043e\u0444\u0444\u043b\u0430\u0439\u043d\u0435.
534534
ignoreExempt=\u00a74\u0412\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430.
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_sv.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74DU kan inte f\u00e4ngelse urkopplad-spelare.
533533
muteExemptOffline=\u00a74DU kan inte st\u00e4nga av urkopplad-spelare.
534534
ignoreExempt=\u00a74DU kan inte ignorera den spelaren.
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_tr.properties

+1
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_zh.properties

+1
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74\u4f60\u53ef\u80fd\u65e0\u6cd5\u76d1\u7981\u5df2\u79bb\
533533
muteExemptOffline=\u00a74\u4f60\u53ef\u80fd\u65e0\u6cd5\u7981\u8a00\u5df2\u79bb\u7ebf\u73a9\u5bb6.
534534
ignoreExempt=\u00a74\u4f60\u65e0\u6cd5\u5ffd\u7565\u90a3\u4e2a\u73a9\u5bb6.
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_zh_HK.properties

+1
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_zh_TW.properties

+1
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

0 commit comments

Comments
 (0)