Even more command fixes.

This commit is contained in:
Olof Larsson 2013-04-16 11:05:49 +02:00
parent a84582ba21
commit e874ea60df
31 changed files with 216 additions and 158 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.cmd.arg.ARFaction;
public abstract class CmdFactionsCapeAbstract extends FCommand public abstract class CmdFactionsCapeAbstract extends FCommand
{ {
@ -20,9 +21,6 @@ public abstract class CmdFactionsCapeAbstract extends FCommand
@Override @Override
public boolean validCall(CommandSender sender, List<String> args) public boolean validCall(CommandSender sender, List<String> args)
{ {
if ( ! super.validCall(sender, args)) return false;
this.capeFaction = null; this.capeFaction = null;
this.currentCape = null; this.currentCape = null;
@ -32,7 +30,7 @@ public abstract class CmdFactionsCapeAbstract extends FCommand
return false; return false;
} }
this.capeFaction = this.argAsFaction(this.requiredArgs.size(), this.myFaction); this.capeFaction = this.arg(this.requiredArgs.size(), ARFaction.get(), this.myFaction);
if (this.capeFaction == null) return false; if (this.capeFaction == null) return false;
// Do we have permission to manage the cape of that faction? // Do we have permission to manage the cape of that faction?

View File

@ -15,6 +15,7 @@ public class CmdFactionsCapeSet extends CmdFactionsCapeAbstract
this.addAliases("set"); this.addAliases("set");
this.addRequiredArg("url"); this.addRequiredArg("url");
this.setErrorOnToManyArgs(false);
this.addRequirements(ReqHasPerm.get(Perm.CAPE_SET.node)); this.addRequirements(ReqHasPerm.get(Perm.CAPE_SET.node));
} }
@ -22,7 +23,7 @@ public class CmdFactionsCapeSet extends CmdFactionsCapeAbstract
@Override @Override
public void perform() public void perform()
{ {
String newCape = this.argAsString(0); String newCape = this.argConcatFrom(0);
if (isUrlValid(newCape)) if (isUrlValid(newCape))
{ {

View File

@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.util.SpiralTask; import com.massivecraft.factions.util.SpiralTask;
import com.massivecraft.mcore.cmd.arg.ARInteger;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
@ -26,9 +28,12 @@ public class CmdFactionsClaim extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// Read and validate input Faction forFaction = this.arg(0, ARFaction.get());
final Faction forFaction = this.argAsFaction(0, myFaction); if (forFaction == null) return;
int radius = this.argAsInt(1, 1);
Integer radius = this.arg(1, ARInteger.get(), 1);
if (radius == null) return;
if (radius < 1) if (radius < 1)
{ {
@ -40,36 +45,37 @@ public class CmdFactionsClaim extends FCommand
{ {
// single chunk // single chunk
fme.attemptClaim(forFaction, me.getLocation(), true); fme.attemptClaim(forFaction, me.getLocation(), true);
return;
} }
else
// radius claim
if (! Perm.CLAIM_RADIUS.has(sender, false))
{ {
// radius claim msg("<b>You do not have permission to claim in a radius.");
if (! Perm.CLAIM_RADIUS.has(sender, false)) return;
{
msg("<b>You do not have permission to claim in a radius.");
return;
}
new SpiralTask(PS.valueOf(me), radius)
{
private int failCount = 0;
private final int limit = ConfServer.radiusClaimFailureLimit - 1;
@Override
public boolean work()
{
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
if (success)
failCount = 0;
else if ( ! success && failCount++ >= limit)
{
this.stop();
return false;
}
return true;
}
};
} }
// TODO: I do not beleive in the spiral-task. Get rid of this. The failcount can be precalculated.
new SpiralTask(PS.valueOf(me), radius)
{
private int failCount = 0;
private final int limit = ConfServer.radiusClaimFailureLimit - 1;
@Override
public boolean work()
{
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
if (success)
failCount = 0;
else if ( ! success && failCount++ >= limit)
{
this.stop();
return false;
}
return true;
}
};
} }
} }

View File

@ -31,7 +31,7 @@ public class CmdFactionsCreate extends FCommand
@Override @Override
public void perform() public void perform()
{ {
String tag = this.argAsString(0); String tag = this.arg(0);
if (fme.hasFaction()) if (fme.hasFaction())
{ {

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsDeinvite extends FCommand public class CmdFactionsDeinvite extends FCommand
@ -15,6 +16,7 @@ public class CmdFactionsDeinvite extends FCommand
this.addRequirements(ReqHasPerm.get(Perm.DEINVITE.node)); this.addRequirements(ReqHasPerm.get(Perm.DEINVITE.node));
// TODO: Base on faction permissions instead?
senderMustBeMember = false; senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false; senderMustBeLeader = false;
@ -23,7 +25,7 @@ public class CmdFactionsDeinvite extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
if (you.getFaction() == myFaction) if (you.getFaction() == myFaction)

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsDemote extends FCommand public class CmdFactionsDemote extends FCommand
@ -24,7 +25,7 @@ public class CmdFactionsDemote extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
if (you.getFaction() != myFaction) if (you.getFaction() != myFaction)

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent; import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
@ -30,8 +31,7 @@ public class CmdFactionsDisband extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// The faction, default to your own.. but null if console sender. Faction faction = this.arg(0, ARFaction.get(), myFaction);
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) return; if (faction == null) return;
if ( ! FPerm.DISBAND.has(sender, faction, true)) return; if ( ! FPerm.DISBAND.has(sender, faction, true)) return;

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -23,11 +24,7 @@ public class CmdFactionsFlag extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction faction = myFaction; Faction faction = this.arg(0, ARFaction.get(), myFaction);
if (this.argIsSet(0))
{
faction = this.argAsFaction(0);
}
if (faction == null) return; if (faction == null) return;
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))

View File

@ -3,7 +3,10 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
@ -24,7 +27,7 @@ public class CmdFactionsInvite extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
if (you.getFaction() == myFaction) if (you.getFaction() == myFaction)

View File

@ -8,6 +8,8 @@ import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -26,10 +28,12 @@ public class CmdFactionsJoin extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction faction = this.argAsFaction(0); Faction faction = this.arg(0, ARFaction.get());
if (faction == null) return; if (faction == null) return;
FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false); FPlayer fplayer = this.arg(1, ARFPlayer.getStartAny(), fme);
if (fplayer == null) return;
boolean samePlayer = fplayer == fme; boolean samePlayer = fplayer == fme;
if (!samePlayer && ! Perm.JOIN_OTHERS.has(sender, false)) if (!samePlayer && ! Perm.JOIN_OTHERS.has(sender, false))

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -27,7 +28,7 @@ public class CmdFactionsKick extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(1, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
if (fme == you) if (fme == you)

View File

@ -7,6 +7,8 @@ import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -27,10 +29,10 @@ public class CmdFactionsLeader extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer newLeader = this.argAsBestFPlayerMatch(0); FPlayer newLeader = this.arg(0, ARFPlayer.getStartAny());
if (newLeader == null) return; if (newLeader == null) return;
Faction targetFaction = this.argAsFaction(1, myFaction); Faction targetFaction = this.arg(1, ARFaction.get(), myFaction);
if (targetFaction == null) return; if (targetFaction == null) return;
FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader(); FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader();

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -21,13 +22,9 @@ public class CmdFactionsMoneyBalance extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction faction = myFaction; Faction faction = this.arg(0, ARFaction.get(), myFaction);
if (this.argIsSet(0))
{
faction = this.argAsFaction(0);
}
if (faction == null) return; if (faction == null) return;
if (faction != myFaction && ! Perm.MONEY_BALANCE_ANY.has(sender, true)) return; if (faction != myFaction && ! Perm.MONEY_BALANCE_ANY.has(sender, true)) return;
Econ.sendBalanceInfo(fme, faction); Econ.sendBalanceInfo(fme, faction);

View File

@ -1,10 +1,13 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.arg.ARDouble;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -29,9 +32,13 @@ public class CmdFactionsMoneyDeposit extends FCommand
@Override @Override
public void perform() public void perform()
{ {
double amount = this.argAsDouble(0, 0d); Double amount = this.arg(0, ARDouble.get());
EconomyParticipator faction = this.argAsFaction(1, myFaction); if (amount == null) return;
Faction faction = this.arg(1, ARFaction.get(), myFaction);
if (faction == null) return; if (faction == null) return;
boolean success = Econ.transferMoney(fme, fme, faction, amount); boolean success = Econ.transferMoney(fme, fme, faction, amount);
if (success && ConfServer.logMoneyTransactions) if (success && ConfServer.logMoneyTransactions)

View File

@ -1,10 +1,13 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.arg.ARDouble;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -29,10 +32,13 @@ public class CmdFactionsMoneyTransferFf extends FCommand
@Override @Override
public void perform() public void perform()
{ {
double amount = this.argAsDouble(0, 0d); Double amount = this.arg(0, ARDouble.get());
EconomyParticipator from = this.argAsFaction(1); if (amount == null) return;
Faction from = this.arg(1, ARFaction.get());
if (from == null) return; if (from == null) return;
EconomyParticipator to = this.argAsFaction(2);
Faction to = this.arg(2, ARFaction.get());
if (to == null) return; if (to == null) return;
boolean success = Econ.transferMoney(fme, from, to, amount); boolean success = Econ.transferMoney(fme, from, to, amount);

View File

@ -1,10 +1,15 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.arg.ARDouble;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -29,10 +34,13 @@ public class CmdFactionsMoneyTransferFp extends FCommand
@Override @Override
public void perform() public void perform()
{ {
double amount = this.argAsDouble(0, 0d); Double amount = this.arg(0, ARDouble.get());
EconomyParticipator from = this.argAsFaction(1); if (amount == null) return;
Faction from = this.arg(1, ARFaction.get());
if (from == null) return; if (from == null) return;
EconomyParticipator to = this.argAsBestFPlayerMatch(2);
FPlayer to = this.arg(2, ARFPlayer.getStartAny());
if (to == null) return; if (to == null) return;
boolean success = Econ.transferMoney(fme, from, to, amount); boolean success = Econ.transferMoney(fme, from, to, amount);

View File

@ -1,10 +1,15 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.arg.ARDouble;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -29,10 +34,13 @@ public class CmdFactionsMoneyTransferPf extends FCommand
@Override @Override
public void perform() public void perform()
{ {
double amount = this.argAsDouble(0, 0d); Double amount = this.arg(0, ARDouble.get());
EconomyParticipator from = this.argAsBestFPlayerMatch(1); if (amount == null) return;
FPlayer from = this.arg(1, ARFPlayer.getStartAny());
if (from == null) return; if (from == null) return;
EconomyParticipator to = this.argAsFaction(2);
Faction to = this.arg(2, ARFaction.get());
if (to == null) return; if (to == null) return;
boolean success = Econ.transferMoney(fme, from, to, amount); boolean success = Econ.transferMoney(fme, from, to, amount);

View File

@ -1,10 +1,13 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.arg.ARDouble;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -28,9 +31,12 @@ public class CmdFactionsMoneyWithdraw extends FCommand
@Override @Override
public void perform() public void perform()
{ {
double amount = this.argAsDouble(0, 0d); Double amount = this.arg(0, ARDouble.get());
EconomyParticipator faction = this.argAsFaction(1, myFaction); if (amount == null) return;
Faction faction = this.arg(1, ARFaction.get(), myFaction);
if (faction == null) return; if (faction == null) return;
boolean success = Econ.transferMoney(fme, faction, fme, amount); boolean success = Econ.transferMoney(fme, faction, fme, amount);
if (success && ConfServer.logMoneyTransactions) if (success && ConfServer.logMoneyTransactions)

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsOfficer extends FCommand public class CmdFactionsOfficer extends FCommand
@ -21,7 +22,7 @@ public class CmdFactionsOfficer extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
boolean permAny = Perm.OFFICER_ANY.has(sender, false); boolean permAny = Perm.OFFICER_ANY.has(sender, false);

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.arg.ARBoolean;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsOpen extends FCommand public class CmdFactionsOpen extends FCommand
@ -22,22 +23,25 @@ public class CmdFactionsOpen extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Boolean target = this.arg(0, ARBoolean.get(), !myFaction.isOpen());
if (target == null) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(ConfServer.econCostOpen, "to open or close the faction", "for opening or closing the faction")) return; if ( ! payForCommand(ConfServer.econCostOpen, "to open or close the faction", "for opening or closing the faction")) return;
myFaction.setOpen(this.argAsBool(0, ! myFaction.isOpen())); myFaction.setOpen(target);
String open = myFaction.isOpen() ? "open" : "closed"; String descTarget = myFaction.isOpen() ? "open" : "closed";
// Inform // Inform
myFaction.msg("%s<i> changed the faction to <h>%s<i>.", fme.describeTo(myFaction, true), open); myFaction.msg("%s<i> changed the faction to <h>%s<i>.", fme.describeTo(myFaction, true), descTarget);
for (Faction faction : FactionColl.get().getAll()) for (Faction faction : FactionColl.get().getAll())
{ {
if (faction == myFaction) if (faction == myFaction)
{ {
continue; continue;
} }
faction.msg("<i>The faction %s<i> is now %s", myFaction.getTag(faction), open); faction.msg("<i>The faction %s<i> is now %s", myFaction.getTag(faction), descTarget);
} }
} }

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -13,7 +14,7 @@ public class CmdFactionsPerm extends FCommand
{ {
this.addAliases("perm"); this.addAliases("perm");
this.addOptionalArg("faction", "your"); this.addOptionalArg("faction", "you");
this.addOptionalArg("perm", "all"); this.addOptionalArg("perm", "all");
this.addOptionalArg("relation", "read"); this.addOptionalArg("relation", "read");
this.addOptionalArg("yes/no", "read"); this.addOptionalArg("yes/no", "read");
@ -25,11 +26,7 @@ public class CmdFactionsPerm extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction faction = myFaction; Faction faction = this.arg(0, ARFaction.get(), myFaction);
if (this.argIsSet(0))
{
faction = this.argAsFaction(0);
}
if (faction == null) return; if (faction == null) return;
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsPower extends FCommand public class CmdFactionsPower extends FCommand
@ -20,7 +21,7 @@ public class CmdFactionsPower extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer target = this.argAsBestFPlayerMatch(0, fme); FPlayer target = this.arg(0, ARFPlayer.getStartAny(), fme);
if (target == null) return; if (target == null) return;
if (target != fme && ! Perm.POWER_ANY.has(sender, true)) return; if (target != fme && ! Perm.POWER_ANY.has(sender, true)) return;

View File

@ -22,7 +22,7 @@ public class CmdFactionsPowerBoost extends FCommand
@Override @Override
public void perform() public void perform()
{ {
String type = this.argAsString(0).toLowerCase(); String type = this.arg(0).toLowerCase();
boolean doPlayer = true; boolean doPlayer = true;
if (type.equals("f") || type.equals("faction")) if (type.equals("f") || type.equals("faction"))
{ {

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsPromote extends FCommand public class CmdFactionsPromote extends FCommand
@ -24,7 +25,7 @@ public class CmdFactionsPromote extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
if (you.getFaction() != myFaction) if (you.getFaction() != myFaction)

View File

@ -7,6 +7,7 @@ import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.event.FactionRelationEvent;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -28,7 +29,7 @@ public abstract class CmdFactionsRelationAbstract extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction them = this.argAsFaction(0); Faction them = this.arg(0, ARFaction.get());
if (them == null) return; if (them == null) return;
/*if ( ! them.isNormal()) /*if ( ! them.isNormal())

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
@ -30,7 +31,7 @@ public class CmdFactionsSethome extends FCommand
return; return;
} }
Faction faction = this.argAsFaction(0, myFaction); Faction faction = this.arg(0, ARFaction.get(), myFaction);
if (faction == null) return; if (faction == null) return;
// Can the player set the home for this faction? // Can the player set the home for this faction?

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
@ -30,12 +31,8 @@ public class CmdFactionsShow extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction faction = myFaction; Faction faction = this.arg(0, ARFaction.get(), myFaction);
if (this.argIsSet(0)) if (faction == null) return;
{
faction = this.argAsFaction(0);
if (faction == null) return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(ConfServer.econCostShow, "to show faction information", "for showing faction information")) return; if ( ! payForCommand(ConfServer.econCostShow, "to show faction information", "for showing faction information")) return;

View File

@ -30,7 +30,7 @@ public class CmdFactionsTag extends FCommand
@Override @Override
public void perform() public void perform()
{ {
String tag = this.argAsString(0); String tag = this.arg(0);
// TODO does not first test cover selfcase? // TODO does not first test cover selfcase?
if (FactionColl.get().isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) if (FactionColl.get().isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag()))

View File

@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.arg.ARString;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -24,11 +26,11 @@ public class CmdFactionsTitle extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
args.remove(0); String title = this.argConcatFrom(1, ARString.get(), "");
String title = Txt.implode(args, " "); if (title == null) return;
if ( ! canIAdministerYou(fme, you)) return; if ( ! canIAdministerYou(fme, you)) return;

View File

@ -1,9 +1,13 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.MCommand; import com.massivecraft.mcore.cmd.MCommand;
import com.massivecraft.mcore.util.Txt;
public abstract class FCommand extends MCommand public abstract class FCommand extends MCommand
{ {
@ -16,4 +20,66 @@ public abstract class FCommand extends MCommand
this.fme = FPlayerColl.get().get(this.sender); this.fme = FPlayerColl.get().get(this.sender);
this.myFaction = this.fme.getFaction(); this.myFaction = this.fme.getFaction();
} }
// -------------------------------------------- //
// COMMONLY USED LOGIC
// -------------------------------------------- //
public boolean canIAdministerYou(FPlayer i, FPlayer you)
{
if ( ! i.getFaction().equals(you.getFaction()))
{
i.sendMessage(Txt.parse("%s <b>is not in the same faction as you.",you.describeTo(i, true)));
return false;
}
if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) )
{
return true;
}
if (you.getRole().equals(Rel.LEADER))
{
i.sendMessage(Txt.parse("<b>Only the faction admin can do that."));
}
else if (i.getRole().equals(Rel.OFFICER))
{
if ( i == you )
{
return true; //Moderators can control themselves
}
else
{
i.sendMessage(Txt.parse("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(Txt.parse("<b>You must be a faction moderator to do that."));
}
return false;
}
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
public boolean payForCommand(double cost, String toDoThis, String forDoingThis)
{
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
else
return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis);
}
// like above, but just make sure they can pay; returns true unless person can't afford the cost
public boolean canAffordCommand(double cost, String toDoThis)
{
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
return Econ.hasAtLeast(myFaction, cost, toDoThis);
else
return Econ.hasAtLeast(fme, cost, toDoThis);
}
} }

View File

@ -379,65 +379,5 @@ public abstract class FCommandOld extends MCommand<Factions>
return this.argAsRel(idx, null); return this.argAsRel(idx, null);
} }
// -------------------------------------------- //
// Commonly used logic
// -------------------------------------------- //
public boolean canIAdministerYou(FPlayer i, FPlayer you)
{
if ( ! i.getFaction().equals(you.getFaction()))
{
i.sendMessage(Txt.parse("%s <b>is not in the same faction as you.",you.describeTo(i, true)));
return false;
}
if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) )
{
return true;
}
if (you.getRole().equals(Rel.LEADER))
{
i.sendMessage(Txt.parse("<b>Only the faction admin can do that."));
}
else if (i.getRole().equals(Rel.OFFICER))
{
if ( i == you )
{
return true; //Moderators can control themselves
}
else
{
i.sendMessage(Txt.parse("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(Txt.parse("<b>You must be a faction moderator to do that."));
}
return false;
}
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
public boolean payForCommand(double cost, String toDoThis, String forDoingThis)
{
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
else
return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis);
}
// like above, but just make sure they can pay; returns true unless person can't afford the cost
public boolean canAffordCommand(double cost, String toDoThis)
{
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
return Econ.hasAtLeast(myFaction, cost, toDoThis);
else
return Econ.hasAtLeast(fme, cost, toDoThis);
}
} }