TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java

112 lines
2.8 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.ArrayList;
2011-08-21 18:02:01 +00:00
import java.util.List;
import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
public class Commandpowertool extends EssentialsCommand
{
public Commandpowertool()
{
super("powertool");
}
@Override
2011-08-29 23:14:03 +00:00
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
2011-09-10 09:39:35 +00:00
String command = getFinalArg(args, 0);
// check to see if this is a clear all command
if (command != null && command.equalsIgnoreCase("d:"))
2011-09-10 09:39:35 +00:00
{
user.clearAllPowertools();
user.sendMessage(_("powerToolClearAll"));
2011-09-10 09:39:35 +00:00
return;
}
2011-11-04 16:42:03 +00:00
2011-08-29 23:14:03 +00:00
final ItemStack itemStack = user.getItemInHand();
if (itemStack == null || itemStack.getType() == Material.AIR)
{
throw new Exception(_("powerToolAir"));
}
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
2011-08-29 23:14:03 +00:00
List<String> powertools = user.getPowertool(itemStack);
if (command != null && !command.isEmpty())
{
2011-08-27 01:54:45 +00:00
if (command.equalsIgnoreCase("l:"))
{
2011-08-21 18:02:01 +00:00
if (powertools == null || powertools.isEmpty())
{
throw new Exception(_("powerToolListEmpty", itemName));
}
else
{
user.sendMessage(_("powerToolList", Util.joinList(powertools), itemName));
}
2012-04-03 23:40:58 +00:00
throw new NoChargeException();
}
if (command.startsWith("r:"))
{
2012-04-03 23:40:58 +00:00
command = command.substring(2);
if (!powertools.contains(command))
{
2012-04-03 23:40:58 +00:00
throw new Exception(_("powerToolNoSuchCommandAssigned", command, itemName));
}
2012-04-03 23:40:58 +00:00
powertools.remove(command);
user.sendMessage(_("powerToolRemove", command, itemName));
}
else
{
if (command.startsWith("a:"))
{
if (!user.isAuthorized("essentials.powertool.append"))
{
throw new Exception(_("noPerm", "essentials.powertool.append"));
}
command = command.substring(2);
2011-08-29 23:14:03 +00:00
if (powertools.contains(command))
{
throw new Exception(_("powerToolAlreadySet", command, itemName));
}
}
else if (powertools != null && !powertools.isEmpty())
{
// Replace all commands with this one
powertools.clear();
}
else
{
powertools = new ArrayList<String>();
}
powertools.add(command);
user.sendMessage(_("powerToolAttach", Util.joinList(powertools), itemName));
}
}
else
{
2011-08-29 23:14:03 +00:00
if (powertools != null)
{
powertools.clear();
}
user.sendMessage(_("powerToolRemoveAll", itemName));
}
2012-04-03 23:40:58 +00:00
if (!user.arePowerToolsEnabled())
{
user.setPowerToolsEnabled(true);
user.sendMessage(_("powerToolsEnabled"));
}
2011-08-29 23:14:03 +00:00
user.setPowertool(itemStack, powertools);
}
}