From 4b9bdf0d94820f293696b28c71fa0544da8e3f25 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 16 Apr 2013 12:04:12 +0200 Subject: [PATCH] No compiletime errors anymore, how kewl. Let's test. --- plugin.yml | 14 +- .../factions/FactionListComparator.java | 49 +++ .../factions/cmd/CmdFactions.java | 6 +- .../factions/cmd/CmdFactionsAccess.java | 10 +- .../factions/cmd/CmdFactionsDeinvite.java | 8 +- .../factions/cmd/CmdFactionsDescription.java | 5 +- .../factions/cmd/CmdFactionsHome.java | 4 +- .../factions/cmd/CmdFactionsInvite.java | 7 +- .../factions/cmd/CmdFactionsLeader.java | 2 +- .../factions/cmd/CmdFactionsLeave.java | 5 +- .../factions/cmd/CmdFactionsList.java | 79 +--- .../factions/cmd/CmdFactionsMoney.java | 14 +- .../factions/cmd/CmdFactionsMoneyBalance.java | 4 +- .../factions/cmd/CmdFactionsMoneyDeposit.java | 5 +- .../cmd/CmdFactionsMoneyTransferFf.java | 5 +- .../cmd/CmdFactionsMoneyTransferFp.java | 5 +- .../cmd/CmdFactionsMoneyTransferPf.java | 5 +- .../cmd/CmdFactionsMoneyWithdraw.java | 5 +- .../factions/cmd/CmdFactionsOpen.java | 5 +- .../cmd/CmdFactionsRelationAbstract.java | 5 +- .../factions/cmd/CmdFactionsTag.java | 5 +- .../factions/cmd/CmdFactionsTitle.java | 6 +- .../factions/cmd/CmdFactionsUnclaimall.java | 5 +- .../factions/cmd/FCommandOld.java | 383 ------------------ .../cmd/req/ReqBankCommandsEnabled.java | 42 ++ .../factions/cmd/req/ReqRoleIsAtLeast.java | 2 +- 26 files changed, 168 insertions(+), 517 deletions(-) create mode 100644 src/com/massivecraft/factions/FactionListComparator.java delete mode 100644 src/com/massivecraft/factions/cmd/FCommandOld.java create mode 100644 src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java diff --git a/plugin.yml b/plugin.yml index eb30322e..1f9add2d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -44,13 +44,13 @@ permissions: factions.list: {description: see a list of the factions} factions.lock: {description: lock all write stuff} factions.map: {description: show the territory map, and set optional auto update} - 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.f2f: {description: transfer money from faction to faction} - factions.money.f2p: {description: transfer money from faction to player} - factions.money.p2f: {description: transfer money from player to faction} - factions.money.withdraw: {description: withdraw money from your faction bank} + factions.money.balance: {description: show money balance for a faction} + factions.money.balance.any: {description: show money balance for another faction} + factions.money.deposit: {description: deposit money to faction bank} + factions.money.f2f: {description: transfer f --> f} + factions.money.f2p: {description: transfer f --> p} + factions.money.p2f: {description: transfer p --> f} + factions.money.withdraw: {description: withdraw money from faction bank} factions.officer: {description: give or revoke officer rights} factions.officer.any: {description: give or revoke officer rights for any player in any faction} factions.open: {description: switch if invitation is required to join} diff --git a/src/com/massivecraft/factions/FactionListComparator.java b/src/com/massivecraft/factions/FactionListComparator.java new file mode 100644 index 00000000..a795af13 --- /dev/null +++ b/src/com/massivecraft/factions/FactionListComparator.java @@ -0,0 +1,49 @@ +package com.massivecraft.factions; + +import java.util.Comparator; + +import com.massivecraft.mcore.util.MUtil; + +public class FactionListComparator implements Comparator +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static FactionListComparator i = new FactionListComparator(); + public static FactionListComparator get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COMPARATOR + // -------------------------------------------- // + + @Override + public int compare(Faction f1, Faction f2) + { + int ret = 0; + + // Null --> Low + if (f1 == null && f2 == null) ret = 0; + if (f1 == null) ret = -1; + if (f2 == null) ret = +1; + if (ret != 0) return ret; + + // None --> High + if (f1.isNone() && f2.isNone()) ret = 0; + if (f1.isNone()) ret = +1; + if (f2.isNone()) ret = -1; + if (ret != 0) return ret; + + // Players Online --> High + ret = f1.getFPlayersWhereOnline(true).size() - f2.getFPlayersWhereOnline(true).size(); + if (ret != 0) return ret; + + // Players Total --> High + ret = f1.getFPlayers().size() - f2.getFPlayers().size(); + if (ret != 0) return ret; + + // Tie by Id + return MUtil.compare(f1.getId(), f2.getId()); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 9e6bba1a..470d7691 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -3,9 +3,7 @@ package com.massivecraft.factions.cmd; import java.util.Collections; import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.Factions; import com.massivecraft.mcore.cmd.HelpCommand; -import com.massivecraft.mcore.util.Txt; public class CmdFactions extends FCommand { @@ -57,8 +55,8 @@ public class CmdFactions extends FCommand // TODO: When is this required? Should this be added to MCore? this.aliases.removeAll(Collections.singletonList(null)); - this.setHelpShort("The faction base command"); - this.helpLong.add(Txt.parse("This command contains all faction stuff.")); + this.setDesc("The faction base command"); + this.setHelp("This command contains all faction stuff."); this.addSubCommand(HelpCommand.get()); this.addSubCommand(this.cmdFactionsList); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java index 1a65d570..98d2e6d8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java @@ -6,6 +6,8 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -21,9 +23,9 @@ public class CmdFactionsAccess extends FCommand this.addOptionalArg("view|p|player|f|faction", "view"); this.addOptionalArg("name", "you"); - this.setHelpShort("view or grant access for the claimed territory you are in"); + this.setDesc("view or grant access for the claimed territory you are in"); - // TODO: Missing permission node here! + // TODO: Missing permission node here!? this.addRequirements(ReqIsPlayer.get()); } @@ -71,14 +73,14 @@ public class CmdFactionsAccess extends FCommand if (doPlayer) { - FPlayer targetPlayer = this.argAsBestFPlayerMatch(1, fme); + FPlayer targetPlayer = this.arg(1, ARFPlayer.getStartAny(), fme); if (targetPlayer == null) return; added = territory.toggleFPlayer(targetPlayer); target = "Player \""+targetPlayer.getName()+"\""; } else { - Faction targetFaction = this.argAsFaction(1, myFaction); + Faction targetFaction = this.arg(1, ARFaction.get(), myFaction); if (targetFaction == null) return; added = territory.toggleFaction(targetFaction); target = "Faction \""+targetFaction.getTag()+"\""; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java index 964bdabe..ab7e3350 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsDeinvite extends FCommand @@ -16,11 +18,7 @@ public class CmdFactionsDeinvite extends FCommand this.addRequiredArg("player"); this.addRequirements(ReqHasPerm.get(Perm.DEINVITE.node)); - - // TODO: Base on faction permissions instead? - senderMustBeMember = false; - senderMustBeOfficer = true; - senderMustBeLeader = false; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java index 9029a786..542c7122 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -4,6 +4,8 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -17,8 +19,7 @@ public class CmdFactionsDescription extends FCommand this.setErrorOnToManyArgs(false); this.addRequirements(ReqHasPerm.get(Perm.DESCRIPTION.node)); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index 39b2b35b..8359dd1f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -16,6 +16,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; @@ -31,8 +32,7 @@ public class CmdFactionsHome extends FCommand this.addRequirements(ReqHasPerm.get(Perm.HOME.node)); this.addRequirements(ReqIsPlayer.get()); - - senderMustBeMember = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.RECRUIT)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java index 51c9c21c..da0ee0e7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -3,11 +3,11 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFPlayer; -import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; @@ -21,8 +21,7 @@ public class CmdFactionsInvite extends FCommand this.addRequirements(ReqHasPerm.get(Perm.INVITE.node)); this.addRequirements(ReqIsPlayer.get()); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java index 82fec7e3..20d9a5da 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java @@ -47,7 +47,7 @@ public class CmdFactionsLeader extends FCommand // Follow the standard rules if (fme.getRole() != Rel.LEADER || targetFaction != myFaction) { - sender.sendMessage(Txt.parse("You must be leader of the faction to %s.", this.getHelpShort())); + sender.sendMessage(Txt.parse("You must be leader of the faction to %s.", this.getDesc())); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java index d6ecbb3d..c2e02349 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsLeave extends FCommand { @@ -10,8 +12,7 @@ public class CmdFactionsLeave extends FCommand { this.addAliases("leave"); this.addRequirements(ReqHasPerm.get(Perm.LEAVE.node)); - - senderMustBeMember = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.RECRUIT)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index b56c9d6b..80b8b224 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -1,13 +1,14 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; +import java.util.List; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; +import com.massivecraft.factions.FactionListComparator; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.arg.ARInteger; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -27,78 +28,30 @@ public class CmdFactionsList extends FCommand @Override public void perform() { + Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); + if (pageHumanBased == null) return; + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(ConfServer.econCostList, "to list the factions", "for listing the factions")) return; - ArrayList factionList = new ArrayList(FactionColl.get().getAll()); - - factionList.remove(FactionColl.get().getNone()); - // TODO: Add flag SECRET To factions instead. - //factionList.remove(Factions.i.getSafeZone()); - //factionList.remove(Factions.i.getWarZone()); + // Create Messages + List lines = new ArrayList(); - // Sort by total followers first - Collections.sort(factionList, new Comparator(){ - @Override - public int compare(Faction f1, Faction f2) { - int f1Size = f1.getFPlayers().size(); - int f2Size = f2.getFPlayers().size(); - if (f1Size < f2Size) - return 1; - else if (f1Size > f2Size) - return -1; - return 0; - } - }); - - // Then sort by how many members are online now - Collections.sort(factionList, new Comparator(){ - @Override - public int compare(Faction f1, Faction f2) { - int f1Size = f1.getFPlayersWhereOnline(true).size(); - int f2Size = f2.getFPlayersWhereOnline(true).size(); - if (f1Size < f2Size) - return 1; - else if (f1Size > f2Size) - return -1; - return 0; - } - }); - - ArrayList lines = new ArrayList(); - -/* // this code was really slow on large servers, getting full info for every faction and then only showing 9 of them; rewritten below - lines.add(Txt.parse("Factionless %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size())); - for (Faction faction : factionList) - { - lines.add(Txt.parse("%s %d/%d online, %d/%d/%d", - faction.getTag(fme), - faction.getFPlayersWhereOnline(true).size(), - faction.getFPlayers().size(), - faction.getLandRounded(), - faction.getPowerRounded(), - faction.getPowerMaxRounded()) - ); - } - - sendMessage(Txt.getPage(lines, this.argAsInt(0, 1), "Faction List")); - */ - - factionList.add(0, FactionColl.get().getNone()); + ArrayList factionList = new ArrayList(FactionColl.get().getAll(null, FactionListComparator.get())); final int pageheight = 9; - int pagenumber = this.argAsInt(0, 1); + int pagecount = (factionList.size() / pageheight) + 1; - if (pagenumber > pagecount) - pagenumber = pagecount; - else if (pagenumber < 1) - pagenumber = 1; - int start = (pagenumber - 1) * pageheight; + if (pageHumanBased > pagecount) + pageHumanBased = pagecount; + else if (pageHumanBased < 1) + pageHumanBased = 1; + int start = (pageHumanBased - 1) * pageheight; int end = start + pageheight; if (end > factionList.size()) end = factionList.size(); - lines.add(Txt.titleize("Faction List "+pagenumber+"/"+pagecount)); + lines.add(Txt.titleize("Faction List "+pageHumanBased+"/"+pagecount)); for (Faction faction : factionList.subList(start, end)) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java index 8581e760..c981696a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java @@ -1,8 +1,7 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.mcore.cmd.HelpCommand; -import com.massivecraft.mcore.util.Txt; public class CmdFactionsMoney extends FCommand { @@ -17,15 +16,10 @@ public class CmdFactionsMoney extends FCommand { this.addAliases("money"); - this.isMoneyCommand = true; + this.setDesc("faction money commands"); + this.setHelp("The faction money commands."); - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - - this.setHelpShort("faction money commands"); - this.helpLong.add(Txt.parse("The faction money commands.")); + this.addRequirements(ReqBankCommandsEnabled.get()); this.addSubCommand(this.cmdMoneyBalance); this.addSubCommand(this.cmdMoneyDeposit); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java index b155d839..8b107238 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; @@ -15,8 +16,7 @@ public class CmdFactionsMoneyBalance extends FCommand this.addOptionalArg("faction", "you"); this.addRequirements(ReqHasPerm.get(Perm.MONEY_BALANCE.node)); - - this.setHelpShort("show faction balance"); + this.addRequirements(ReqBankCommandsEnabled.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java index a7f56e1b..819200b8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java @@ -5,7 +5,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -25,8 +25,7 @@ public class CmdFactionsMoneyDeposit extends FCommand this.addOptionalArg("faction", "you"); this.addRequirements(ReqHasPerm.get(Perm.MONEY_DEPOSIT.node)); - - this.setHelpShort("deposit money"); + this.addRequirements(ReqBankCommandsEnabled.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java index 186eba75..d5f11c47 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java @@ -4,7 +4,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.arg.ARDouble; @@ -25,8 +25,7 @@ public class CmdFactionsMoneyTransferFf extends FCommand this.addRequiredArg("faction"); this.addRequirements(ReqHasPerm.get(Perm.MONEY_F2F.node)); - - this.setHelpShort("transfer f -> f"); + this.addRequirements(ReqBankCommandsEnabled.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java index b3be667a..45c09b56 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java @@ -6,7 +6,7 @@ import com.massivecraft.factions.Faction; 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.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.arg.ARDouble; @@ -27,8 +27,7 @@ public class CmdFactionsMoneyTransferFp extends FCommand this.addRequiredArg("player"); this.addRequirements(ReqHasPerm.get(Perm.MONEY_F2P.node)); - - this.setHelpShort("transfer f -> p"); + this.addRequirements(ReqBankCommandsEnabled.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java index e77ebe9b..74d0adf3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java @@ -6,7 +6,7 @@ import com.massivecraft.factions.Faction; 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.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.arg.ARDouble; @@ -27,8 +27,7 @@ public class CmdFactionsMoneyTransferPf extends FCommand this.addRequiredArg("faction"); this.addRequirements(ReqHasPerm.get(Perm.MONEY_P2F.node)); - - this.setHelpShort("transfer p -> f"); + this.addRequirements(ReqBankCommandsEnabled.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java index a665564c..31e2540b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java @@ -4,7 +4,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.arg.ARDouble; @@ -24,8 +24,7 @@ public class CmdFactionsMoneyWithdraw extends FCommand this.addOptionalArg("faction", "you"); this.addRequirements(ReqHasPerm.get(Perm.MONEY_WITHDRAW.node)); - - this.setHelpShort("withdraw money"); + this.addRequirements(ReqBankCommandsEnabled.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java index bb979ec2..b221c3d3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java @@ -4,6 +4,8 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -16,8 +18,7 @@ public class CmdFactionsOpen extends FCommand this.addOptionalArg("yes/no", "toggle"); this.addRequirements(ReqHasPerm.get(Perm.OPEN.node)); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index ebe6009d..23c28084 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -8,10 +8,10 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.req.ReqHasPerm; -import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public abstract class CmdFactionsRelationAbstract extends FCommand { @@ -22,8 +22,7 @@ public abstract class CmdFactionsRelationAbstract extends FCommand this.addAliases("faction"); this.addRequirements(ReqHasPerm.get(Perm.RELATION.node)); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index 014393c0..1a3b0adc 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -8,6 +8,8 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.event.FactionRenameEvent; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.util.MiscUtil; @@ -23,8 +25,7 @@ public class CmdFactionsTag extends FCommand this.addRequiredArg("new tag"); this.addRequirements(ReqHasPerm.get(Perm.TAG.node)); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java index e8063ee2..11771cd6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java @@ -3,11 +3,12 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.arg.ARString; import com.massivecraft.mcore.cmd.req.ReqHasPerm; -import com.massivecraft.mcore.util.Txt; public class CmdFactionsTitle extends FCommand { @@ -19,8 +20,7 @@ public class CmdFactionsTitle extends FCommand this.addOptionalArg("title", ""); this.addRequirements(ReqHasPerm.get(Perm.TITLE.node)); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index b92c0534..587e0ef0 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -6,6 +6,8 @@ import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.event.LandUnclaimAllEvent; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; @@ -18,8 +20,7 @@ public class CmdFactionsUnclaimall extends FCommand this.addAliases("unclaimall", "declaimall"); this.addRequirements(ReqHasPerm.get(Perm.UNCLAIM_ALL.node)); - - senderMustBeOfficer = true; + this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); } @Override diff --git a/src/com/massivecraft/factions/cmd/FCommandOld.java b/src/com/massivecraft/factions/cmd/FCommandOld.java deleted file mode 100644 index 7b104c3f..00000000 --- a/src/com/massivecraft/factions/cmd/FCommandOld.java +++ /dev/null @@ -1,383 +0,0 @@ -package com.massivecraft.factions.cmd; - -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.factions.FFlag; -import com.massivecraft.factions.FPerm; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.FPlayerColl; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.FactionColl; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.zcore.MCommand; -import com.massivecraft.mcore.util.Txt; - - -public abstract class FCommandOld extends MCommand -{ - public FPlayer fme; - public Faction myFaction; - - // TODO: All these are "command reqs" - public boolean senderMustBeMember; - public boolean senderMustBeOfficer; - public boolean senderMustBeLeader; - - public boolean isMoneyCommand; - - public FCommandOld() - { - super(Factions.get()); - - // The money commands must be disabled if money should not be used. - isMoneyCommand = false; - - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - } - - @Override - public void execute(CommandSender sender, List args, List> commandChain) - { - if (sender instanceof Player) - { - this.fme = FPlayerColl.get().get(sender); - this.myFaction = this.fme.getFaction(); - } - else - { - this.fme = null; - this.myFaction = null; - } - super.execute(sender, args, commandChain); - } - - @Override - public boolean isEnabled() - { - if (this.isMoneyCommand && ! ConfServer.econEnabled) - { - msg("Faction economy features are disabled on this server."); - return false; - } - - if (this.isMoneyCommand && ! ConfServer.bankEnabled) - { - msg("The faction bank system is disabled on this server."); - return false; - } - - return true; - } - - @Override - public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) - { - boolean superValid = super.validSenderType(sender, informSenderIfNot); - if ( ! superValid) return false; - - if ( ! (this.senderMustBeMember || this.senderMustBeOfficer || this.senderMustBeLeader)) return true; - - if ( ! (sender instanceof Player)) return false; - - FPlayer fplayer = FPlayerColl.get().get((Player)sender); - - if ( ! fplayer.hasFaction()) - { - sender.sendMessage(Txt.parse("You are not member of any faction.")); - return false; - } - - if (this.senderMustBeOfficer && ! fplayer.getRole().isAtLeast(Rel.OFFICER)) - { - sender.sendMessage(Txt.parse("Only faction moderators can %s.", this.getHelpShort())); - return false; - } - - if (this.senderMustBeLeader && ! fplayer.getRole().isAtLeast(Rel.LEADER)) - { - sender.sendMessage(Txt.parse("Only faction admins can %s.", this.getHelpShort())); - return false; - } - - return true; - } - - // -------------------------------------------- // - // Assertions - // -------------------------------------------- // - - // These are not used. Remove in the future if no need for them arises. - - /* - public boolean assertHasFaction() - { - if (me == null) return true; - - if ( ! fme.hasFaction()) - { - sendMessage("You are not member of any faction."); - return false; - } - return true; - } - - public boolean assertMinRole(Rel role) - { - if (me == null) return true; - - if (fme.getRole().isLessThan(role)) - { - msg("You must be "+role+" to "+this.getHelpShort()+"."); - return false; - } - return true; - }*/ - - // -------------------------------------------- // - // Argument Readers - // -------------------------------------------- // - - // TODO: Convert these arg-readers to MCore ArgReaders. - - // FPLAYER ====================== - public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) - { - FPlayer ret = def; - - if (name != null) - { - FPlayer fplayer = FPlayerColl.get().get(name); - if (fplayer != null) - { - ret = fplayer; - } - } - - if (msg && ret == null) - { - this.msg("No player \"

%s\" could be found.", name); - } - - return ret; - } - public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) - { - return this.strAsFPlayer(this.argAsString(idx), def, msg); - } - public FPlayer argAsFPlayer(int idx, FPlayer def) - { - return this.argAsFPlayer(idx, def, true); - } - public FPlayer argAsFPlayer(int idx) - { - return this.argAsFPlayer(idx, null); - } - - // BEST FPLAYER MATCH ====================== - public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) - { - FPlayer ret = def; - - if (name != null) - { - // TODO: Easy fix for now - //FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name); - FPlayer fplayer = FPlayerColl.get().getId2entity().get(name); - if (fplayer != null) - { - ret = fplayer; - } - } - - if (msg && ret == null) - { - this.msg("No player match found for \"

%s\".", name); - } - - return ret; - } - public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) - { - return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg); - } - public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) - { - return this.argAsBestFPlayerMatch(idx, def, true); - } - public FPlayer argAsBestFPlayerMatch(int idx) - { - return this.argAsBestFPlayerMatch(idx, null); - } - - // FACTION ====================== - public Faction strAsFaction(String name, Faction def, boolean msg) - { - Faction ret = def; - - if (name != null) - { - Faction faction = null; - - // First we try an exact match - if (faction == null) - { - faction = FactionColl.get().getByTag(name); - } - - // Next we match faction tags - if (faction == null) - { - faction = FactionColl.get().getBestTagMatch(name); - } - - // Next we match player names - if (faction == null) - { - // TODO: Easy fix for now - //FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name); - FPlayer fplayer = FPlayerColl.get().getId2entity().get(name); - - if (fplayer != null) - { - faction = fplayer.getFaction(); - } - } - - if (faction != null) - { - ret = faction; - } - } - - if (msg && ret == null) - { - this.msg("The faction or player \"

%s\" could not be found.", name); - } - - return ret; - } - public Faction argAsFaction(int idx, Faction def, boolean msg) - { - return this.strAsFaction(this.argAsString(idx), def, msg); - } - public Faction argAsFaction(int idx, Faction def) - { - return this.argAsFaction(idx, def, true); - } - public Faction argAsFaction(int idx) - { - return this.argAsFaction(idx, null); - } - - // FACTION FLAG ====================== - public FFlag strAsFactionFlag(String name, FFlag def, boolean msg) - { - FFlag ret = def; - - if (name != null) - { - FFlag flag = FFlag.parse(name); - if (flag != null) - { - ret = flag; - } - } - - if (msg && ret == null) - { - this.msg("The faction-flag \"

%s\" could not be found.", name); - } - - return ret; - } - public FFlag argAsFactionFlag(int idx, FFlag def, boolean msg) - { - return this.strAsFactionFlag(this.argAsString(idx), def, msg); - } - public FFlag argAsFactionFlag(int idx, FFlag def) - { - return this.argAsFactionFlag(idx, def, true); - } - public FFlag argAsFactionFlag(int idx) - { - return this.argAsFactionFlag(idx, null); - } - - // FACTION PERM ====================== - public FPerm strAsFactionPerm(String name, FPerm def, boolean msg) - { - FPerm ret = def; - - if (name != null) - { - FPerm perm = FPerm.parse(name); - if (perm != null) - { - ret = perm; - } - } - - if (msg && ret == null) - { - this.msg("The faction-perm \"

%s\" could not be found.", name); - } - - return ret; - } - public FPerm argAsFactionPerm(int idx, FPerm def, boolean msg) - { - return this.strAsFactionPerm(this.argAsString(idx), def, msg); - } - public FPerm argAsFactionPerm(int idx, FPerm def) - { - return this.argAsFactionPerm(idx, def, true); - } - public FPerm argAsFactionPerm(int idx) - { - return this.argAsFactionPerm(idx, null); - } - - // FACTION REL ====================== - public Rel strAsRel(String name, Rel def, boolean msg) - { - Rel ret = def; - - if (name != null) - { - Rel perm = Rel.parse(name); - if (perm != null) - { - ret = perm; - } - } - - if (msg && ret == null) - { - this.msg("The role \"

%s\" could not be found.", name); - } - - return ret; - } - public Rel argAsRel(int idx, Rel def, boolean msg) - { - return this.strAsRel(this.argAsString(idx), def, msg); - } - public Rel argAsRel(int idx, Rel def) - { - return this.argAsRel(idx, def, true); - } - public Rel argAsRel(int idx) - { - return this.argAsRel(idx, null); - } - - -} diff --git a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java new file mode 100644 index 00000000..e4838316 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd.req; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.ConfServer; +import com.massivecraft.mcore.cmd.MCommand; +import com.massivecraft.mcore.cmd.req.ReqAbstract; +import com.massivecraft.mcore.util.Txt; + +public class ReqBankCommandsEnabled extends ReqAbstract +{ + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled(); + public static ReqBankCommandsEnabled get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MCommand command) + { + return ConfServer.econEnabled && ConfServer.bankEnabled; + } + + @Override + public String createErrorMessage(CommandSender sender, MCommand command) + { + if (!ConfServer.bankEnabled) + { + return Txt.parse("The Factions bank system is disabled on this server."); + } + + return Txt.parse("The Factions economy features are disabled on this server."); + } + +} diff --git a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java index 5eb7e85b..811af272 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java +++ b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java @@ -40,7 +40,7 @@ public class ReqRoleIsAtLeast extends ReqAbstract @Override public String createErrorMessage(CommandSender sender, MCommand command) { - return Txt.parse("You must be %s or higher to do this.", Txt.getNicedEnum(this.rel)); + return Txt.parse("You must be %s or higher to "+(command == null ? "do that" : command.getDesc())+".", Txt.getNicedEnum(this.rel)); } }