From 9ce1158aeb8b26a7d08b57c614e6b6f17c3eb354 Mon Sep 17 00:00:00 2001 From: Chris Ward Date: Tue, 21 Jan 2014 00:54:48 +1100 Subject: Add support for vanilla JSON metadata syntax (/give, /i, /kit, etc.) --- .../src/com/earth2me/essentials/MetaItemStack.java | 45 +++++++++++++++------- Essentials/src/messages.properties | 1 + Essentials/src/messages_cs.properties | 1 + Essentials/src/messages_da.properties | 1 + Essentials/src/messages_de.properties | 1 + Essentials/src/messages_en.properties | 1 + Essentials/src/messages_es.properties | 1 + Essentials/src/messages_fi.properties | 1 + Essentials/src/messages_fr.properties | 1 + Essentials/src/messages_hu.properties | 1 + Essentials/src/messages_it.properties | 1 + Essentials/src/messages_lt.properties | 1 + Essentials/src/messages_nl.properties | 1 + Essentials/src/messages_pl.properties | 1 + Essentials/src/messages_pt.properties | 1 + Essentials/src/messages_ro.properties | 1 + Essentials/src/messages_ru.properties | 1 + Essentials/src/messages_sv.properties | 1 + Essentials/src/messages_tr.properties | 1 + Essentials/src/messages_zh.properties | 1 + Essentials/src/messages_zh_HK.properties | 1 + Essentials/src/messages_zh_TW.properties | 1 + 22 files changed, 53 insertions(+), 13 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index 90b761249..8dd146c50 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -8,6 +8,8 @@ import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.NumberUtil; import java.util.*; import java.util.regex.Pattern; + +import com.google.common.base.Joiner; import net.ess3.api.IEssentials; import org.bukkit.Color; import org.bukkit.DyeColor; @@ -36,7 +38,7 @@ public class MetaItemStack } } private final transient Pattern splitPattern = Pattern.compile("[:+',;.]"); - private final ItemStack stack; + private ItemStack stack; private FireworkEffect.Builder builder = FireworkEffect.builder(); private PotionEffectType pEffectType; private PotionEffect pEffect; @@ -95,25 +97,42 @@ public class MetaItemStack public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception { - - for (int i = fromArg; i < string.length; i++) + if (string[fromArg].startsWith("{")) { - addStringMeta(sender, allowUnsafe, string[i], ess); + try + { + stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length))); + } + catch (NoSuchMethodError nsme) + { + throw new Exception(_("noMetaJson"), nsme); + } + catch (Throwable throwable) + { + throw new Exception(throwable.getMessage(), throwable); + } } - if (validFirework) + else { - if (!hasMetaPermission(sender, "firework", true, true, ess)) + for (int i = fromArg; i < string.length; i++) { - throw new Exception(_("noMetaFirework")); + addStringMeta(sender, allowUnsafe, string[i], ess); } - FireworkEffect effect = builder.build(); - FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta(); - fmeta.addEffect(effect); - if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) + if (validFirework) { - throw new Exception(_("multipleCharges")); + if (!hasMetaPermission(sender, "firework", true, true, ess)) + { + throw new Exception(_("noMetaFirework")); + } + FireworkEffect effect = builder.build(); + FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta(); + fmeta.addEffect(effect); + if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) + { + throw new Exception(_("multipleCharges")); + } + stack.setItemMeta(fmeta); } - stack.setItemMeta(fmeta); } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index afc798cf3..b0cb2f6bd 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -533,3 +533,4 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index c537db2b4..ce17552fa 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a7Nemuzes uveznit hrace, kteri nejsou pripojeni. muteExemptOffline=\u00a7Nemuzes umlcet hrace, kteri nejsou pripojeni. ignoreExempt=\u00a74Nemuzes ignorovat tohoto hrace. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index b59d3dbdd..6f8d677e6 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Du kan ikke s\u00e6tte offline spillere i f\u00e6ngsel. muteExemptOffline=\u00a74Du kan ikke g\u00f8re offline spillere tavse. ignoreExempt=\u00a74Du kan ikke ignorere den spiller. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 04f0f0b75..7a9a21967 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Du darfst abgemeldete Spieler nicht einsperren. muteExemptOffline=\u00a74Du darfst abgemeldete Spieler nicht stummschalten. ignoreExempt=\u00a74Du kannst diesen Spieler nicht ignorieren. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 13ac60c8a..7e8b64cd8 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You may not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index dd66e1c5e..448a95ae9 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74No puedes encarcelar a jugadores que no est\u00e1n cone muteExemptOffline=\u00a74No puedes silenciar a jugadores que no est\u00e1n conectados. ignoreExempt=\u00a74No puedes ignorar a este jugador. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 2160a8394..a673ca1d7 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 8a386a603..2cd02e1d4 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Vous ne pouvez pas emprisonner les joueurs d\u00e9conne muteExemptOffline=\u00a74Vous ne pouvez pas rendre muets les joueurs d\u00e9connect\u00e9s. ignoreExempt=\u00a74Vous ne pouvez pas ignorer ce joueur. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_hu.properties b/Essentials/src/messages_hu.properties index a8b300030..65e155e4e 100644 --- a/Essentials/src/messages_hu.properties +++ b/Essentials/src/messages_hu.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Nem b\u00f6rt\u00f6n\u00f6zhetsz be Offline j\u00e1t\u0 muteExemptOffline=\u00a74Nem n\u00e9m\u00edthatsz le Offline j\u00e1t\u00e9kost. ignoreExempt=\u00a74Nem hagyhatod figyelmen k\u00edv\u0171l ezt a j\u00e1t\u00e9kost. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index 5f9730392..3af2b8eb4 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Non puoi imprigionare un giocatore che e'' offline. muteExemptOffline=\u00a74Non puoi silenziare un giocatore che e'' offline. ignoreExempt=\u00a74Non puoi ignorare quel giocatore. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_lt.properties b/Essentials/src/messages_lt.properties index 357280bbc..8e3925c5a 100644 --- a/Essentials/src/messages_lt.properties +++ b/Essentials/src/messages_lt.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Tu negali pasodinti i kalejima neprisijungusiu zaideju. muteExemptOffline=\u00a74Tu negali uztildyti neprisijungusiu zaideju. ignoreExempt=\u00a74Tu negali ignoruoti sio zaidejo. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index e63a1017c..c864e55b2 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Je mag geen offline spelers in de gevangenis zetten. muteExemptOffline=\u00a74Je mag geen offline players dempen ignoreExempt=\u00a74Je kan die speler niet negeren. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 8c8dbe16c..b4fc6598f 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Nie mozesz wrzucic do wiezienia graczy offline. muteExemptOffline=\u00a74Nie mozesz wyciszyc graczy offline. ignoreExempt=\u00a74Nie mozesz ignorowac tego gracza. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index dc1f96066..9a6b33927 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74Voce nao pode prender jogadores desconectados. muteExemptOffline=\u00a74Voce nao pode silenciar jogadores desconectados. ignoreExempt=\u00a74Voce nao pode ignorar aquele jogador. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_ro.properties b/Essentials/src/messages_ro.properties index 2b234ed24..42a008abe 100644 --- a/Essentials/src/messages_ro.properties +++ b/Essentials/src/messages_ro.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_ru.properties b/Essentials/src/messages_ru.properties index 58510124a..3839bddf4 100644 --- a/Essentials/src/messages_ru.properties +++ b/Essentials/src/messages_ru.properties @@ -533,3 +533,4 @@ mayNotJailOffline=\u00a74\u0412\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u044 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. 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. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_sv.properties b/Essentials/src/messages_sv.properties index 989a40658..d22e1f630 100644 --- a/Essentials/src/messages_sv.properties +++ b/Essentials/src/messages_sv.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74DU kan inte f\u00e4ngelse urkopplad-spelare. muteExemptOffline=\u00a74DU kan inte st\u00e4nga av urkopplad-spelare. ignoreExempt=\u00a74DU kan inte ignorera den spelaren. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_tr.properties b/Essentials/src/messages_tr.properties index 8214162ab..ecc85a9e0 100644 --- a/Essentials/src/messages_tr.properties +++ b/Essentials/src/messages_tr.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_zh.properties b/Essentials/src/messages_zh.properties index 9de38b211..51ba2b6ee 100644 --- a/Essentials/src/messages_zh.properties +++ b/Essentials/src/messages_zh.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74\u4f60\u53ef\u80fd\u65e0\u6cd5\u76d1\u7981\u5df2\u79bb\ muteExemptOffline=\u00a74\u4f60\u53ef\u80fd\u65e0\u6cd5\u7981\u8a00\u5df2\u79bb\u7ebf\u73a9\u5bb6. ignoreExempt=\u00a74\u4f60\u65e0\u6cd5\u5ffd\u7565\u90a3\u4e2a\u73a9\u5bb6. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_zh_HK.properties b/Essentials/src/messages_zh_HK.properties index 4f43238b5..f4b21f338 100644 --- a/Essentials/src/messages_zh_HK.properties +++ b/Essentials/src/messages_zh_HK.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit diff --git a/Essentials/src/messages_zh_TW.properties b/Essentials/src/messages_zh_TW.properties index 05e5104e1..543300009 100644 --- a/Essentials/src/messages_zh_TW.properties +++ b/Essentials/src/messages_zh_TW.properties @@ -533,4 +533,5 @@ mayNotJailOffline=\u00a74You may not jail offline players. muteExemptOffline=\u00a74You may not mute offline players. ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. +noMetaJson=JSON Metadata is not supported in this version of Bukkit -- cgit v1.2.3