mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 17:47:34 +01:00
Added enchantment to /give and /item
Updated plugin.yml
This commit is contained in:
parent
b8f9a4b96f
commit
098072517a
@ -7,6 +7,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -16,6 +17,7 @@ import static com.earth2me.essentials.I18n._;
|
||||
public class Commandenchant extends EssentialsCommand
|
||||
{
|
||||
private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<String, Enchantment>();
|
||||
private static final transient Pattern NUMPATTERN = Pattern.compile("\\d+");
|
||||
|
||||
static
|
||||
{
|
||||
@ -89,20 +91,7 @@ public class Commandenchant extends EssentialsCommand
|
||||
level = -1;
|
||||
}
|
||||
}
|
||||
Enchantment enchantment = Enchantment.getByName(args[0].toUpperCase(Locale.ENGLISH));
|
||||
if (enchantment == null)
|
||||
{
|
||||
enchantment = ENCHANTMENTS.get(args[0].toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
if (enchantment == null)
|
||||
{
|
||||
throw new Exception(_("enchantmentNotFound"));
|
||||
}
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (!user.isAuthorized("essentials.enchant." + enchantmentName))
|
||||
{
|
||||
throw new Exception(_("enchantmentPerm", enchantmentName));
|
||||
}
|
||||
Enchantment enchantment = getEnchantment(args[0], user);
|
||||
if (level < enchantment.getStartLevel() || level > enchantment.getMaxLevel())
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
@ -110,6 +99,32 @@ public class Commandenchant extends EssentialsCommand
|
||||
stack.addEnchantment(enchantment, level);
|
||||
user.setItemInHand(stack);
|
||||
user.updateInventory();
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
user.sendMessage(_("enchantmentApplied", enchantmentName.replace('_', ' ')));
|
||||
}
|
||||
|
||||
public static Enchantment getEnchantment(final String name, final User user) throws Exception
|
||||
{
|
||||
|
||||
Enchantment enchantment;
|
||||
if (NUMPATTERN.matcher(name).matches()) {
|
||||
enchantment = Enchantment.getById(Integer.parseInt(name));
|
||||
} else {
|
||||
enchantment = Enchantment.getByName(name.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
if (enchantment == null)
|
||||
{
|
||||
enchantment = ENCHANTMENTS.get(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
if (enchantment == null)
|
||||
{
|
||||
throw new Exception(_("enchantmentNotFound"));
|
||||
}
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName))
|
||||
{
|
||||
throw new Exception(_("enchantmentPerm", enchantmentName));
|
||||
}
|
||||
return enchantment;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -44,6 +45,29 @@ public class Commandgive extends EssentialsCommand
|
||||
stack.setAmount(Integer.parseInt(args[2]));
|
||||
}
|
||||
|
||||
if (args.length > 3)
|
||||
{
|
||||
for (int i = 3; i < args.length; i++)
|
||||
{
|
||||
final String[] split = args[i].split("[:+',;.]", 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Enchantment enchantment = Commandenchant.getEnchantment(split[0], sender instanceof Player ? ess.getUser(sender) : null);
|
||||
int level;
|
||||
if (split.length > 1)
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getType() == Material.AIR)
|
||||
{
|
||||
throw new Exception(ChatColor.RED + "You can't give air.");
|
||||
|
@ -5,6 +5,7 @@ import com.earth2me.essentials.User;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@ -40,6 +41,29 @@ public class Commanditem extends EssentialsCommand
|
||||
stack.setAmount(Integer.parseInt(args[1]));
|
||||
}
|
||||
|
||||
if (args.length > 2)
|
||||
{
|
||||
for (int i = 2; i < args.length; i++)
|
||||
{
|
||||
final String[] split = args[i].split("[:+',;.]", 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Enchantment enchantment = Commandenchant.getEnchantment(split[0], user);
|
||||
int level;
|
||||
if (split.length > 1)
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getType() == Material.AIR)
|
||||
{
|
||||
throw new Exception(_("cantSpawnItem", "Air"));
|
||||
|
@ -129,7 +129,7 @@ public class BukkitConstructor extends Constructor
|
||||
for (int i = 2; i < split1.length; i++)
|
||||
{
|
||||
final String[] split3 = split1[0].split("[:+',;.]", 2);
|
||||
if (split3.length != 2)
|
||||
if (split3.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -148,7 +148,7 @@ public class BukkitConstructor extends Constructor
|
||||
continue;
|
||||
}
|
||||
int level = enchantment.getStartLevel();
|
||||
if (NUMPATTERN.matcher(split3[1]).matches())
|
||||
if (split3.length == 2 && NUMPATTERN.matcher(split3[1]).matches())
|
||||
{
|
||||
level = Integer.parseInt(split3[1]);
|
||||
}
|
||||
|
@ -79,6 +79,10 @@ commands:
|
||||
description: Manages the server economy.
|
||||
usage: /<command> <give|take|reset> <player> <amount>
|
||||
aliases: [economy,eeco,eeconomy]
|
||||
enchant:
|
||||
description: Enchants the item the user is holding.
|
||||
usage: /<command> <enchantmentname> [level]
|
||||
aliases: [enchantment]
|
||||
essentials:
|
||||
description: Reloads essentials.
|
||||
usage: /<command>
|
||||
@ -104,7 +108,7 @@ commands:
|
||||
aliases: [mem,memory,egc,emem,ememory]
|
||||
give:
|
||||
description: Give a player an item.
|
||||
usage: /<command> <player> <item|numeric> [amount]
|
||||
usage: /<command> <player> <item|numeric> [amount <enchantmentname[:level]> ...]
|
||||
aliases: [egive]
|
||||
god:
|
||||
description: Enables your godly powers.
|
||||
@ -140,7 +144,7 @@ commands:
|
||||
aliases: [einvsee]
|
||||
item:
|
||||
description: Spawn an item.
|
||||
usage: /<command> <item|numeric> [amount]
|
||||
usage: /<command> <item|numeric> [amount <enchantmentname[:level]> ...]
|
||||
aliases: [i,eitem]
|
||||
jails:
|
||||
description: List all jails.
|
||||
|
Loading…
Reference in New Issue
Block a user