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

55 lines
1.3 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import java.util.List;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
import org.bukkit.entity.Player;
public class Commandpay extends EssentialsCommand
{
public Commandpay()
{
super("pay");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 2)
{
throw new NotEnoughArgumentsException();
}
2013-03-19 23:24:06 +00:00
2013-02-03 04:14:23 +00:00
//TODO: TL this.
if (args[0].trim().length() < 2)
{
throw new NotEnoughArgumentsException("You need to specify a player to pay.");
}
double amount = Double.parseDouble(args[1].replaceAll("[^0-9\\.]", ""));
2013-03-19 23:24:06 +00:00
boolean skipHidden = !user.isAuthorized("essentials.vanish.interact");
2012-06-10 23:08:31 +00:00
boolean foundUser = false;
2013-03-19 23:24:06 +00:00
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
2013-03-19 23:24:06 +00:00
User player = ess.getUser(matchPlayer);
if (skipHidden && player.isHidden())
{
continue;
}
foundUser = true;
2013-03-19 23:24:06 +00:00
user.payUser(player, amount);
Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), player.getName(), new Trade(amount, ess), user.getLocation(), ess);
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
}