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

@ -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( 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>To lear more use the money command." ));
pageLines.add( "" );
pageLines.add( p.cmdBase.cmdMoney.getUseageTemplate() );
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( "" );
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;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
public class CmdWithdraw extends FCommand
public class CmdMoneyWithdraw extends FCommand
{
public CmdWithdraw()
public CmdMoneyWithdraw()
{
this.aliases.add("withdraw");
this.requiredArgs.add("amount");
//this.optionalArgs.put("factiontag", "yours");
this.optionalArgs.put("faction", "yours");
this.permission = Permission.WITHDRAW.node;
this.disableOnLock = true;
this.permission = Permission.MONEY_WITHDRAW.node;
this.isMoneyCommand = true;
this.isBankCommand = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@ -27,9 +27,10 @@ public class CmdWithdraw extends FCommand
@Override
public void perform()
{
if ( ! Conf.bankEnabled) return;
Econ.transferMoney(fme, myFaction, fme, this.argAsDouble(0, 0));
double amount = this.argAsDouble(0, 0);
Faction faction = this.argAsFaction(1, myFaction);
if (faction == null) return;
Econ.transferMoney(fme, faction, fme, amount);
/*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 CmdAutoSafeclaim cmdAutoSafeclaim = new CmdAutoSafeclaim();
public CmdAutoWarclaim cmdAutoWarclaim = new CmdAutoWarclaim();
public CmdBalance cmdBalance = new CmdBalance();
public CmdBoom cmdBoom = new CmdBoom();
public CmdBypass cmdBypass = new CmdBypass();
public CmdChat cmdChat = new CmdChat();
@ -16,7 +15,6 @@ public class FCmdRoot extends FCommand
public CmdConfig cmdConfig = new CmdConfig();
public CmdCreate cmdCreate = new CmdCreate();
public CmdDeinvite cmdDeinvite = new CmdDeinvite();
public CmdDeposit cmdDeposit = new CmdDeposit();
public CmdDescription cmdDescription = new CmdDescription();
public CmdDisband cmdDisband = new CmdDisband();
public CmdHelp cmdHelp = new CmdHelp();
@ -29,10 +27,10 @@ public class FCmdRoot extends FCommand
public CmdLock cmdLock = new CmdLock();
public CmdMap cmdMap = new CmdMap();
public CmdMod cmdMod = new CmdMod();
public CmdMoney cmdMoney = new CmdMoney();
public CmdOpen cmdOpen = new CmdOpen();
public CmdOwner cmdOwner = new CmdOwner();
public CmdOwnerList cmdOwnerList = new CmdOwnerList();
public CmdPay cmdPay = new CmdPay();
public CmdPeaceful cmdPeaceful = new CmdPeaceful();
public CmdPermanent cmdPermanent = new CmdPermanent();
public CmdPower cmdPower = new CmdPower();
@ -52,7 +50,6 @@ public class FCmdRoot extends FCommand
public CmdVersion cmdVersion = new CmdVersion();
public CmdWarclaim cmdWarclaim = new CmdWarclaim();
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
public CmdWithdraw cmdWithdraw = new CmdWithdraw();
public FCmdRoot()
{
@ -60,6 +57,9 @@ public class FCmdRoot extends FCommand
this.aliases.addAll(Conf.baseCommandAliases);
this.allowNoSlashAccess = Conf.allowNoSlashCommand;
//this.requiredArgs.add("");
//this.optionalArgs.put("","")
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
@ -76,7 +76,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdAutoClaim);
this.addSubCommand(this.cmdAutoSafeclaim);
this.addSubCommand(this.cmdAutoWarclaim);
this.addSubCommand(this.cmdBalance);
this.addSubCommand(this.cmdBoom);
this.addSubCommand(this.cmdBypass);
this.addSubCommand(this.cmdChat);
@ -84,7 +83,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdConfig);
this.addSubCommand(this.cmdCreate);
this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDeposit);
this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband);
this.addSubCommand(this.cmdHelp);
@ -97,10 +95,10 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdLock);
this.addSubCommand(this.cmdMap);
this.addSubCommand(this.cmdMod);
this.addSubCommand(this.cmdMoney);
this.addSubCommand(this.cmdOpen);
this.addSubCommand(this.cmdOwner);
this.addSubCommand(this.cmdOwnerList);
this.addSubCommand(this.cmdPay);
this.addSubCommand(this.cmdPeaceful);
this.addSubCommand(this.cmdPermanent);
this.addSubCommand(this.cmdPower);
@ -120,7 +118,6 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdVersion);
this.addSubCommand(this.cmdWarclaim);
this.addSubCommand(this.cmdWarunclaimall);
this.addSubCommand(this.cmdWithdraw);
}
@Override

View File

@ -26,6 +26,9 @@ public abstract class FCommand extends MCommand<P>
public boolean senderMustBeModerator;
public boolean senderMustBeAdmin;
public boolean isMoneyCommand;
public boolean isBankCommand;
public FCommand()
{
super(P.p);
@ -33,6 +36,10 @@ public abstract class FCommand extends MCommand<P>
// Due to safety reasons it defaults to disable on lock.
disableOnLock = true;
// The money commands must be disabled if money should not be used.
isMoneyCommand = false;
isBankCommand = false;
senderMustBeMember = false;
senderMustBeModerator = 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.");
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;
}