TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java
snowleo 6427a93d14 Correctly charge for the use of commands.
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.
2011-08-27 23:14:49 +02:00

37 lines
1,023 B
Java

package com.earth2me.essentials.commands;
import org.bukkit.Server;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.command.CommandSender;
public class Commandbalance extends EssentialsCommand
{
public Commandbalance()
{
super("balance");
}
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
sender.sendMessage(Util.format("balance", Util.formatCurrency(getPlayer(server, args, 0, true).getMoney(), ess)));
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
double bal = (args.length < 1
|| !(user.isAuthorized("essentials.balance.others")
|| user.isAuthorized("essentials.balance.other"))
? user
: getPlayer(server, args, 0, true)).getMoney();
user.sendMessage(Util.format("balance", Util.formatCurrency(bal, ess)));
}
}