mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-04 19:46:27 +00:00
Allow unsafe enchantments in /item /give /kit and /enchant
Needs enabled in config file manually.
This commit is contained in:
parent
d551e8c6d2
commit
ed88f8aa06
7 changed files with 67 additions and 20 deletions
|
@ -151,6 +151,8 @@ public interface ISettings extends IConf
|
||||||
Set<String> getNoGodWorlds();
|
Set<String> getNoGodWorlds();
|
||||||
|
|
||||||
boolean getUpdateBedAtDaytime();
|
boolean getUpdateBedAtDaytime();
|
||||||
|
|
||||||
|
boolean allowUnsafeEnchantments();
|
||||||
|
|
||||||
boolean getRepairEnchanted();
|
boolean getRepairEnchanted();
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,13 @@ public class Kit
|
||||||
{
|
{
|
||||||
throw new Exception(_("kitError"), ex);
|
throw new Exception(_("kitError"), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public class Kit
|
||||||
|
|
||||||
// When was the last kit used?
|
// When was the last kit used?
|
||||||
final long lastTime = user.getKitTimestamp(kitName);
|
final long lastTime = user.getKitTimestamp(kitName);
|
||||||
|
|
||||||
if (lastTime < earliestLong || lastTime == 0L)
|
if (lastTime < earliestLong || lastTime == 0L)
|
||||||
{
|
{
|
||||||
user.setKitTimestamp(kitName, time.getTimeInMillis());
|
user.setKitTimestamp(kitName, time.getTimeInMillis());
|
||||||
|
@ -80,15 +81,15 @@ public class Kit
|
||||||
throw new NoChargeException();
|
throw new NoChargeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getItems(final User user, final Map<String, Object> kit) throws Exception
|
public static List<String> getItems(final User user, final Map<String, Object> kit) throws Exception
|
||||||
{
|
{
|
||||||
if (kit == null)
|
if (kit == null)
|
||||||
{
|
{
|
||||||
throw new Exception(_("kitError2"));
|
throw new Exception(_("kitError2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (List<String>)kit.get("items");
|
return (List<String>)kit.get("items");
|
||||||
|
@ -99,7 +100,7 @@ public class Kit
|
||||||
throw new Exception(_("kitErrorHelp"), e);
|
throw new Exception(_("kitErrorHelp"), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void expandItems(final IEssentials ess, final User user, final List<String> items) throws Exception
|
public static void expandItems(final IEssentials ess, final User user, final List<String> items) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -107,7 +108,7 @@ public class Kit
|
||||||
boolean spew = false;
|
boolean spew = false;
|
||||||
for (String d : items)
|
for (String d : items)
|
||||||
{
|
{
|
||||||
if (d.startsWith(ess.getSettings().getCurrencySymbol()))
|
if (d.startsWith(ess.getSettings().getCurrencySymbol()))
|
||||||
{
|
{
|
||||||
Double value = Double.parseDouble(d.substring(ess.getSettings().getCurrencySymbol().length()).trim());
|
Double value = Double.parseDouble(d.substring(ess.getSettings().getCurrencySymbol().length()).trim());
|
||||||
Trade t = new Trade(value, ess);
|
Trade t = new Trade(value, ess);
|
||||||
|
@ -119,7 +120,7 @@ public class Kit
|
||||||
final int id = Material.getMaterial(Integer.parseInt(item[0])).getId();
|
final int id = Material.getMaterial(Integer.parseInt(item[0])).getId();
|
||||||
final short data = item.length > 1 ? Short.parseShort(item[1]) : 0;
|
final short data = item.length > 1 ? Short.parseShort(item[1]) : 0;
|
||||||
final int amount = parts.length > 1 ? Integer.parseInt(parts[1]) : 1;
|
final int amount = parts.length > 1 ? Integer.parseInt(parts[1]) : 1;
|
||||||
|
|
||||||
final ItemStack stack = new ItemStack(id, amount, data);
|
final ItemStack stack = new ItemStack(id, amount, data);
|
||||||
if (parts.length > 2)
|
if (parts.length > 2)
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -154,7 +162,7 @@ public class Kit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<Integer, ItemStack> overfilled;
|
final Map<Integer, ItemStack> overfilled;
|
||||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -856,6 +856,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()
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class Commanditem extends EssentialsCommand
|
||||||
{
|
{
|
||||||
super("item");
|
super("item");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ public class Commanditem extends EssentialsCommand
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
final ItemStack stack = ess.getItemDb().get(args[0]);
|
final ItemStack stack = ess.getItemDb().get(args[0]);
|
||||||
|
|
||||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||||
if (ess.getSettings().permissionBasedItemSpawn()
|
if (ess.getSettings().permissionBasedItemSpawn()
|
||||||
? (!user.isAuthorized("essentials.itemspawn.item-all")
|
? (!user.isAuthorized("essentials.itemspawn.item-all")
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,12 +84,12 @@ public class Commanditem extends EssentialsCommand
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getType() == Material.AIR)
|
if (stack.getType() == Material.AIR)
|
||||||
{
|
{
|
||||||
throw new Exception(_("cantSpawnItem", "Air"));
|
throw new Exception(_("cantSpawnItem", "Air"));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
|
final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
|
||||||
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
|
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
|
||||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue