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;
} }
@ -146,7 +147,14 @@ public class Kit
} }
try try
{ {
stack.addEnchantment(enchantment, level); if (ess.getSettings().allowUnsafeEnchantments())
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level);
}
} }
catch (Exception ex) catch (Exception 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();
} }
@ -66,7 +67,14 @@ public class Commandenchant extends EssentialsCommand
} }
else else
{ {
stack.addEnchantment(enchantment, level); if (allowUnsafe)
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level);
}
} }
user.getInventory().setItemInHand(stack); user.getInventory().setItemInHand(stack);
user.updateInventory(); user.updateInventory();

View File

@ -81,7 +81,19 @@ public class Commandgive extends EssentialsCommand
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
stack.addEnchantment(enchantment, level); 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);
}
} }
} }

View File

@ -69,7 +69,14 @@ public class Commanditem extends EssentialsCommand
{ {
level = enchantment.getMaxLevel(); level = enchantment.getMaxLevel();
} }
stack.addEnchantment(enchantment, level); if (ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe"))
{
stack.addUnsafeEnchantment(enchantment, level);
}
else
{
stack.addEnchantment(enchantment, level);
}
} }
} }
} }

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