Allow unsafe enchantments in /item /give /kit and /enchant

Needs enabled in config file manually.
This commit is contained in:
KHobbits 2012-12-29 08:35:52 +00:00
parent d551e8c6d2
commit ed88f8aa06
7 changed files with 67 additions and 20 deletions

View File

@ -152,6 +152,8 @@ public interface ISettings extends IConf
boolean getUpdateBedAtDaytime(); boolean getUpdateBedAtDaytime();
boolean allowUnsafeEnchantments();
boolean getRepairEnchanted(); boolean getRepairEnchanted();
boolean isWorldTeleportPermissions(); boolean isWorldTeleportPermissions();

View File

@ -39,7 +39,8 @@ public class Kit
public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws Exception public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws Exception
{ {
if (user.isAuthorized("essentials.kit.exemptdelay")) { if (user.isAuthorized("essentials.kit.exemptdelay"))
{
return; return;
} }
@ -145,9 +146,16 @@ public class Kit
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
try try
{
if (ess.getSettings().allowUnsafeEnchantments())
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{ {
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
}
catch (Exception ex) catch (Exception ex)
{ {
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);

View File

@ -857,6 +857,12 @@ public class Settings implements ISettings
return config.getBoolean("repair-enchanted", true); return config.getBoolean("repair-enchanted", true);
} }
@Override
public boolean allowUnsafeEnchantments()
{
return config.getBoolean("unsafe-enchantments", false);
}
@Override @Override
public boolean isWorldTeleportPermissions() public boolean isWorldTeleportPermissions()
{ {

View File

@ -56,7 +56,8 @@ public class Commandenchant extends EssentialsCommand
} }
} }
final Enchantment enchantment = getEnchantment(args[0], user); final Enchantment enchantment = getEnchantment(args[0], user);
if (level < 0 || level > enchantment.getMaxLevel()) final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe");
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel()))
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
@ -65,9 +66,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.getInventory().setItemInHand(stack); user.getInventory().setItemInHand(stack);
user.updateInventory(); user.updateInventory();
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);

View File

@ -81,9 +81,21 @@ public class Commandgive extends EssentialsCommand
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
if (allowUnsafe && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.enchant.allowunsafe"))
{
allowUnsafe = false;
}
if (allowUnsafe)
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
} }
}
if (stack.getType() == Material.AIR) if (stack.getType() == Material.AIR)
{ {

View File

@ -69,10 +69,17 @@ public class Commanditem extends EssentialsCommand
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
if (ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe"))
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
} }
} }
}
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();

View File

@ -334,6 +334,10 @@ oversized-stacksize: 64
# essentials.repair.enchanted # essentials.repair.enchanted
repair-enchanted: true repair-enchanted: true
# Allow 'unsafe' enchantments in kits and item spawning.
# Warning: Mixing and overleveling some enchantments can cause issues with clients, servers and plugins.
unsafe-enchantments: false
#Do you want essentials to keep track of previous location for /back in the teleport listener? #Do you want essentials to keep track of previous location for /back in the teleport listener?
#If you set this to true any plugin that uses teleport will have the previous location registered. #If you set this to true any plugin that uses teleport will have the previous location registered.
register-back-in-listener: false register-back-in-listener: false