mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-03 22:08:28 +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)) {
|
||||
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();
|
||||
|
@ -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]);
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue