2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
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.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandgive extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandgive()
|
|
|
|
{
|
|
|
|
super("give");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(Server server, Essentials parent, CommandSender sender, String commandLabel, String[] args) throws Exception
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "Usage: /" + commandLabel + " [player] [item]<:data> <amount>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] itemArgs = args[1].split("[^a-zA-Z0-9]");
|
|
|
|
ItemStack stack = ItemDb.get(itemArgs[0]);
|
|
|
|
|
|
|
|
if(sender instanceof Player && !User.get(sender).isAuthorized("essentials.itemspawn.exempt") && !User.get(sender).canSpawnItem(stack.getTypeId()))
|
|
|
|
{
|
|
|
|
sender.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
|
|
|
}
|
|
|
|
if (args.length > 2 && Integer.parseInt(args[2]) > 0) {
|
2011-03-19 22:39:51 +00:00
|
|
|
stack.setAmount(Integer.parseInt(args[2]));
|
2011-04-01 23:06:44 +00:00
|
|
|
}
|
2011-04-21 10:08:44 +00:00
|
|
|
|
|
|
|
if (stack.getType() == Material.AIR) {
|
|
|
|
sender.sendMessage(ChatColor.RED + "You can't give air.");
|
|
|
|
return;
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
User giveTo = getPlayer(server, args, 0);
|
|
|
|
String itemName = stack.getType().name().toLowerCase().replace('_', ' ');
|
2011-04-01 23:06:44 +00:00
|
|
|
if (sender instanceof Player) {
|
2011-03-19 22:39:51 +00:00
|
|
|
User.get(sender).charge(this);
|
2011-04-01 23:06:44 +00:00
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
|
|
|
|
giveTo.getInventory().addItem(stack);
|
|
|
|
}
|
|
|
|
}
|