Merge branch 'banks' of git://github.com/eXeC64/Factions

This commit is contained in:
Brettflan 2011-10-01 03:45:28 -05:00
commit 4cab42ec6e
15 changed files with 378 additions and 26 deletions

View File

@ -22,6 +22,12 @@ public class Conf {
public static ChatColor colorCommand = ChatColor.AQUA; public static ChatColor colorCommand = ChatColor.AQUA;
public static ChatColor colorParameter = ChatColor.DARK_AQUA; public static ChatColor colorParameter = ChatColor.DARK_AQUA;
//Money
public static boolean bankEnabled = true;
public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction
public static boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome
public static boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs.
// Power // Power
public static double powerPlayerMax = 10.0; public static double powerPlayerMax = 10.0;
public static double powerPlayerMin = -10.0; public static double powerPlayerMin = -10.0;

View File

@ -624,12 +624,24 @@ public class FPlayer {
if (Econ.enabled() && !Conf.adminBypassPlayers.contains(this.playerName)) { if (Econ.enabled() && !Conf.adminBypassPlayers.contains(this.playerName)) {
double cost = Econ.calculateClaimCost(ownedLand, otherFaction.isNormal()); double cost = Econ.calculateClaimCost(ownedLand, otherFaction.isNormal());
String costString = Econ.moneyString(cost); String costString = Econ.moneyString(cost);
if(Conf.bankFactionPaysLandCosts && this.hasFaction()) {
Faction faction = this.getFaction();
if(!faction.removeMoney(cost)) {
sendMessage("It costs "+costString+" to claim this land, which your faction can't currently afford.");
return false;
} else {
sendMessage(faction.getTag()+" has paid "+costString+" to claim some land.");
}
} else {
if (!Econ.deductMoney(this.playerName, cost)) { if (!Econ.deductMoney(this.playerName, cost)) {
sendMessage("Claiming this land will cost "+costString+", which you can't currently afford."); sendMessage("Claiming this land will cost "+costString+", which you can't currently afford.");
return false; return false;
} }
sendMessage("You have paid "+costString+" to claim this land."); sendMessage("You have paid "+costString+" to claim this land.");
} }
}
// announce success // announce success
if (otherFaction.isNormal()) { if (otherFaction.isNormal()) {

View File

@ -39,6 +39,7 @@ public class Faction {
private String description; private String description;
private Location home; private Location home;
private transient long lastPlayerLoggedOffTime; private transient long lastPlayerLoggedOffTime;
private double money;
// -------------------------------------------- // // -------------------------------------------- //
// Construct // Construct
@ -54,6 +55,7 @@ public class Faction {
this.peaceful = false; this.peaceful = false;
this.peacefulExplosionsEnabled = false; this.peacefulExplosionsEnabled = false;
this.permanent = false; this.permanent = false;
this.money = 0.0;
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -592,6 +594,30 @@ public class Faction {
return false; return false;
} }
public double getMoney() {
return this.money;
}
public boolean addMoney(double amount) {
if ( amount > 0.0 )
{
this.money += amount;
return true;
}
return false;
}
public boolean removeMoney( double amount ) {
if (amount <= 0.0 )
return false;
if (amount > this.money )
return false;
this.money -= amount;
return true;
}
//----------------------------------------------// //----------------------------------------------//
// Persistance and entity management // Persistance and entity management

View File

@ -98,12 +98,14 @@ public class Factions extends JavaPlugin {
commands.add(new FCommandAutoClaim()); commands.add(new FCommandAutoClaim());
commands.add(new FCommandAutoSafeclaim()); commands.add(new FCommandAutoSafeclaim());
commands.add(new FCommandAutoWarclaim()); commands.add(new FCommandAutoWarclaim());
commands.add(new FCommandBalance());
commands.add(new FCommandBypass()); commands.add(new FCommandBypass());
commands.add(new FCommandChat()); commands.add(new FCommandChat());
commands.add(new FCommandClaim()); commands.add(new FCommandClaim());
commands.add(new FCommandConfig()); commands.add(new FCommandConfig());
commands.add(new FCommandCreate()); commands.add(new FCommandCreate());
commands.add(new FCommandDeinvite()); commands.add(new FCommandDeinvite());
commands.add(new FCommandDeposit());
commands.add(new FCommandDescription()); commands.add(new FCommandDescription());
commands.add(new FCommandDisband()); commands.add(new FCommandDisband());
commands.add(new FCommandHome()); commands.add(new FCommandHome());
@ -119,6 +121,7 @@ public class Factions extends JavaPlugin {
commands.add(new FCommandOpen()); commands.add(new FCommandOpen());
commands.add(new FCommandOwner()); commands.add(new FCommandOwner());
commands.add(new FCommandOwnerList()); commands.add(new FCommandOwnerList());
commands.add(new FCommandPay());
commands.add(new FCommandPower()); commands.add(new FCommandPower());
commands.add(new FCommandPeaceful()); commands.add(new FCommandPeaceful());
commands.add(new FCommandPermanent()); commands.add(new FCommandPermanent());
@ -138,6 +141,7 @@ public class Factions extends JavaPlugin {
commands.add(new FCommandVersion()); commands.add(new FCommandVersion());
commands.add(new FCommandWarclaim()); commands.add(new FCommandWarclaim());
commands.add(new FCommandWarunclaimall()); commands.add(new FCommandWarunclaimall());
commands.add(new FCommandWithdraw());
// Ensure base folder exists! // Ensure base folder exists!
this.getDataFolder().mkdirs(); this.getDataFolder().mkdirs();

View File

@ -253,19 +253,40 @@ public class FBaseCommand {
String desc = this.helpDescription.toLowerCase(); String desc = this.helpDescription.toLowerCase();
Faction faction = me.getFaction();
// pay up // pay up
if (cost > 0.0) { if (cost > 0.0) {
String costString = Econ.moneyString(cost); String costString = Econ.moneyString(cost);
if(Conf.bankFactionPaysCosts && me.hasFaction() ) {
if(!faction.removeMoney(cost)) {
sendMessage("It costs "+costString+" to "+desc+", which your faction can't currently afford.");
return false;
} else {
sendMessage(faction.getTag()+" has paid "+costString+" to "+desc+".");
}
} else {
if (!Econ.deductMoney(me.getName(), cost)) { if (!Econ.deductMoney(me.getName(), cost)) {
sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford."); sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford.");
return false; return false;
} }
sendMessage("You have paid "+costString+" to "+desc+"."); sendMessage("You have paid "+costString+" to "+desc+".");
} }
}
// wait... we pay you to use this command? // wait... we pay you to use this command?
else { else {
String costString = Econ.moneyString(-cost); String costString = Econ.moneyString(-cost);
if(Conf.bankFactionPaysCosts && me.hasFaction() ) {
faction.addMoney(-cost);
sendMessage(faction.getTag()+" has been paid "+costString+" to "+desc+".");
} else {
Econ.addMoney(me.getName(), -cost); Econ.addMoney(me.getName(), -cost);
}
sendMessage("You have been paid "+costString+" to "+desc+"."); sendMessage("You have been paid "+costString+" to "+desc+".");
} }
return true; return true;

View File

@ -0,0 +1,41 @@
package com.massivecraft.factions.commands;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ;
import com.massivecraft.factions.Faction;
public class FCommandBalance extends FBaseCommand {
public FCommandBalance() {
aliases.add("balance");
aliases.add("money");
optionalParameters.add("faction name");
helpDescription = "Shows a faction's current balance";
}
@Override
public void perform() {
if ( ! assertHasFaction()) {
return;
}
if (!Conf.bankEnabled) {
return;
}
Faction faction;
if (parameters.size() > 0) {
faction = findFaction(parameters.get(0), true);
} else {
faction = me.getFaction();
}
sendMessage(Conf.colorChrome+faction.getTag()+" balance: "+ Econ.moneyString(faction.getMoney()));
}
}

View File

@ -0,0 +1,60 @@
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;
public class FCommandDeposit extends FBaseCommand {
public FCommandDeposit() {
aliases.add("deposit");
helpDescription = "Deposit money into your faction's bank";
requiredParameters.add("amount");
}
@Override
public void perform() {
if ( ! assertHasFaction()) {
return;
}
if (!Conf.bankEnabled) {
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( !Econ.deductMoney(me.getName(), amount ) ) {
sendMessage("You cannot afford to deposit that much.");
}
else
{
faction.addMoney(amount);
sendMessage("You have deposited "+amountString+" into "+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 deposited "+amountString);
}
}
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.commands; package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
@ -67,6 +68,11 @@ public class FCommandDisband extends FBaseCommand {
fplayer.sendMessage((senderIsConsole ? "A server admin" : me.getNameAndRelevant(fplayer))+Conf.colorSystem+" disbanded the faction "+faction.getTag(fplayer)+"."); fplayer.sendMessage((senderIsConsole ? "A server admin" : me.getNameAndRelevant(fplayer))+Conf.colorSystem+" disbanded the faction "+faction.getTag(fplayer)+".");
} }
} }
if (Conf.bankEnabled) {
Econ.addMoney(me.getName(), me.getFaction().getMoney() ); //Give all the faction's money to the disbander
}
Faction.delete( faction.getId() ); Faction.delete( faction.getId() );
SpoutFeatures.updateAppearances(); SpoutFeatures.updateAppearances();

View File

@ -78,6 +78,13 @@ public class FCommandHelp extends FBaseCommand {
pageLines.add( new FCommandSethome().getUseageTemplate() ); pageLines.add( new FCommandSethome().getUseageTemplate() );
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add( new FCommandBalance().getUseageTemplate() );
pageLines.add( new FCommandDeposit().getUseageTemplate() );
pageLines.add( new FCommandWithdraw().getUseageTemplate() );
pageLines.add( new FCommandPay().getUseageTemplate() );
helpPages.add(pageLines);
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new FCommandClaim().getUseageTemplate() ); pageLines.add( new FCommandClaim().getUseageTemplate() );
pageLines.add( new FCommandAutoClaim().getUseageTemplate() ); pageLines.add( new FCommandAutoClaim().getUseageTemplate() );

View File

@ -0,0 +1,73 @@
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 FCommandPay extends FBaseCommand {
public FCommandPay() {
aliases.add("pay");
helpDescription = "Pay another faction money from your faction's bank";
requiredParameters.add("faction");
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 pay another faction.");
return;
}
double amount = 0.0;
Faction us = me.getFaction();
Faction them = null;
if (parameters.size() == 2) {
try {
them = Faction.findByTag(parameters.get(0));
amount = Double.parseDouble(parameters.get(1));
} catch (NumberFormatException e) {
// wasn't valid
}
}
if(them == null) {
sendMessage(parameters.get(0)+" could not be found.");
return;
}
String amountString = Econ.moneyString(amount);
if( amount > 0.0 ) {
if( amount > us.getMoney() ) {
amount = us.getMoney();
}
us.removeMoney(amount);
them.addMoney(amount);
sendMessage("You have paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
sendMessage(us.getTag()+" now has "+Econ.moneyString(us.getMoney()));
for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == us || fplayer.getFaction() == them) {
fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" has sent "+amountString+" from "+us.getTag()+" to "+them.getTag() );
}
}
}
}
}

View File

@ -83,6 +83,11 @@ public class FCommandShow extends FBaseCommand {
String stringRefund = (refund > 0.0) ? (" ("+Econ.moneyString(refund)+" depreciated)") : ""; String stringRefund = (refund > 0.0) ? (" ("+Econ.moneyString(refund)+" depreciated)") : "";
sendMessage(Conf.colorChrome+"Total land value: " + Conf.colorSystem + stringValue + stringRefund); sendMessage(Conf.colorChrome+"Total land value: " + Conf.colorSystem + stringValue + stringRefund);
} }
//Show bank contents
if(Conf.bankEnabled) {
sendMessage(Conf.colorChrome+"Bank contains: " + Conf.colorSystem + Econ.moneyString(faction.getMoney()));
}
} }
String listpart; String listpart;

View File

@ -76,17 +76,32 @@ public class FCommandUnclaim extends FBaseCommand {
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded()); double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
// a real refund // a real refund
if (refund > 0.0) { if (refund > 0.0) {
if(Conf.bankFactionPaysLandCosts) {
Faction faction = me.getFaction();
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+" received a refund of "+Econ.moneyString(refund)+".";
} else {
Econ.addMoney(player.getName(), refund); Econ.addMoney(player.getName(), refund);
moneyBack = " They received a refund of "+Econ.moneyString(refund)+"."; moneyBack = " They received a refund of "+Econ.moneyString(refund)+".";
} }
}
// wait, you're charging people to unclaim land? outrageous // wait, you're charging people to unclaim land? outrageous
else if (refund < 0.0) { else if (refund < 0.0) {
if(Conf.bankFactionPaysLandCosts) {
Faction faction = me.getFaction();
if(!faction.removeMoney(-refund)) {
sendMessage("Unclaiming this land will cost "+Econ.moneyString(-refund)+", which your faction can't currently afford.");
return;
}
moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+".";
} else {
if (!Econ.deductMoney(player.getName(), -refund)) { if (!Econ.deductMoney(player.getName(), -refund)) {
sendMessage("Unclaiming this land will cost "+Econ.moneyString(-refund)+", which you can't currently afford."); sendMessage("Unclaiming this land will cost "+Econ.moneyString(-refund)+", which you can't currently afford.");
return; return;
} }
moneyBack = " It cost them "+Econ.moneyString(refund)+"."; moneyBack = " It cost them "+Econ.moneyString(refund)+".";
} }
}
// no refund // no refund
else { else {
moneyBack = ""; moneyBack = "";

View File

@ -37,17 +37,33 @@ public class FCommandUnclaimall extends FBaseCommand {
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded()); double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
// a real refund // a real refund
if (refund > 0.0) { if (refund > 0.0) {
if(Conf.bankFactionPaysLandCosts) {
Faction faction = me.getFaction();
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+" received a refund of "+Econ.moneyString(refund)+".";
} else {
Econ.addMoney(player.getName(), refund); Econ.addMoney(player.getName(), refund);
moneyBack = " They received a refund of "+Econ.moneyString(refund)+"."; moneyBack = " They received a refund of "+Econ.moneyString(refund)+".";
} }
}
// wait, you're charging people to unclaim land? outrageous // wait, you're charging people to unclaim land? outrageous
else if (refund < 0.0) { else if (refund < 0.0) {
if(Conf.bankFactionPaysLandCosts) {
Faction faction = me.getFaction();
if(!faction.removeMoney(-refund)) {
sendMessage("Unclaiming all faction land will cost "+Econ.moneyString(-refund)+", which your faction can't currently afford.");
return;
}
moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+".";
} else {
if (!Econ.deductMoney(player.getName(), -refund)) { if (!Econ.deductMoney(player.getName(), -refund)) {
sendMessage("Unclaiming all faction land will cost "+Econ.moneyString(-refund)+", which you can't currently afford."); sendMessage("Unclaiming all faction land will cost "+Econ.moneyString(-refund)+", which you can't currently afford.");
return; return;
} }
moneyBack = " It cost them "+Econ.moneyString(refund)+"."; moneyBack = " It cost them "+Econ.moneyString(refund)+".";
} }
moneyBack = " It cost them "+Econ.moneyString(refund)+".";
}
// no refund // no refund
else { else {
moneyBack = ""; moneyBack = "";
@ -55,7 +71,7 @@ public class FCommandUnclaimall extends FBaseCommand {
} }
Board.unclaimAll(myFaction.getId()); Board.unclaimAll(myFaction.getId());
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed ALL of your factions land."+moneyBack); myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed ALL of your faction's land."+moneyBack);
} }
} }

View File

@ -0,0 +1,65 @@
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);
}
}
}
}
}

View File

@ -217,11 +217,6 @@ public class FactionsPlayerListener extends PlayerListener{
me.sendMessage("You can't claim more land! You need more power!"); me.sendMessage("You can't claim more land! You need more power!");
me.enableAutoClaim(false); me.enableAutoClaim(false);
} }
else if (!Econ.canAfford(player.getName(), cost)) {
String costString = Econ.moneyString(cost);
me.sendMessage("Claiming this land will cost "+costString+", which you can't currently afford.");
me.enableAutoClaim(false);
}
else else
me.attemptClaim(false); me.attemptClaim(false);
} }