2011-04-03 20:21:20 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.Essentials;
|
2011-04-03 20:52:23 +00:00
|
|
|
import com.earth2me.essentials.InventoryWorkaround;
|
2011-04-03 20:21:20 +00:00
|
|
|
import com.earth2me.essentials.ItemDb;
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import org.bukkit.ChatColor;
|
2011-04-04 13:06:01 +00:00
|
|
|
import org.bukkit.Material;
|
2011-04-03 20:21:20 +00:00
|
|
|
import org.bukkit.Server;
|
2011-04-03 20:52:23 +00:00
|
|
|
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
2011-04-03 20:21:20 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
public class Commandunlimited extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandunlimited()
|
|
|
|
{
|
|
|
|
super("unlimited");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
|
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
2011-04-04 14:27:06 +00:00
|
|
|
user.sendMessage("§cUsage: /" + commandLabel + " [list|item] <player>");
|
2011-04-03 20:21:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-04 14:27:06 +00:00
|
|
|
|
2011-04-03 20:21:20 +00:00
|
|
|
User target = user;
|
|
|
|
|
|
|
|
if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) {
|
|
|
|
target = getPlayer(server, args, 1);
|
2011-04-04 14:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("list")) {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append("Unlimited items: ");
|
|
|
|
boolean first = true;
|
|
|
|
for (Integer integer : target.getUnlimited()) {
|
|
|
|
if (!first) {
|
|
|
|
sb.append(", ");
|
|
|
|
first = true;
|
|
|
|
}
|
|
|
|
String matname = Material.getMaterial(integer).toString().toLowerCase().replace("_", "-");
|
|
|
|
sb.append(matname);
|
|
|
|
}
|
|
|
|
user.sendMessage(sb.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack stack = ItemDb.get(args[0], 1);
|
2011-04-03 20:21:20 +00:00
|
|
|
|
2011-04-04 14:16:00 +00:00
|
|
|
String itemname = stack.getType().toString().toLowerCase().replace("_", "-");
|
|
|
|
if (!user.isAuthorized("essentials.unlimited.item-add") &&
|
|
|
|
!user.isAuthorized("essentials.unlimited.item-"+itemname)
|
|
|
|
&& !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET)
|
|
|
|
&& user.isAuthorized("essentials.unlimited.item-bucket"))) {
|
|
|
|
user.sendMessage(ChatColor.RED + "No permission for unlimited item "+itemname+".");
|
2011-04-04 13:06:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-03 20:21:20 +00:00
|
|
|
String itemName = stack.getType().name().toLowerCase().replace('_', ' ');
|
|
|
|
|
|
|
|
if (target.hasUnlimited(stack)) {
|
|
|
|
if (user != target) {
|
|
|
|
user.sendMessage("§7Disable unlimited placing of " + itemName + " for " + user.getDisplayName() + ".");
|
|
|
|
}
|
|
|
|
target.sendMessage("§7Disable unlimited placing of " + itemName + " for " + user.getDisplayName() + ".");
|
|
|
|
target.setUnlimited(stack, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
user.charge(this);
|
|
|
|
if (user != target) {
|
|
|
|
user.sendMessage("§7Giving unlimited amount of " + itemName + " to " + user.getDisplayName() + ".");
|
|
|
|
}
|
|
|
|
target.sendMessage("§7Giving unlimited amount of " + itemName + " to " + user.getDisplayName() + ".");
|
2011-04-03 20:52:23 +00:00
|
|
|
if (!InventoryWorkaround.containsItem((CraftInventory)target.getInventory(), true, stack)) {
|
|
|
|
target.getInventory().addItem(stack);
|
|
|
|
}
|
2011-04-03 20:21:20 +00:00
|
|
|
target.setUnlimited(stack, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|