mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-05 23:08:23 +00:00
Allow enchants on fireworks/charges/potions/banners (#3882)
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
parent
8142da608c
commit
fa87c74b56
1 changed files with 30 additions and 23 deletions
|
@ -263,22 +263,27 @@ public class MetaItemStack {
|
||||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("itemflags") && hasMetaPermission(sender, "itemflags", false, true, ess)) {
|
} else if (split.length > 1 && split[0].equalsIgnoreCase("itemflags") && hasMetaPermission(sender, "itemflags", false, true, ess)) {
|
||||||
addItemFlags(string);
|
addItemFlags(string);
|
||||||
} else if (MaterialUtil.isFirework(stack.getType())) {
|
} else if (MaterialUtil.isFirework(stack.getType())) {
|
||||||
//WARNING - Meta for fireworks will be ignored after this point.
|
if (!parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
|
||||||
addFireworkMeta(sender, false, string, ess);
|
//WARNING - Meta for fireworks will be ignored after this point.
|
||||||
|
addFireworkMeta(sender, false, string, ess);
|
||||||
|
}
|
||||||
} else if (MaterialUtil.isFireworkCharge(stack.getType())) {
|
} 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())) {
|
} else if (MaterialUtil.isPotion(stack.getType())) {
|
||||||
//WARNING - Meta for potions will be ignored after this point.
|
if (split[0].equalsIgnoreCase("power") || !parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
|
||||||
addPotionMeta(sender, false, string, ess);
|
//WARNING - Meta for potions will be ignored after this point.
|
||||||
|
addPotionMeta(sender, false, string, ess);
|
||||||
|
}
|
||||||
} else if (MaterialUtil.isBanner(stack.getType())) {
|
} else if (MaterialUtil.isBanner(stack.getType())) {
|
||||||
if (stack.getType().toString().equals("SHIELD") && Enchantments.getByName(split[0]) != null) {
|
if (!parseEnchantmentStrings(sender, allowUnsafe, split, ess)) {
|
||||||
parseEnchantmentStrings(sender, allowUnsafe, split, ess);
|
|
||||||
} else {
|
|
||||||
//WARNING - Meta for banners will be ignored after this point.
|
//WARNING - Meta for banners will be ignored after this point.
|
||||||
addBannerMeta(sender, false, string, ess);
|
addBannerMeta(sender, false, string, ess);
|
||||||
}
|
}
|
||||||
} else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour")) && MaterialUtil.isLeatherArmor(stack.getType())) {
|
} 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("#"))) {
|
if (color.length == 1 && (NumberUtil.isInt(color[0]) || color[0].startsWith("#"))) {
|
||||||
// Either integer or hexadecimal
|
// Either integer or hexadecimal
|
||||||
final LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
|
final LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
|
||||||
|
@ -540,25 +545,27 @@ public class MetaItemStack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
final Enchantment enchantment = Enchantments.getByName(split[0]);
|
||||||
if (enchantment == null || !hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
|
if (enchantment == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
|
||||||
int level = -1;
|
int level = -1;
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
try {
|
try {
|
||||||
level = Integer.parseInt(split[1]);
|
level = Integer.parseInt(split[1]);
|
||||||
} catch (final NumberFormatException ex) {
|
} catch (final NumberFormatException ex) {
|
||||||
level = -1;
|
level = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
|
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
|
||||||
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 {
|
public void addEnchantment(final CommandSource sender, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception {
|
||||||
|
|
Loading…
Reference in a new issue