Almost finished money refactoring

This commit is contained in:
Olof Larsson
2011-10-12 17:25:01 +02:00
parent d37a4d6ff7
commit b202acb685
29 changed files with 510 additions and 270 deletions

View File

@ -48,7 +48,7 @@ public class CmdBalance extends FCommand
return;
}
msg("<a>%s balance: %s", faction.getTag(fme), Econ.moneyString(faction.getMoney()));
msg("<a>%s balance: %s", faction.getTag(fme), Econ.moneyString(faction.getAccount().balance()));
}
}

View File

@ -3,10 +3,6 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
public class CmdDeposit extends FCommand
@ -33,11 +29,8 @@ public class CmdDeposit extends FCommand
public void perform()
{
if ( ! Conf.bankEnabled) return;
Faction faction = myFaction;
double amount = this.argAsDouble(0, 0);
Econ.transferMoney(fme, fme, myFaction, this.argAsDouble(0, 0));
/*
if( amount > 0.0 )
{
String amountString = Econ.moneyString(amount);
@ -61,7 +54,7 @@ public class CmdDeposit extends FCommand
}
}
}
}
}*/
}
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
@ -71,10 +70,13 @@ public class CmdDisband extends FCommand
}
}
if (Conf.bankEnabled)
if (Econ.shouldBeUsed())
{
double amount = faction.getMoney();
Econ.addMoney(fme.getId(), amount); //Give all the faction's money to the disbander
//Give all the faction's money to the disbander
double amount = faction.getAccount().balance();
fme.getAccount().add(amount);
faction.getAccount().remove();
if (amount > 0.0)
{
String amountString = Econ.moneyString(amount);

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
@ -84,7 +83,7 @@ public class CmdHelp extends FCommand
pageLines.add( p.cmdBase.cmdSethome.getUseageTemplate() );
helpPages.add(pageLines);
if (Econ.enabled() && Conf.bankEnabled)
if (Econ.shouldBeUsed())
{
pageLines = new ArrayList<String>();
pageLines.add( "" );

View File

@ -101,7 +101,7 @@ public class CmdHome extends FCommand
continue;
FPlayer fp = FPlayers.i.get(p);
if (fme.getRelation(fp) != Relation.ENEMY)
if (fme.getRelationTo(fp) != Relation.ENEMY)
continue;
Location l = p.getLocation();

View File

@ -49,16 +49,16 @@ public class CmdPay extends FCommand
{
String amountString = Econ.moneyString(amount);
if( amount > us.getMoney() )
if( amount > us.getAccount().balance() )
{
amount = us.getMoney();
amount = us.getAccount().balance();
}
us.removeMoney(amount);
them.addMoney(amount);
us.getAccount().subtract(amount);
them.getAccount().add(amount);
msg("<i>You have paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
msg("<i>"+us.getTag()+" now has "+Econ.moneyString(us.getMoney()));
msg("<i>"+us.getTag()+" now has "+Econ.moneyString(us.getAccount().balance()));
P.p.log(fme.getName() + " paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayers.i.getOnline())

View File

@ -69,7 +69,7 @@ public class CmdShow extends FCommand
}
// show the land value
if (Econ.enabled())
if (Econ.shouldBeUsed())
{
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
double refund = value * Conf.econClaimRefundMultiplier;
@ -82,7 +82,7 @@ public class CmdShow extends FCommand
//Show bank contents
if(Conf.bankEnabled) {
msg("<a>Bank contains: <i>"+Econ.moneyString(faction.getMoney()));
msg("<a>Bank contains: <i>"+Econ.moneyString(faction.getAccount().balance()));
}
}
@ -98,11 +98,11 @@ public class CmdShow extends FCommand
continue;
}
listpart = otherFaction.getTag(fme)+p.txt.parse("<i>")+", ";
if (otherFaction.getRelation(faction).isAlly())
if (otherFaction.getRelationTo(faction).isAlly())
{
allyList += listpart;
}
else if (otherFaction.getRelation(faction).isEnemy())
else if (otherFaction.getRelationTo(faction).isEnemy())
{
enemyList += listpart;
}

View File

@ -29,7 +29,7 @@ public class CmdUnclaimall extends FCommand
public void perform()
{
String moneyBack = "<i>";
if (Econ.enabled())
if (Econ.shouldBeUsed())
{
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
// a real refund

View File

@ -2,12 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdWithdraw extends FCommand
@ -34,7 +29,9 @@ public class CmdWithdraw extends FCommand
{
if ( ! Conf.bankEnabled) return;
if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR))
Econ.transferMoney(fme, myFaction, fme, this.argAsDouble(0, 0));
/*if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR))
{
msg("<b>Only faction moderators or admins are able to withdraw from the bank.");
return;
@ -69,7 +66,7 @@ public class CmdWithdraw extends FCommand
fplayer.msg("%s<i> has withdrawn %s", fme.getNameAndRelevant(fplayer), amountString);
}
}
}
}*/
}
}

View File

@ -275,14 +275,25 @@ public abstract class FCommand extends MCommand<P>
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
public boolean payForCommand(double cost)
{
if ( ! Econ.enabled() || this.fme == null || cost == 0.0 || fme.isAdminBypassing())
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing())
{
return true;
}
String desc = this.getHelpShort().toLowerCase();
Faction faction = fme.getFaction();
if(Conf.bankFactionPaysLandCosts && fme.hasFaction())
{
if ( ! Econ.modifyMoney(myFaction, -cost, "to "+desc, "for "+desc)) return false;
}
else
{
if ( ! Econ.modifyMoney(fme, -cost, "to "+desc, "for "+desc)) return false;
}
return true;
/*
// pay up
if (cost > 0.0)
@ -290,7 +301,7 @@ public abstract class FCommand extends MCommand<P>
String costString = Econ.moneyString(cost);
if(Conf.bankFactionPaysCosts && fme.hasFaction() )
{
if(!faction.removeMoney(cost))
if( ! faction.getAccount().subtract(cost))
{
sendMessage("It costs "+costString+" to "+desc+", which your faction can't currently afford.");
return false;
@ -303,7 +314,7 @@ public abstract class FCommand extends MCommand<P>
}
else
{
if (!Econ.deductMoney(fme.getName(), cost))
if ( ! Econ.deductMoney(fme.getName(), cost))
{
sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford.");
return false;
@ -318,7 +329,7 @@ public abstract class FCommand extends MCommand<P>
if(Conf.bankFactionPaysCosts && fme.hasFaction() )
{
faction.addMoney(-cost);
faction.getAccount().add(-cost);
sendMessage(faction.getTag()+" has been paid "+costString+" to "+desc+".");
}
else
@ -329,6 +340,6 @@ public abstract class FCommand extends MCommand<P>
sendMessage("You have been paid "+costString+" to "+desc+".");
}
return true;
return true;*/
}
}

View File

@ -49,7 +49,7 @@ public abstract class FRelationCommand extends FCommand
if ( ! payForCommand(targetRelation.getRelationCost())) return;
myFaction.setRelationWish(them, targetRelation);
Relation currentRelation = myFaction.getRelation(them, true);
Relation currentRelation = myFaction.getRelationTo(them, true);
ChatColor currentRelationColor = currentRelation.getColor();
if (targetRelation.value == currentRelation.value)
{