Factions/src/com/massivecraft/factions/commands/FCommandWithdraw.java

66 lines
1.6 KiB
Java
Raw Normal View History

2011-09-24 03:22:53 +02:00
package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandWithdraw extends FBaseCommand {
public FCommandWithdraw() {
aliases.add("withdraw");
helpDescription = "Withdraw money from your faction's bank";
requiredParameters.add("amount");
}
@Override
public void perform() {
if ( ! assertHasFaction()) {
return;
}
if (!Conf.bankEnabled) {
return;
}
if ( !Conf.bankMembersCanWithdraw && !assertMinRole(Role.MODERATOR)) {
sendMessage("Only faction moderators or admins are able to withdraw from the bank.");
return;
}
double amount = 0.0;
Faction faction = me.getFaction();
if (parameters.size() == 1) {
try {
amount = Double.parseDouble(parameters.get(0));
} catch (NumberFormatException e) {
// wasn't valid
}
}
String amountString = Econ.moneyString(amount);
if( amount > 0.0 ) {
if( amount > faction.getMoney() ) {
amount = faction.getMoney();
}
faction.removeMoney(amount);
Econ.addMoney(me.getName(), amount);
sendMessage("You have withdrawn "+amountString+" from "+faction.getTag()+"'s bank.");
sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == faction) {
fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" has withdrawn "+amountString);
}
}
}
}
}