mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-24 14:33:51 +00:00

We now first test, if the user could pay it, do the stuff and then charge him. If the command throws an exception, the user will not be charged.
96 lines
2.3 KiB
Java
96 lines
2.3 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import com.earth2me.essentials.User;
|
|
import com.earth2me.essentials.Util;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Server;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
public class Commandpowertool extends EssentialsCommand
|
|
{
|
|
public Commandpowertool()
|
|
{
|
|
super("powertool");
|
|
}
|
|
|
|
@Override
|
|
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
|
{
|
|
ItemStack is = user.getItemInHand();
|
|
List<String> powertools = user.getPowertool(is);
|
|
if (is == null || is.getType() == Material.AIR)
|
|
{
|
|
throw new Exception(Util.i18n("powerToolAir"));
|
|
}
|
|
|
|
String itemName = is.getType().toString().toLowerCase().replaceAll("_", " ");
|
|
String command = getFinalArg(args, 0);
|
|
if (command != null && !command.isEmpty())
|
|
{
|
|
if (command.equalsIgnoreCase("l:"))
|
|
{
|
|
if (powertools == null || powertools.isEmpty())
|
|
{
|
|
throw new Exception(Util.format("powerToolListEmpty", itemName));
|
|
}
|
|
else
|
|
{
|
|
user.sendMessage(Util.format("powerToolList", Util.joinList(powertools), itemName));
|
|
}
|
|
return;
|
|
}
|
|
if (command.startsWith("r:"))
|
|
{
|
|
try
|
|
{
|
|
command = command.substring(2);
|
|
if (!powertools.contains(command))
|
|
{
|
|
throw new Exception(Util.format("powerToolNoSuchCommandAssigned", command, itemName));
|
|
}
|
|
|
|
powertools.remove(command);
|
|
user.sendMessage(Util.format("powerToolRemove", command, itemName));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
user.sendMessage(e.getMessage());
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (command.startsWith("a:"))
|
|
{
|
|
command = command.substring(2);
|
|
if(powertools.contains(command))
|
|
{
|
|
throw new Exception(Util.format("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(Util.format("powerToolAttach", Util.joinList(powertools), itemName));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
powertools.clear();
|
|
user.sendMessage(Util.format("powerToolRemoveAll", itemName));
|
|
}
|
|
|
|
user.setPowertool(is, powertools);
|
|
}
|
|
}
|