mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 12:02:53 +00:00
Add default enchantment level for enchant sign (#3070)
Defaults the enchantment level on signs to `1` if one is not provided on the sign. Closes #1497.
This commit is contained in:
parent
1bc1f646fd
commit
e9d29f789f
1 changed files with 15 additions and 18 deletions
|
@ -28,21 +28,19 @@ public class SignEnchant extends EssentialsSign {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
final String[] enchantLevel = sign.getLine(2).split(":");
|
final String[] enchantLevel = sign.getLine(2).split(":");
|
||||||
if (enchantLevel.length != 2) {
|
int level = 1;
|
||||||
sign.setLine(2, "§c<enchant>");
|
|
||||||
throw new SignException(tl("invalidSignLine", 3));
|
|
||||||
}
|
|
||||||
final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]);
|
final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]);
|
||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
sign.setLine(2, "§c<enchant>");
|
sign.setLine(2, "§c<enchant>");
|
||||||
throw new SignException(tl("enchantmentNotFound"));
|
throw new SignException(tl("enchantmentNotFound"));
|
||||||
}
|
}
|
||||||
int level;
|
if (enchantLevel.length > 1) {
|
||||||
try {
|
try {
|
||||||
level = Integer.parseInt(enchantLevel[1]);
|
level = Integer.parseInt(enchantLevel[1]);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
sign.setLine(2, "§c<enchant>");
|
sign.setLine(2, "§c<enchant>");
|
||||||
throw new SignException(ex.getMessage(), ex);
|
throw new SignException(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.enchantments.allowunsafe") && player.isAuthorized("essentials.signs.enchant.allowunsafe");
|
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.enchantments.allowunsafe") && player.isAuthorized("essentials.signs.enchant.allowunsafe");
|
||||||
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
|
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
|
||||||
|
@ -70,18 +68,17 @@ public class SignEnchant extends EssentialsSign {
|
||||||
final Trade charge = getTrade(sign, 3, ess);
|
final Trade charge = getTrade(sign, 3, ess);
|
||||||
charge.isAffordableFor(player);
|
charge.isAffordableFor(player);
|
||||||
final String[] enchantLevel = sign.getLine(2).split(":");
|
final String[] enchantLevel = sign.getLine(2).split(":");
|
||||||
if (enchantLevel.length != 2) {
|
|
||||||
throw new SignException(tl("invalidSignLine", 3));
|
|
||||||
}
|
|
||||||
final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]);
|
final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]);
|
||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
throw new SignException(tl("enchantmentNotFound"));
|
throw new SignException(tl("enchantmentNotFound"));
|
||||||
}
|
}
|
||||||
int level;
|
int level = 1;
|
||||||
try {
|
if (enchantLevel.length > 1) {
|
||||||
level = Integer.parseInt(enchantLevel[1]);
|
try {
|
||||||
} catch (NumberFormatException ex) {
|
level = Integer.parseInt(enchantLevel[1]);
|
||||||
level = enchantment.getMaxLevel();
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new SignException(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ItemStack playerHand = player.getBase().getItemInHand();
|
final ItemStack playerHand = player.getBase().getItemInHand();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue