Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,27 @@ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe,
} else if (split.length > 1 && split[0].equalsIgnoreCase("itemflags") && hasMetaPermission(sender, "itemflags", false, true, ess)) {
addItemFlags(string);
} else if (MaterialUtil.isFirework(stack.getType())) {
//WARNING - Meta for fireworks will be ignored after this point.
addFireworkMeta(sender, false, string, ess);
if (!parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
//WARNING - Meta for fireworks will be ignored after this point.
addFireworkMeta(sender, false, string, ess);
}
} else if (MaterialUtil.isFireworkCharge(stack.getType())) {
addChargeMeta(sender, false, string, ess);
if (!parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
//WARNING - Meta for fireworks will be ignored after this point.
addChargeMeta(sender, false, string, ess);
}
} else if (MaterialUtil.isPotion(stack.getType())) {
//WARNING - Meta for potions will be ignored after this point.
addPotionMeta(sender, false, string, ess);
if (split[0].equalsIgnoreCase("power") || !parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
//WARNING - Meta for potions will be ignored after this point.
addPotionMeta(sender, false, string, ess);
}
} else if (MaterialUtil.isBanner(stack.getType())) {
if (stack.getType().toString().equals("SHIELD") && Enchantments.getByName(split[0]) != null) {
parseEnchantmentStrings(sender, allowUnsafe, split, ess);
} else {
if (!parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
//WARNING - Meta for banners will be ignored after this point.
addBannerMeta(sender, false, string, ess);
}
} else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour")) && MaterialUtil.isLeatherArmor(stack.getType())) {
final String[] color = split[1].split("(\\||,)");
final String[] color = split[1].split("[|,]");
if (color.length == 1 && (NumberUtil.isInt(color[0]) || color[0].startsWith("#"))) {
// Either integer or hexadecimal
final LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
Expand Down Expand Up @@ -540,25 +545,27 @@ public void addPotionMeta(final CommandSource sender, final boolean allowShortNa
}
}

private void parseEnchantmentStrings(final CommandSource sender, final boolean allowUnsafe, final String[] split, final IEssentials ess) throws Exception {
private boolean parseEnchantmentStrings(final CommandSource sender, final boolean allowUnsafe, final String[] split, final IEssentials ess) throws Exception {
final Enchantment enchantment = Enchantments.getByName(split[0]);
if (enchantment == null || !hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
return;
if (enchantment == null) {
return false;
}

int level = -1;
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (final NumberFormatException ex) {
level = -1;
if (hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
int level = -1;
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (final NumberFormatException ex) {
level = -1;
}
}
}

if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
level = enchantment.getMaxLevel();
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
level = enchantment.getMaxLevel();
}
addEnchantment(sender, allowUnsafe, enchantment, level);
}
addEnchantment(sender, allowUnsafe, enchantment, level);
return true;
}

public void addEnchantment(final CommandSource sender, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception {
Expand Down