Some tweaking of the faction bank code...

The new help page with bank related commands will now only be shown if banks are enabled and the Economy is enabled and hooked in.
Shortened a couple of command descriptions to fit on one line.
Made Deposit, Pay, and Withdraw commands additionally log to the server console/log.
When bank is given to person disbanding a faction, it now lets them know and logs it to the server log.
Added commands to commandDisable list in plugin.yml, along with "permanent" command which I'd missed adding before
Added new permission node factions.viewAnyFactionBalance (granted by default if using superperms), which is required to view the bank balance of other factions

For reference, about the faction bank addition as a whole...
New conf.json settings:
"bankEnabled": true,  - enable faction banks
"bankMembersCanWithdraw": false,  - have to be at least moderator to withdraw or pay money to another faction, unless this is set to true
"bankFactionPaysCosts": true,  - if true, payments for faction command costs are charged to faction bank
"bankFactionPaysLandCosts": true,  - if true, payments for land claims are charged to faction bank

New commands:
/f balance *<faction tag> - Shows the bank balance of a specified faction (if permission checks out), or the player's faction if none is specified
/f deposit <amount> - Deposit money into your faction's bank
/f pay <faction tag> <amount> - Pay money from your faction bank to another faction (requires moderator or admin status)
/f withdraw <amount> - Withdraw money from your faction's bank (requires moderator or admin status, unless "bankMembersCanWithdraw" is set to true)

New permission node:
factions.viewAnyFactionBalance - Allows the player to view the faction bank balance of all factions (default)
This commit is contained in:
Brettflan 2011-10-01 05:59:09 -05:00
parent 4cab42ec6e
commit feac58c6d6
9 changed files with 94 additions and 33 deletions

View File

@ -22,12 +22,6 @@ 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;
@ -225,6 +219,12 @@ public class Conf {
public static double econCostNeutral = 0.0; public static double econCostNeutral = 0.0;
public static double econCostNoBoom = 0.0; public static double econCostNoBoom = 0.0;
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them
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.
public static Set<String> worldsNoClaiming = new HashSet<String>(); public static Set<String> worldsNoClaiming = new HashSet<String>();
public static Set<String> worldsNoPowerLoss = new HashSet<String>(); public static Set<String> worldsNoPowerLoss = new HashSet<String>();
public static Set<String> worldsIgnorePvP = new HashSet<String>(); public static Set<String> worldsIgnorePvP = new HashSet<String>();

View File

@ -4,6 +4,7 @@ import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.listeners.FactionsServerListener; import com.massivecraft.factions.listeners.FactionsServerListener;
import com.massivecraft.factions.commands.FCommandHelp;
import com.earth2me.essentials.api.Economy; import com.earth2me.essentials.api.Economy;
import com.nijikokun.register.payment.Methods; import com.nijikokun.register.payment.Methods;
@ -55,6 +56,7 @@ public class Econ {
else { else {
Factions.log("Un-hooked from Register."); Factions.log("Un-hooked from Register.");
} }
FCommandHelp.updateHelp();
} }
public static void iConomySet(boolean enable) { public static void iConomySet(boolean enable) {
@ -65,6 +67,7 @@ public class Econ {
else { else {
Factions.log("Un-hooked from iConomy."); Factions.log("Un-hooked from iConomy.");
} }
FCommandHelp.updateHelp();
} }
public static void essentialsEcoSet(boolean enable) { public static void essentialsEcoSet(boolean enable) {
@ -75,6 +78,7 @@ public class Econ {
else { else {
Factions.log("Un-hooked from EssentialsEco."); Factions.log("Un-hooked from EssentialsEco.");
} }
FCommandHelp.updateHelp();
} }
public static boolean registerHooked() { public static boolean registerHooked() {

View File

@ -1,10 +1,10 @@
package com.massivecraft.factions.commands; package com.massivecraft.factions.commands;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ; import com.massivecraft.factions.Econ;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
public class FCommandBalance extends FBaseCommand { public class FCommandBalance extends FBaseCommand {
@ -12,9 +12,9 @@ public class FCommandBalance extends FBaseCommand {
aliases.add("balance"); aliases.add("balance");
aliases.add("money"); aliases.add("money");
optionalParameters.add("faction name"); optionalParameters.add("faction tag");
helpDescription = "Shows a faction's current balance"; helpDescription = "Show faction's current balance";
} }
@Override @Override
@ -30,11 +30,20 @@ public class FCommandBalance extends FBaseCommand {
Faction faction; Faction faction;
if (parameters.size() > 0) { if (parameters.size() > 0) {
if (!Factions.hasPermViewAnyFactionBalance(sender)) {
sendMessage("You do not have sufficient permissions to view the bank balance of other factions.");
return;
}
faction = findFaction(parameters.get(0), true); faction = findFaction(parameters.get(0), true);
} else { } else {
faction = me.getFaction(); faction = me.getFaction();
} }
if(faction == null) {
sendMessage("Faction "+parameters.get(0)+" could not be found.");
return;
}
sendMessage(Conf.colorChrome+faction.getTag()+" balance: "+ Econ.moneyString(faction.getMoney())); sendMessage(Conf.colorChrome+faction.getTag()+" balance: "+ Econ.moneyString(faction.getMoney()));
} }

View File

@ -2,8 +2,10 @@ package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ; import com.massivecraft.factions.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FPlayer;
public class FCommandDeposit extends FBaseCommand { public class FCommandDeposit extends FBaseCommand {
@ -36,9 +38,9 @@ public class FCommandDeposit extends FBaseCommand {
} }
} }
if( amount > 0.0 ) {
String amountString = Econ.moneyString(amount); String amountString = Econ.moneyString(amount);
if( amount > 0.0 ) {
if( !Econ.deductMoney(me.getName(), amount ) ) { if( !Econ.deductMoney(me.getName(), amount ) ) {
sendMessage("You cannot afford to deposit that much."); sendMessage("You cannot afford to deposit that much.");
} }
@ -47,6 +49,7 @@ public class FCommandDeposit extends FBaseCommand {
faction.addMoney(amount); faction.addMoney(amount);
sendMessage("You have deposited "+amountString+" into "+faction.getTag()+"'s bank."); sendMessage("You have deposited "+amountString+" into "+faction.getTag()+"'s bank.");
sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney())); sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
Factions.log(player.getName() + " deposited "+amountString+" into "+faction.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayer.getAllOnline()) { for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {

View File

@ -70,7 +70,13 @@ public class FCommandDisband extends FBaseCommand {
} }
if (Conf.bankEnabled) { if (Conf.bankEnabled) {
Econ.addMoney(me.getName(), me.getFaction().getMoney() ); //Give all the faction's money to the disbander double amount = faction.getMoney();
Econ.addMoney(me.getName(), amount ); //Give all the faction's money to the disbander
if (amount > 0.0) {
String amountString = Econ.moneyString(amount);
sendMessage("You have been given the disbanded faction's bank, totaling "+amountString+".");
Factions.log(player.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
}
} }
Faction.delete( faction.getId() ); Faction.delete( faction.getId() );

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ;
import com.massivecraft.factions.util.TextUtil; import com.massivecraft.factions.util.TextUtil;
@ -48,9 +49,9 @@ public class FCommandHelp extends FBaseCommand {
// Build the help pages // Build the help pages
//----------------------------------------------// //----------------------------------------------//
public static final ArrayList<ArrayList<String>> helpPages; public static ArrayList<ArrayList<String>> helpPages;
static { public static void updateHelp() {
helpPages = new ArrayList<ArrayList<String>>(); helpPages = new ArrayList<ArrayList<String>>();
ArrayList<String> pageLines; ArrayList<String> pageLines;
@ -78,12 +79,19 @@ public class FCommandHelp extends FBaseCommand {
pageLines.add( new FCommandSethome().getUseageTemplate() ); pageLines.add( new FCommandSethome().getUseageTemplate() );
helpPages.add(pageLines); helpPages.add(pageLines);
if (Econ.enabled() && Conf.bankEnabled) {
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( "" );
pageLines.add( "Your faction has a bank which is used to pay for certain" );
pageLines.add( "things, so it will need to have money deposited into it." );
pageLines.add( "" );
pageLines.add( new FCommandBalance().getUseageTemplate() ); pageLines.add( new FCommandBalance().getUseageTemplate() );
pageLines.add( new FCommandDeposit().getUseageTemplate() ); pageLines.add( new FCommandDeposit().getUseageTemplate() );
pageLines.add( new FCommandWithdraw().getUseageTemplate() ); pageLines.add( new FCommandWithdraw().getUseageTemplate() );
pageLines.add( new FCommandPay().getUseageTemplate() ); pageLines.add( new FCommandPay().getUseageTemplate() );
pageLines.add( "" );
helpPages.add(pageLines); helpPages.add(pageLines);
}
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new FCommandClaim().getUseageTemplate() ); pageLines.add( new FCommandClaim().getUseageTemplate() );
@ -170,5 +178,8 @@ public class FCommandHelp extends FBaseCommand {
helpPages.add(pageLines); helpPages.add(pageLines);
} }
static {
updateHelp();
}
} }

View File

@ -2,16 +2,18 @@ package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ; import com.massivecraft.factions.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
public class FCommandPay extends FBaseCommand { public class FCommandPay extends FBaseCommand {
public FCommandPay() { public FCommandPay() {
aliases.add("pay"); aliases.add("pay");
helpDescription = "Pay another faction money from your faction's bank"; helpDescription = "Pay another faction from your bank";
requiredParameters.add("faction"); requiredParameters.add("faction");
requiredParameters.add("amount"); requiredParameters.add("amount");
} }
@ -46,13 +48,13 @@ public class FCommandPay extends FBaseCommand {
} }
if(them == null) { if(them == null) {
sendMessage(parameters.get(0)+" could not be found."); sendMessage("Faction "+parameters.get(0)+" could not be found.");
return; return;
} }
if( amount > 0.0 ) {
String amountString = Econ.moneyString(amount); String amountString = Econ.moneyString(amount);
if( amount > 0.0 ) {
if( amount > us.getMoney() ) { if( amount > us.getMoney() ) {
amount = us.getMoney(); amount = us.getMoney();
} }
@ -61,6 +63,7 @@ public class FCommandPay extends FBaseCommand {
them.addMoney(amount); them.addMoney(amount);
sendMessage("You have paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank."); sendMessage("You have paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
sendMessage(us.getTag()+" now has "+Econ.moneyString(us.getMoney())); sendMessage(us.getTag()+" now has "+Econ.moneyString(us.getMoney()));
Factions.log(player.getName() + " paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayer.getAllOnline()) { for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == us || fplayer.getFaction() == them) { if (fplayer.getFaction() == us || fplayer.getFaction() == them) {

View File

@ -2,10 +2,12 @@ package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Econ; import com.massivecraft.factions.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
public class FCommandWithdraw extends FBaseCommand { public class FCommandWithdraw extends FBaseCommand {
public FCommandWithdraw() { public FCommandWithdraw() {
@ -42,9 +44,9 @@ public class FCommandWithdraw extends FBaseCommand {
} }
} }
if( amount > 0.0 ) {
String amountString = Econ.moneyString(amount); String amountString = Econ.moneyString(amount);
if( amount > 0.0 ) {
if( amount > faction.getMoney() ) { if( amount > faction.getMoney() ) {
amount = faction.getMoney(); amount = faction.getMoney();
} }
@ -53,6 +55,7 @@ public class FCommandWithdraw extends FBaseCommand {
Econ.addMoney(me.getName(), amount); Econ.addMoney(me.getName(), amount);
sendMessage("You have withdrawn "+amountString+" from "+faction.getTag()+"'s bank."); sendMessage("You have withdrawn "+amountString+" from "+faction.getTag()+"'s bank.");
sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney())); sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
Factions.log(player.getName() + " withdrew "+amountString+" from "+faction.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayer.getAllOnline()) { for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {

View File

@ -1,5 +1,5 @@
name: Factions name: Factions
version: 1.5.1 version: 1.5.1_dev
main: com.massivecraft.factions.Factions main: com.massivecraft.factions.Factions
softdepend: softdepend:
- Permissions - Permissions
@ -27,6 +27,7 @@ permissions:
factions.participate: true factions.participate: true
factions.create: true factions.create: true
factions.viewAnyPower: true factions.viewAnyPower: true
factions.viewAnyFactionBalance: true
factions.peacefulExplosionToggle: true factions.peacefulExplosionToggle: true
factions.adminBypass: true factions.adminBypass: true
factions.config: true factions.config: true
@ -49,6 +50,9 @@ permissions:
factions.viewAnyPower: factions.viewAnyPower:
description: Allows the player to view the power level of anyone else description: Allows the player to view the power level of anyone else
default: true default: true
factions.viewAnyFactionBalance:
description: Allows the player to view the faction bank balance for any faction
default: true
factions.peacefulExplosionToggle: factions.peacefulExplosionToggle:
description: Allows peaceful faction admins and moderators to disable explosions in their territory description: Allows peaceful faction admins and moderators to disable explosions in their territory
default: true default: true
@ -100,6 +104,9 @@ permissions:
factions.commandDisable.autowar: factions.commandDisable.autowar:
description: autowar command disabled description: autowar command disabled
default: false default: false
factions.commandDisable.balance:
description: balance/money command disabled
default: false
factions.commandDisable.bypass: factions.commandDisable.bypass:
description: bypass command disabled description: bypass command disabled
default: false default: false
@ -121,6 +128,9 @@ permissions:
factions.commandDisable.deinv: factions.commandDisable.deinv:
description: deinvite command disabled description: deinvite command disabled
default: false default: false
factions.commandDisable.deposit:
description: deposit command disabled
default: false
factions.commandDisable.desc: factions.commandDisable.desc:
description: desc command disabled description: desc command disabled
default: false default: false
@ -169,6 +179,9 @@ permissions:
factions.commandDisable.mod: factions.commandDisable.mod:
description: mod command disabled description: mod command disabled
default: false default: false
factions.commandDisable.money:
description: balance/money command disabled
default: false
factions.commandDisable.noboom: factions.commandDisable.noboom:
description: noboom command disabled description: noboom command disabled
default: false default: false
@ -184,9 +197,15 @@ permissions:
factions.commandDisable.ownerlist: factions.commandDisable.ownerlist:
description: ownerlist command disabled description: ownerlist command disabled
default: false default: false
factions.commandDisable.pay:
description: pay command disabled
default: false
factions.commandDisable.peaceful: factions.commandDisable.peaceful:
description: peaceful command disabled description: peaceful command disabled
default: false default: false
factions.commandDisable.permanent:
description: permanent command disabled
default: false
factions.commandDisable.power: factions.commandDisable.power:
description: power command disabled description: power command disabled
default: false default: false
@ -265,6 +284,9 @@ permissions:
factions.commandDisable.wardeclaimall: factions.commandDisable.wardeclaimall:
description: warunclaimall command disabled description: warunclaimall command disabled
default: false default: false
factions.commandDisable.withdraw:
description: withdraw command disabled
default: false
factions.commandDisable.worldnoclaim: factions.commandDisable.worldnoclaim:
description: worldnoclaim command disabled description: worldnoclaim command disabled
default: false default: false