|
8 | 8 | import com.earth2me.essentials.utils.NumberUtil;
|
9 | 9 | import java.util.*;
|
10 | 10 | import java.util.regex.Pattern;
|
| 11 | + |
| 12 | +import com.google.common.base.Joiner; |
11 | 13 | import net.ess3.api.IEssentials;
|
12 | 14 | import org.bukkit.Color;
|
13 | 15 | import org.bukkit.DyeColor;
|
@@ -36,7 +38,7 @@ public class MetaItemStack
|
36 | 38 | }
|
37 | 39 | }
|
38 | 40 | private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
39 |
| - private final ItemStack stack; |
| 41 | + private ItemStack stack; |
40 | 42 | private FireworkEffect.Builder builder = FireworkEffect.builder();
|
41 | 43 | private PotionEffectType pEffectType;
|
42 | 44 | private PotionEffect pEffect;
|
@@ -95,25 +97,42 @@ private void resetPotionMeta()
|
95 | 97 |
|
96 | 98 | public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception
|
97 | 99 | {
|
98 |
| - |
99 |
| - for (int i = fromArg; i < string.length; i++) |
| 100 | + if (string[fromArg].startsWith("{")) |
100 | 101 | {
|
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 | + } |
102 | 114 | }
|
103 |
| - if (validFirework) |
| 115 | + else |
104 | 116 | {
|
105 |
| - if (!hasMetaPermission(sender, "firework", true, true, ess)) |
| 117 | + for (int i = fromArg; i < string.length; i++) |
106 | 118 | {
|
107 |
| - throw new Exception(_("noMetaFirework")); |
| 119 | + addStringMeta(sender, allowUnsafe, string[i], ess); |
108 | 120 | }
|
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) |
113 | 122 | {
|
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); |
115 | 135 | }
|
116 |
| - stack.setItemMeta(fmeta); |
117 | 136 | }
|
118 | 137 | }
|
119 | 138 |
|
|