Econ messages improved. All money commands is now under the money parent command.

This commit is contained in:
Olof Larsson 2011-10-13 14:41:07 +02:00
parent 0039370f05
commit 0888e027ad
18 changed files with 361 additions and 619 deletions

View File

@ -20,6 +20,7 @@ permissions:
factions.setpermanent: true factions.setpermanent: true
factions.setpeaceful: true factions.setpeaceful: true
factions.sethome.any: true factions.sethome.any: true
factions.money.withdraw.any: true
factions.kit.halfmod: factions.kit.halfmod:
description: Zones, bypassing, and kicking description: Zones, bypassing, and kicking
children: children:
@ -39,14 +40,9 @@ permissions:
children: children:
factions.admin: true factions.admin: true
factions.autoclaim: true factions.autoclaim: true
factions.balance: true
factions.balance.any: true
factions.withdraw: true
factions.pay: true
factions.chat: true factions.chat: true
factions.claim: true factions.claim: true
factions.deinvite: true factions.deinvite: true
factions.deposit: true
factions.description: true factions.description: true
factions.disband: true factions.disband: true
factions.help: true factions.help: true
@ -58,6 +54,11 @@ permissions:
factions.list: true factions.list: true
factions.map: true factions.map: true
factions.mod: true factions.mod: true
factions.money.balance: true
factions.money.balance.any: true
factions.money.deposit: true
factions.money.pay: true
factions.money.withdraw: true
factions.noboom: true factions.noboom: true
factions.open: true factions.open: true
factions.owner: true factions.owner: true
@ -76,14 +77,6 @@ permissions:
description: hand over your admin rights description: hand over your admin rights
factions.autoclaim: factions.autoclaim:
description: auto-claim land as you walk around description: auto-claim land as you walk around
factions.balance:
description: show current faction balance
factions.balance.any:
description: show on other factions balance
factions.withdraw:
description: withdraw money from your faction bank
factions.pay:
description: pay another faction from your bank
factions.bypass: factions.bypass:
description: enable admin bypass mode description: enable admin bypass mode
factions.chat: factions.chat:
@ -96,8 +89,6 @@ permissions:
description: create a new faction description: create a new faction
factions.deinvite: factions.deinvite:
description: remove a pending invitation description: remove a pending invitation
factions.deposit:
description: deposit money into your faction bank
factions.description: factions.description:
description: change the faction description description: change the faction description
factions.disband: factions.disband:
@ -130,6 +121,26 @@ permissions:
description: show the territory map, and set optional auto update description: show the territory map, and set optional auto update
factions.mod: factions.mod:
description: give or revoke moderator rights description: give or revoke moderator rights
factions.money.*:
children:
factions.money.balance: true
factions.money.balance.any: true
factions.money.deposit: true
factions.money.pay: true
factions.money.withdraw: true
factions.money.withdraw.any: true
factions.money.balance:
description: show your factions current money balance
factions.money.balance.any:
description: show money balance for factions other than your own
factions.money.deposit:
description: deposit money into a faction bank
factions.money.pay:
description: pay another faction from your bank
factions.money.withdraw:
description: withdraw money from your faction bank
factions.money.withdraw.any:
description: withdraw money from your factions other than your own
factions.noboom: factions.noboom:
description: toggle explosions (peaceful factions only) description: toggle explosions (peaceful factions only)
factions.open: factions.open:

View File

@ -123,7 +123,6 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
// FIELD: account // FIELD: account
public MethodAccount getAccount() public MethodAccount getAccount()
{ {
P.p.log("Econ.shouldBeUsed() "+Econ.shouldBeUsed());
if ( ! Econ.shouldBeUsed()) return null; if ( ! Econ.shouldBeUsed()) return null;
return Econ.getMethod().getAccount(this.getId()); return Econ.getMethod().getAccount(this.getId());
} }

View File

@ -104,7 +104,7 @@ public class Faction extends Entity implements EconomyParticipator
return; return;
} }
sendMessage("Your faction home has been un-set since it is no longer in your territory."); msg("<b>Your faction home has been un-set since it is no longer in your territory.");
this.home = null; this.home = null;
} }
@ -113,7 +113,7 @@ public class Faction extends Entity implements EconomyParticipator
// FIELD: account (fake field) // FIELD: account (fake field)
// Bank functions // Bank functions
public double money; // Deprecated TODO: Hantera. public double money;
public String getAccountId() { return "faction-"+this.getId(); } public String getAccountId() { return "faction-"+this.getId(); }
public MethodAccount getAccount() public MethodAccount getAccount()
{ {
@ -129,26 +129,6 @@ public class Faction extends Entity implements EconomyParticipator
return Econ.getMethod().getAccount(aid); return Econ.getMethod().getAccount(aid);
} }
/*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;
}*/
// -------------------------------------------- // // -------------------------------------------- //
// Construct // Construct
// -------------------------------------------- // // -------------------------------------------- //
@ -214,25 +194,25 @@ public class Faction extends Entity implements EconomyParticipator
@Override @Override
public String describeTo(RelationParticipator that, boolean ucfirst) public String describeTo(RelationParticipator that, boolean ucfirst)
{ {
return RelationUtil.describeThatToMe(that, this, ucfirst); return RelationUtil.describeThatToMe(this, that, ucfirst);
} }
@Override @Override
public String describeTo(RelationParticipator that) public String describeTo(RelationParticipator that)
{ {
return RelationUtil.describeThatToMe(that, this); return RelationUtil.describeThatToMe(this, that);
} }
@Override @Override
public Relation getRelationTo(RelationParticipator rp) public Relation getRelationTo(RelationParticipator rp)
{ {
return RelationUtil.getRelationTo(rp, this); return RelationUtil.getRelationTo(this, rp);
} }
@Override @Override
public Relation getRelationTo(RelationParticipator rp, boolean ignorePeaceful) public Relation getRelationTo(RelationParticipator rp, boolean ignorePeaceful)
{ {
return RelationUtil.getRelationTo(rp, this, ignorePeaceful); return RelationUtil.getRelationTo(this, rp, ignorePeaceful);
} }
@Override @Override
@ -262,44 +242,6 @@ public class Faction extends Entity implements EconomyParticipator
} }
} }
/*public Relation getRelationTo(Faction otherFaction)
{
return getRelationTo(otherFaction, false);
}
public Relation getRelationTo(Faction otherFaction, boolean ignorePeaceful)
{
if (!otherFaction.isNormal() || !this.isNormal())
{
return Relation.NEUTRAL;
}
if (otherFaction.equals(this))
{
return Relation.MEMBER;
}
if (!ignorePeaceful && (this.peaceful || otherFaction.isPeaceful()))
{
return Relation.NEUTRAL;
}
if(this.getRelationWish(otherFaction).value >= otherFaction.getRelationWish(this).value)
{
return otherFaction.getRelationWish(this);
}
return this.getRelationWish(otherFaction);
}
public Relation getRelationTo(FPlayer fplayer)
{
if (fplayer == null)
return Relation.NEUTRAL;
else
return getRelationTo(fplayer.getFaction());
}*/
//----------------------------------------------// //----------------------------------------------//
// Power // Power
//----------------------------------------------// //----------------------------------------------//
@ -662,83 +604,10 @@ public class Faction extends Entity implements EconomyParticipator
} }
//----------------------------------------------// //----------------------------------------------//
// Persistance and entity management // Persistance and entity management
//----------------------------------------------// //----------------------------------------------//
/*public static boolean save() {
//Factions.log("Saving factions to disk");
try {
DiscUtil.write(file, P.p.gson.toJson(instances));
} catch (IOException e) {
e.printStackTrace();
P.log("Failed to save the factions to disk due to I/O exception.");
return false;
} catch (Exception e) {
e.printStackTrace();
P.log("Failed to save the factions to disk.");
return false;
}
return true;
}
*/
/*public static boolean load() {
P.log("Loading factions from disk");
if ( ! file.exists()) {
if ( ! loadOld())
P.log("No factions to load from disk. Creating new file.");
save();
}
try {
Type type = new TypeToken<Map<Integer, Faction>>(){}.getType();
Map<Integer, Faction> instancesFromFile = P.p.gson.fromJson(DiscUtil.read(file), type);
instances.clear();
instances.putAll(instancesFromFile);
} catch (Exception e) {
e.printStackTrace();
P.log("Failed to load the factions from disk.");
return false;
}
fillIds();
// Make sure the default neutral faction exists
if ( ! instances.containsKey(0)) {
Faction faction = new Faction();
faction.tag = ChatColor.DARK_GREEN+"Wilderness";
faction.description = "";
faction.id = 0;
instances.put(faction.id, faction);
}
// Make sure the safe zone faction exists
if ( ! instances.containsKey(-1)) {
Faction faction = new Faction();
faction.tag = ChatColor.GOLD+"Safe Zone";
faction.description = "Free from PVP and monsters";
faction.id = -1;
instances.put(faction.id, faction);
}
// Make sure the war zone faction exists
if ( ! instances.containsKey(-2)) {
Faction faction = new Faction();
faction.tag = ChatColor.DARK_RED+"War Zone";
faction.description = "Not the safest place to be";
faction.id = -2;
instances.put(faction.id, faction);
}
return true;
}*/
@Override @Override
public void postDetach() public void postDetach()
@ -756,94 +625,4 @@ public class Faction extends Entity implements EconomyParticipator
// Clean the fplayers // Clean the fplayers
FPlayers.i.clean(); FPlayers.i.clean();
} }
/*public static Faction get(Integer factionId)
{
if ( ! instances.containsKey(factionId))
{
P.log(Level.WARNING, "Non existing factionId "+factionId+" requested! Issuing cleaning!");
Board.clean();
FPlayer.clean();
}
return instances.get(factionId);
}*/
/*
public static Faction getNone() {
return instances.get(0);
}
public static Faction getSafeZone() {
return instances.get(-1);
}
public static Faction getWarZone() {
return instances.get(-2);
}*/
/*
public static boolean exists(Integer factionId) {
return instances.containsKey(factionId);
}
//TODO ta parametrar här. All info som behövs ska matas in här och sparar vi i denna method.
public static Faction create()
{
Faction faction = new Faction();
faction.id = nextId;
nextId += 1;
instances.put(faction.id, faction);
P.log("created new faction "+faction.id);
//faction.save();
return faction;
}
public static void delete(Integer id) {
// Remove the faction
instances.remove(id);
// Clean the board
Board.clean();
// Clean the fplayers
FPlayer.clean();
}
private static boolean loadOld() {
File folderFaction = new File(P.p.getDataFolder(), "faction");
if ( ! folderFaction.isDirectory())
return false;
P.log("Factions file doesn't exist, attempting to load old pre-1.1 data.");
String ext = ".json";
class jsonFileFilter implements FileFilter {
@Override
public boolean accept(File file) {
return (file.getName().toLowerCase().endsWith(".json") && file.isFile());
}
}
File[] jsonFiles = folderFaction.listFiles(new jsonFileFilter());
for (File jsonFile : jsonFiles) {
// Extract the name from the filename. The name is filename minus ".json"
String name = jsonFile.getName();
name = name.substring(0, name.length() - ext.length());
int id = Integer.parseInt(name);
try {
Faction faction = P.p.gson.fromJson(DiscUtil.read(jsonFile), Faction.class);
faction.id = id;
instances.put(faction.id, faction);
P.log("loaded pre-1.1 faction "+id);
} catch (Exception e) {
e.printStackTrace();
P.log(Level.WARNING, "Failed to load faction "+id);
}
}
return true;
}*/
} }

View File

@ -53,6 +53,7 @@ public class P extends MPlugin
// Commands // Commands
public FCmdRoot cmdBase; public FCmdRoot cmdBase;
public CmdAutoHelp cmdAutoHelp;
public P() public P()
{ {
@ -83,6 +84,7 @@ public class P extends MPlugin
// Add Base Commands // Add Base Commands
this.cmdBase = new FCmdRoot(); this.cmdBase = new FCmdRoot();
this.cmdAutoHelp = new CmdAutoHelp();
this.getBaseCommands().add(cmdBase); this.getBaseCommands().add(cmdBase);
//setupPermissions(); //setupPermissions();

View File

@ -0,0 +1,48 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import com.massivecraft.factions.P;
import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.MCommand;
public class CmdAutoHelp extends MCommand<P>
{
public CmdAutoHelp()
{
super(P.p);
this.aliases.add("?");
this.aliases.add("h");
this.aliases.add("help");
this.setHelpShort("");
this.optionalArgs.put("page","1");
}
@Override
public void perform()
{
if (this.commandChain.size() == 0) return;
MCommand<?> pcmd = this.commandChain.get(this.commandChain.size()-1);
ArrayList<String> lines = new ArrayList<String>();
lines.addAll(pcmd.helpLong);
for(MCommand<?> scmd : pcmd.subCommands)
{
if
(
scmd.visibility == CommandVisibility.VISIBLE
||
(scmd.visibility == CommandVisibility.SECRET && scmd.validSenderPermissions(sender, false))
)
{
lines.add(scmd.getUseageTemplate(this.commandChain, true));
}
}
sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), "Help for command \""+pcmd.aliases.get(0)+"\""));
}
}

View File

@ -1,54 +0,0 @@
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.Faction;
public class CmdBalance extends FCommand
{
public CmdBalance()
{
super();
this.aliases.add("balance");
this.aliases.add("money");
//this.requiredArgs.add("player name");
this.optionalArgs.put("factiontag", "yours");
this.permission = Permission.BALANCE.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled)
{
return;
}
Faction faction = this.argAsFaction(0, myFaction);
// TODO MAKE HIERARCHIAL COMMAND STRUCTURE HERE
if ( faction != myFaction && ! Permission.BALANCE_ANY.has(sender))
{
msg("<b>You do not have sufficient permissions to view the bank balance of other factions.");
return;
}
if (faction == null)
{
msg("<b>Faction %s<b> could not be found.", args.get(0));
return;
}
msg("<a>%s<i> balance: <h>%s", faction.getTag(fme), Econ.moneyString(faction.getAccount().balance()));
}
}

View File

@ -1,60 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
public class CmdDeposit extends FCommand
{
public CmdDeposit()
{
super();
this.aliases.add("deposit");
this.requiredArgs.add("amount");
//this.optionalArgs
this.permission = Permission.DEPOSIT.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled) return;
Econ.transferMoney(fme, fme, myFaction, this.argAsDouble(0, 0));
/*
if( amount > 0.0 )
{
String amountString = Econ.moneyString(amount);
if( ! Econ.deductMoney(fme.getName(), amount ) )
{
msg("<b>You cannot afford to deposit that much.");
}
else
{
faction.addMoney(amount);
msg("<i>You have deposited <h>%s<i> into <h>%s's<i> bank.", amountString, faction.getTag());
msg("%s<i> now has <h>%s", faction.getTag(fme), Econ.moneyString(faction.getMoney()));
P.p.log(fme.getName() + " deposited "+amountString+" into "+faction.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == faction)
{
fplayer.msg("%s<i> has deposited <h>%s", fme.getNameAndRelevant(fplayer), amountString);
}
}
}
}*/
}
}

View File

@ -89,11 +89,11 @@ public class CmdHelp extends FCommand
pageLines.add( "" ); pageLines.add( "" );
pageLines.add( p.txt.parse("<i>Your faction has a bank which is used to pay for certain" )); pageLines.add( p.txt.parse("<i>Your faction has a bank which is used to pay for certain" ));
pageLines.add( p.txt.parse("<i>things, so it will need to have money deposited into it." )); pageLines.add( p.txt.parse("<i>things, so it will need to have money deposited into it." ));
pageLines.add( p.txt.parse("<i>To lear more use the money command." ));
pageLines.add( "" );
pageLines.add( p.cmdBase.cmdMoney.getUseageTemplate() );
pageLines.add( "" );
pageLines.add( "" ); pageLines.add( "" );
pageLines.add( p.cmdBase.cmdBalance.getUseageTemplate() );
pageLines.add( p.cmdBase.cmdDeposit.getUseageTemplate() );
pageLines.add( p.cmdBase.cmdWithdraw.getUseageTemplate() );
pageLines.add( p.cmdBase.cmdPay.getUseageTemplate() );
pageLines.add( "" ); pageLines.add( "" );
helpPages.add(pageLines); helpPages.add(pageLines);
} }

View File

@ -0,0 +1,44 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
public class CmdMoney extends FCommand
{
public CmdMoneyBalance cmdMoneyBalance = new CmdMoneyBalance();
public CmdMoneyDeposit cmdMoneyDeposit = new CmdMoneyDeposit();
public CmdMoneyWithdraw cmdMoneyWithdraw = new CmdMoneyWithdraw();
public CmdMoneyPay cmdMoneyPay = new CmdMoneyPay();
public CmdMoney()
{
super();
this.aliases.add("money");
//this.requiredArgs.add("");
//this.optionalArgs.put("","")
this.isMoneyCommand = true;
this.isBankCommand = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("faction money commands");
this.helpLong.add(p.txt.parseTags("<i>The faction money commands."));
this.addSubCommand(this.cmdMoneyBalance);
this.addSubCommand(this.cmdMoneyDeposit);
this.addSubCommand(this.cmdMoneyWithdraw);
this.addSubCommand(this.cmdMoneyPay);
}
@Override
public void perform()
{
this.commandChain.add(this);
P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.Faction;
public class CmdMoneyBalance extends FCommand
{
public CmdMoneyBalance()
{
super();
this.aliases.add("b");
this.aliases.add("balance");
//this.requiredArgs.add("");
this.optionalArgs.put("faction", "yours");
this.permission = Permission.MONEY_BALANCE.node;
this.isMoneyCommand = true;
this.isBankCommand = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
Faction faction = myFaction;
if (this.argIsSet(0))
{
faction = this.argAsFaction(0);
}
if (faction == null) return;
if (faction != myFaction && ! Permission.MONEY_BALANCE_ANY.has(sender, true)) return;
Econ.sendBalanceInfo(fme, faction);
}
}

View File

@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
public class CmdMoneyDeposit extends FCommand
{
public CmdMoneyDeposit()
{
super();
this.aliases.add("deposit");
this.requiredArgs.add("amount");
this.optionalArgs.put("faction", "yours");
this.permission = Permission.MONEY_DEPOSIT.node;
this.isMoneyCommand = true;
this.isBankCommand = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
double amount = this.argAsDouble(0, 0);
Faction faction = this.argAsFaction(1, myFaction);
if (faction == null) return;
Econ.transferMoney(fme, fme, faction, amount);
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
public class CmdMoneyPay extends FCommand
{
public CmdMoneyPay()
{
this.aliases.add("pay");
this.requiredArgs.add("amount");
this.requiredArgs.add("faction");
//this.optionalArgs.put("", "");
this.permission = Permission.MONEY_PAY.node;
this.isMoneyCommand = true;
this.isBankCommand = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
double amount = this.argAsDouble(0, 0);
Faction faction = this.argAsFaction(1);
if (faction == null) return;
Econ.transferMoney(fme, myFaction, faction, amount);
}
}

View File

@ -1,25 +1,25 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
public class CmdMoneyWithdraw extends FCommand
public class CmdWithdraw extends FCommand
{ {
public CmdWithdraw() public CmdMoneyWithdraw()
{ {
this.aliases.add("withdraw"); this.aliases.add("withdraw");
this.requiredArgs.add("amount"); this.requiredArgs.add("amount");
//this.optionalArgs.put("factiontag", "yours"); this.optionalArgs.put("faction", "yours");
this.permission = Permission.WITHDRAW.node; this.permission = Permission.MONEY_WITHDRAW.node;
this.disableOnLock = true; this.isMoneyCommand = true;
this.isBankCommand = true;
senderMustBePlayer = true; senderMustBePlayer = true;
senderMustBeMember = true; senderMustBeMember = false;
senderMustBeModerator = false; senderMustBeModerator = false;
senderMustBeAdmin = false; senderMustBeAdmin = false;
} }
@ -27,9 +27,10 @@ public class CmdWithdraw extends FCommand
@Override @Override
public void perform() public void perform()
{ {
if ( ! Conf.bankEnabled) return; double amount = this.argAsDouble(0, 0);
Faction faction = this.argAsFaction(1, myFaction);
Econ.transferMoney(fme, myFaction, fme, this.argAsDouble(0, 0)); if (faction == null) return;
Econ.transferMoney(fme, faction, fme, amount);
/*if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR)) /*if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR))
{ {

View File

@ -1,73 +0,0 @@
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 CmdPay extends FCommand
{
public CmdPay()
{
this.aliases.add("pay");
this.requiredArgs.add("faction");
this.requiredArgs.add("amount");
//this.optionalArgs.put("", "");
this.permission = Permission.PAY.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled) return;
if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR))
{
msg("<b>Only faction moderators or admins are able to pay another faction.");
return;
}
Faction us = fme.getFaction();
Faction them = this.argAsFaction(0);
if ( them == null ) return;
double amount = this.argAsDouble(1, 0d);
if( amount > 0.0 )
{
String amountString = Econ.moneyString(amount);
if( amount > us.getAccount().balance() )
{
amount = us.getAccount().balance();
}
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.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())
{
if (fplayer.getFaction() == us || fplayer.getFaction() == them)
{
fplayer.msg(fme.getNameAndRelevant(fplayer)+"<i> has sent "+amountString+" from "+us.getTag()+" to "+them.getTag());
}
}
}
}
}

View File

@ -8,7 +8,6 @@ public class FCmdRoot extends FCommand
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
public CmdAutoSafeclaim cmdAutoSafeclaim = new CmdAutoSafeclaim(); public CmdAutoSafeclaim cmdAutoSafeclaim = new CmdAutoSafeclaim();
public CmdAutoWarclaim cmdAutoWarclaim = new CmdAutoWarclaim(); public CmdAutoWarclaim cmdAutoWarclaim = new CmdAutoWarclaim();
public CmdBalance cmdBalance = new CmdBalance();
public CmdBoom cmdBoom = new CmdBoom(); public CmdBoom cmdBoom = new CmdBoom();
public CmdBypass cmdBypass = new CmdBypass(); public CmdBypass cmdBypass = new CmdBypass();
public CmdChat cmdChat = new CmdChat(); public CmdChat cmdChat = new CmdChat();
@ -16,7 +15,6 @@ public class FCmdRoot extends FCommand
public CmdConfig cmdConfig = new CmdConfig(); public CmdConfig cmdConfig = new CmdConfig();
public CmdCreate cmdCreate = new CmdCreate(); public CmdCreate cmdCreate = new CmdCreate();
public CmdDeinvite cmdDeinvite = new CmdDeinvite(); public CmdDeinvite cmdDeinvite = new CmdDeinvite();
public CmdDeposit cmdDeposit = new CmdDeposit();
public CmdDescription cmdDescription = new CmdDescription(); public CmdDescription cmdDescription = new CmdDescription();
public CmdDisband cmdDisband = new CmdDisband(); public CmdDisband cmdDisband = new CmdDisband();
public CmdHelp cmdHelp = new CmdHelp(); public CmdHelp cmdHelp = new CmdHelp();
@ -29,10 +27,10 @@ public class FCmdRoot extends FCommand
public CmdLock cmdLock = new CmdLock(); public CmdLock cmdLock = new CmdLock();
public CmdMap cmdMap = new CmdMap(); public CmdMap cmdMap = new CmdMap();
public CmdMod cmdMod = new CmdMod(); public CmdMod cmdMod = new CmdMod();
public CmdMoney cmdMoney = new CmdMoney();
public CmdOpen cmdOpen = new CmdOpen(); public CmdOpen cmdOpen = new CmdOpen();
public CmdOwner cmdOwner = new CmdOwner(); public CmdOwner cmdOwner = new CmdOwner();
public CmdOwnerList cmdOwnerList = new CmdOwnerList(); public CmdOwnerList cmdOwnerList = new CmdOwnerList();
public CmdPay cmdPay = new CmdPay();
public CmdPeaceful cmdPeaceful = new CmdPeaceful(); public CmdPeaceful cmdPeaceful = new CmdPeaceful();
public CmdPermanent cmdPermanent = new CmdPermanent(); public CmdPermanent cmdPermanent = new CmdPermanent();
public CmdPower cmdPower = new CmdPower(); public CmdPower cmdPower = new CmdPower();
@ -52,7 +50,6 @@ public class FCmdRoot extends FCommand
public CmdVersion cmdVersion = new CmdVersion(); public CmdVersion cmdVersion = new CmdVersion();
public CmdWarclaim cmdWarclaim = new CmdWarclaim(); public CmdWarclaim cmdWarclaim = new CmdWarclaim();
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall(); public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
public CmdWithdraw cmdWithdraw = new CmdWithdraw();
public FCmdRoot() public FCmdRoot()
{ {
@ -60,6 +57,9 @@ public class FCmdRoot extends FCommand
this.aliases.addAll(Conf.baseCommandAliases); this.aliases.addAll(Conf.baseCommandAliases);
this.allowNoSlashAccess = Conf.allowNoSlashCommand; this.allowNoSlashAccess = Conf.allowNoSlashCommand;
//this.requiredArgs.add("");
//this.optionalArgs.put("","")
senderMustBePlayer = false; senderMustBePlayer = false;
senderMustBeMember = false; senderMustBeMember = false;
senderMustBeModerator = false; senderMustBeModerator = false;
@ -76,7 +76,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdAutoClaim); this.addSubCommand(this.cmdAutoClaim);
this.addSubCommand(this.cmdAutoSafeclaim); this.addSubCommand(this.cmdAutoSafeclaim);
this.addSubCommand(this.cmdAutoWarclaim); this.addSubCommand(this.cmdAutoWarclaim);
this.addSubCommand(this.cmdBalance);
this.addSubCommand(this.cmdBoom); this.addSubCommand(this.cmdBoom);
this.addSubCommand(this.cmdBypass); this.addSubCommand(this.cmdBypass);
this.addSubCommand(this.cmdChat); this.addSubCommand(this.cmdChat);
@ -84,7 +83,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdConfig); this.addSubCommand(this.cmdConfig);
this.addSubCommand(this.cmdCreate); this.addSubCommand(this.cmdCreate);
this.addSubCommand(this.cmdDeinvite); this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDeposit);
this.addSubCommand(this.cmdDescription); this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband); this.addSubCommand(this.cmdDisband);
this.addSubCommand(this.cmdHelp); this.addSubCommand(this.cmdHelp);
@ -97,10 +95,10 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdLock); this.addSubCommand(this.cmdLock);
this.addSubCommand(this.cmdMap); this.addSubCommand(this.cmdMap);
this.addSubCommand(this.cmdMod); this.addSubCommand(this.cmdMod);
this.addSubCommand(this.cmdMoney);
this.addSubCommand(this.cmdOpen); this.addSubCommand(this.cmdOpen);
this.addSubCommand(this.cmdOwner); this.addSubCommand(this.cmdOwner);
this.addSubCommand(this.cmdOwnerList); this.addSubCommand(this.cmdOwnerList);
this.addSubCommand(this.cmdPay);
this.addSubCommand(this.cmdPeaceful); this.addSubCommand(this.cmdPeaceful);
this.addSubCommand(this.cmdPermanent); this.addSubCommand(this.cmdPermanent);
this.addSubCommand(this.cmdPower); this.addSubCommand(this.cmdPower);
@ -120,7 +118,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdVersion); this.addSubCommand(this.cmdVersion);
this.addSubCommand(this.cmdWarclaim); this.addSubCommand(this.cmdWarclaim);
this.addSubCommand(this.cmdWarunclaimall); this.addSubCommand(this.cmdWarunclaimall);
this.addSubCommand(this.cmdWithdraw);
} }
@Override @Override

View File

@ -26,6 +26,9 @@ public abstract class FCommand extends MCommand<P>
public boolean senderMustBeModerator; public boolean senderMustBeModerator;
public boolean senderMustBeAdmin; public boolean senderMustBeAdmin;
public boolean isMoneyCommand;
public boolean isBankCommand;
public FCommand() public FCommand()
{ {
super(P.p); super(P.p);
@ -33,6 +36,10 @@ public abstract class FCommand extends MCommand<P>
// Due to safety reasons it defaults to disable on lock. // Due to safety reasons it defaults to disable on lock.
disableOnLock = true; disableOnLock = true;
// The money commands must be disabled if money should not be used.
isMoneyCommand = false;
isBankCommand = false;
senderMustBeMember = false; senderMustBeMember = false;
senderMustBeModerator = false; senderMustBeModerator = false;
senderMustBeAdmin = false; senderMustBeAdmin = false;
@ -62,6 +69,19 @@ public abstract class FCommand extends MCommand<P>
msg("<b>Factions was locked by an admin. Please try again later."); msg("<b>Factions was locked by an admin. Please try again later.");
return false; return false;
} }
if (this.isMoneyCommand && ! Conf.econEnabled)
{
msg("<b>Faction economy features are diabled on this server.");
return false;
}
if (this.isBankCommand && ! Conf.bankEnabled)
{
msg("<b>The faction bank system is diabled on this server.");
return false;
}
return true; return true;
} }

View File

@ -1,5 +1,8 @@
package com.massivecraft.factions.integration; package com.massivecraft.factions.integration;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -76,30 +79,35 @@ public class Econ
acc.add(delta); acc.add(delta);
} }
public static boolean canInvokerTransferFrom(EconomyParticipator invoker, EconomyParticipator from) public static void sendBalanceInfo(FPlayer to, EconomyParticipator about)
{ {
Faction fInvoker = RelationUtil.getFaction(invoker); to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Econ.moneyString(about.getAccount().balance()));
Faction fFrom = RelationUtil.getFaction(from); }
public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you)
{
Faction fInvoker = RelationUtil.getFaction(i);
Faction fFrom = RelationUtil.getFaction(you);
// This is a system invoker. Accept it. // This is a system invoker. Accept it.
if (fInvoker == null) return true; if (fInvoker == null) return true;
// Bypassing players can do any kind of transaction // Bypassing players can do any kind of transaction
if (invoker instanceof FPlayer && ((FPlayer)invoker).isAdminBypassing()) return true; if (i instanceof FPlayer && ((FPlayer)i).isAdminBypassing()) return true;
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again. // You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
if (invoker == from) return true; if (i == you) return true;
// A faction can always transfer away the money of it's members and its own money... // A faction can always transfer away the money of it's members and its own money...
// This will however probably never happen as a faction does not have free will. // This will however probably never happen as a faction does not have free will.
// Ohh by the way... Yes it could. For daily rent to the faction. // Ohh by the way... Yes it could. For daily rent to the faction.
if (invoker == fInvoker && fInvoker == fFrom) return true; if (i == fInvoker && fInvoker == fFrom) return true;
// If you are part of the same faction as from and members can withdraw or you are at least moderator... then it is ok. // If you are part of the same faction as from and members can withdraw or you are at least moderator... then it is ok.
if (fInvoker == fFrom && (Conf.bankMembersCanWithdraw || ((FPlayer)invoker).getRole().value < Role.MODERATOR.value)) return true; if (fInvoker == fFrom && (Conf.bankMembersCanWithdraw || ((FPlayer)i).getRole().value >= Role.MODERATOR.value)) return true;
// Otherwise you may not! ;,,; // Otherwise you may not! ;,,;
invoker.msg("<h>%s<b> don't have the right to transfer money from <h>%s<b>.", invoker.describeTo(invoker, true), from.describeTo(invoker)); i.msg("<h>%s<i> lack permission to controll <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));
return false; return false;
} }
@ -118,23 +126,15 @@ public class Econ
} }
// Check the rights // Check the rights
if ( ! canInvokerTransferFrom(invoker, from)) return false; if ( ! canIControllYou(invoker, from)) return false;
//Faction fFrom = RelationUtil.getFaction(from);
//Faction fTo = RelationUtil.getFaction(to);
//Faction fInvoker = RelationUtil.getFaction(invoker);
// Is there enough money for the transaction to happen? // Is there enough money for the transaction to happen?
P.p.log("from "+from);
P.p.log("from.getAccount() "+from.getAccount());
if ( ! from.getAccount().hasEnough(amount)) if ( ! from.getAccount().hasEnough(amount))
{ {
// There was not enough money to pay // There was not enough money to pay
if (invoker != null) if (invoker != null)
{ {
invoker.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker)); invoker.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker));
} }
return false; return false;
} }
@ -144,23 +144,66 @@ public class Econ
to.getAccount().add(amount); to.getAccount().add(amount);
// Inform // Inform
sendTransferInfo(invoker, from, to, amount);
return true;
}
public static Set<FPlayer> getFplayers(EconomyParticipator ep)
{
Set<FPlayer> fplayers = new HashSet<FPlayer>();
if (ep == null)
{
// Add nothing
}
else if (ep instanceof FPlayer)
{
fplayers.add((FPlayer)ep);
}
else if (ep instanceof Faction)
{
fplayers.addAll(((Faction)ep).getFPlayers());
}
return fplayers;
}
public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount)
{
Set<FPlayer> recipients = new HashSet<FPlayer>();
recipients.addAll(getFplayers(invoker));
recipients.addAll(getFplayers(from));
recipients.addAll(getFplayers(to));
if (invoker == null) if (invoker == null)
{ {
from.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(from), to.describeTo(from)); for (FPlayer recipient : recipients)
to.msg ("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(to), to.describeTo(to)); {
recipient.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
}
} }
else if (invoker == from || invoker == to) else if (invoker == from)
{ {
from.msg("<h>%s<i> transfered <h>%s<i> to <h>%s<i>.", from.describeTo(from, true), moneyString(amount), to.describeTo(from)); for (FPlayer recipient : recipients)
to.msg ("<h>%s<i> transfered <h>%s<i> to <h>%s<i>.", from.describeTo(to, true), moneyString(amount), to.describeTo(to)); {
recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient));
}
}
else if (invoker == to)
{
for (FPlayer recipient : recipients)
{
recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient));
}
} }
else else
{ {
from.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i> by <h>%s<i>.", moneyString(amount), from.describeTo(from), to.describeTo(from), invoker.describeTo(from)); for (FPlayer recipient : recipients)
to.msg ("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i> by <h>%s<i>.", moneyString(amount), from.describeTo(to), to.describeTo(to), invoker.describeTo(to)); {
recipient.msg("<h>%s<i> transfered <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
}
} }
return true;
} }
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis)
@ -201,8 +244,6 @@ public class Econ
} }
} }
// format money string based on server's set currency type, like "24 gold" or "$24.50" // format money string based on server's set currency type, like "24 gold" or "$24.50"
public static String moneyString(double amount) public static String moneyString(double amount)
{ {
@ -220,138 +261,6 @@ public class Econ
} }
} }
// whether a player can afford specified amount
/*public static boolean canAfford(String playerName, double amount) {
// if Economy support is not enabled, they can certainly afford to pay nothing
if (!enabled())
{
return true;
}
if (registerAvailable())
{
MethodAccount holdings = getRegisterAccount(playerName);
if (holdings == null)
{
return false;
}
return holdings.hasEnough(amount);
}
else if (iConomyUse)
{
Holdings holdings = getIconomyHoldings(playerName);
if (holdings == null)
{
return false;
}
return holdings.hasEnough(amount);
}
else
{
try
{
return Economy.hasEnough(playerName, amount);
}
catch (Exception ex)
{
return false;
}
}
}*/
// deduct money from their account; returns true if successful
/*public static boolean deductMoney(String playerName, double amount)
{
if (!enabled())
{
return true;
}
if (registerAvailable())
{
MethodAccount holdings = getRegisterAccount(playerName);
if (holdings == null || !holdings.hasEnough(amount))
{
return false;
}
return holdings.subtract(amount);
}
else if (iConomyUse)
{
Holdings holdings = getIconomyHoldings(playerName);
if (holdings == null || !holdings.hasEnough(amount))
{
return false;
}
holdings.subtract(amount);
return true;
}
else
{
try
{
if (!Economy.hasEnough(playerName, amount))
{
return false;
}
Economy.subtract(playerName, amount);
return true;
}
catch (Exception ex)
{
return false;
}
}
}*/
// add money to their account; returns true if successful
/*public static boolean addMoney(String playerName, double amount)
{
if (!enabled())
{
return true;
}
if (registerAvailable())
{
MethodAccount holdings = getRegisterAccount(playerName);
if (holdings == null)
{
return false;
}
return holdings.add(amount);
}
else if (iConomyUse)
{
Holdings holdings = getIconomyHoldings(playerName);
if (holdings == null)
{
return false;
}
holdings.add(amount);
return true;
}
else
{
try
{
Economy.add(playerName, amount);
return true;
}
catch (Exception ex)
{
return false;
}
}
}*/
// calculate the cost for claiming land // calculate the cost for claiming land
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction)
{ {

View File

@ -11,17 +11,12 @@ public enum Permission
OWNERSHIP_BYPASS("ownershipbypass"), OWNERSHIP_BYPASS("ownershipbypass"),
ADMIN("admin"), ADMIN("admin"),
AUTOCLAIM("autoclaim"), AUTOCLAIM("autoclaim"),
BALANCE("balance"),
BALANCE_ANY("balance.any"),
WITHDRAW("withdraw"),
PAY("pay"),
BYPASS("bypass"), BYPASS("bypass"),
CHAT("chat"), CHAT("chat"),
CLAIM("claim"), CLAIM("claim"),
CONFIG("config"), CONFIG("config"),
CREATE("create"), CREATE("create"),
DEINVITE("deinvite"), DEINVITE("deinvite"),
DEPOSIT("deposit"),
DESCRIPTION("description"), DESCRIPTION("description"),
DISBAND("disband"), DISBAND("disband"),
DISBAND_ANY("disband.any"), DISBAND_ANY("disband.any"),
@ -36,6 +31,12 @@ public enum Permission
LOCK("lock"), LOCK("lock"),
MAP("map"), MAP("map"),
MOD("mod"), MOD("mod"),
MONEY_BALANCE("money.balance"),
MONEY_BALANCE_ANY("money.balance.any"),
MONEY_DEPOSIT("money.deposit"),
MONEY_PAY("money.pay"),
MONEY_WITHDRAW("money.withdraw"),
MONEY_WITHDRAW_ANY("money.withdraw.any"),
NO_BOOM("noboom"), NO_BOOM("noboom"),
OPEN("open"), OPEN("open"),
OWNER("owner"), OWNER("owner"),