2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import com.earth2me.essentials.Essentials;
|
|
|
|
import com.earth2me.essentials.ItemDb;
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import org.bukkit.ChatColor;
|
2011-04-21 10:08:44 +00:00
|
|
|
import org.bukkit.Material;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commanditem extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commanditem()
|
|
|
|
{
|
|
|
|
super("item");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
|
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
user.sendMessage("§cUsage: /" + commandLabel + " [item] <amount>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String[] itemArgs = args[0].split("[^a-zA-Z0-9]");
|
|
|
|
ItemStack stack = ItemDb.get(itemArgs[0]);
|
|
|
|
|
|
|
|
if(!user.isAuthorized("essentials.itemspawn.exempt") && !user.canSpawnItem(stack.getTypeId()))
|
|
|
|
{
|
|
|
|
user.sendMessage(ChatColor.RED + "You are not allowed to spawn that item");
|
|
|
|
return;
|
|
|
|
}
|
2011-04-01 23:06:44 +00:00
|
|
|
if (itemArgs.length > 1) {
|
2011-03-19 22:39:51 +00:00
|
|
|
stack.setDurability(Short.parseShort(itemArgs[1]));
|
2011-04-01 23:06:44 +00:00
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2011-04-01 23:06:44 +00:00
|
|
|
if (args.length > 1 && Integer.parseInt(args[1]) > 0) {
|
2011-03-19 22:39:51 +00:00
|
|
|
stack.setAmount(Integer.parseInt(args[1]));
|
2011-04-01 23:06:44 +00:00
|
|
|
}
|
2011-04-21 10:08:44 +00:00
|
|
|
|
|
|
|
if (stack.getType() == Material.AIR) {
|
|
|
|
user.sendMessage(ChatColor.RED + "You can't get air.");
|
|
|
|
return;
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
String itemName = stack.getType().name().toLowerCase().replace('_', ' ');
|
|
|
|
user.charge(this);
|
|
|
|
user.sendMessage("§7Giving " + stack.getAmount() + " of " + itemName + " to " + user.getDisplayName() + ".");
|
|
|
|
user.getInventory().addItem(stack);
|
|
|
|
}
|
|
|
|
}
|