1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-30 01:39:51 +02:00

Allow unsafe enchantments in /item /give /enchant with permissions.

This commit is contained in:
snowleo
2012-10-16 21:24:00 +02:00
parent d056b9e436
commit c644eb1ee2
4 changed files with 29 additions and 4 deletions

View File

@@ -50,8 +50,9 @@ public class Commandenchant extends EssentialsCommand
level = -1; level = -1;
} }
} }
final boolean allowUnsafe = Permissions.ENCHANT_UNSAFE.isAuthorized(user);
final Enchantment enchantment = getEnchantment(args[0], user); final Enchantment enchantment = getEnchantment(args[0], user);
if (level < 0 || level > enchantment.getMaxLevel()) if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel()))
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
@@ -60,9 +61,16 @@ public class Commandenchant extends EssentialsCommand
stack.removeEnchantment(enchantment); stack.removeEnchantment(enchantment);
} }
else else
{
if (allowUnsafe)
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{ {
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
}
user.getPlayer().getInventory().setItemInHand(stack); user.getPlayer().getInventory().setItemInHand(stack);
user.getPlayer().updateInventory(); user.getPlayer().updateInventory();
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);

View File

@@ -60,9 +60,16 @@ public class Commandgive extends EssentialsCommand
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
if (Permissions.GIVE_ENCHANTED_UNSAFE.isAuthorized(sender))
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
} }
}
if (stack.getTypeId() == 0) if (stack.getTypeId() == 0)
{ {

View File

@@ -56,9 +56,16 @@ public class Commanditem extends EssentialsCommand
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
if (Permissions.ITEM_ENCHANTED_UNSAFE.isAuthorized(sender))
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
} }
}
if (stack.getTypeId() == 0) if (stack.getTypeId() == 0)
{ {

View File

@@ -27,6 +27,7 @@ public enum Permissions implements IPermission
CLEARINVENTORY_OTHERS, CLEARINVENTORY_OTHERS,
DELHOME_OTHERS, DELHOME_OTHERS,
ECO_LOAN(PermissionDefault.FALSE), ECO_LOAN(PermissionDefault.FALSE),
ENCHANT_UNSAFE(PermissionDefault.FALSE),
ENDERCHEST_OTHERS, ENDERCHEST_OTHERS,
ESSENTIALS, ESSENTIALS,
EXP_GIVE, EXP_GIVE,
@@ -42,6 +43,7 @@ public enum Permissions implements IPermission
GETPOS_OTHERS, GETPOS_OTHERS,
GOD_OTHERS, GOD_OTHERS,
GIVE_ENCHANTED, GIVE_ENCHANTED,
GIVE_ENCHANTED_UNSAFE(PermissionDefault.FALSE),
HEAL_COOLDOWN_BYPASS, HEAL_COOLDOWN_BYPASS,
HEAL_OTHERS, HEAL_OTHERS,
HELPOP_RECEIVE, HELPOP_RECEIVE,
@@ -51,6 +53,7 @@ public enum Permissions implements IPermission
INVSEE_MODIFY, INVSEE_MODIFY,
INVSEE_PREVENT_MODIFY, INVSEE_PREVENT_MODIFY,
ITEM_ENCHANTED, ITEM_ENCHANTED,
ITEM_ENCHANTED_UNSAFE(PermissionDefault.FALSE),
KEEPXP, KEEPXP,
KICK_EXEMPT, KICK_EXEMPT,
KICK_NOTIFY, KICK_NOTIFY,