From 43d2354f043de01774b6541d7aac3d8ee7795b5d Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Thu, 9 Apr 2015 14:35:39 +0200 Subject: [PATCH] Update ArgReaders --- .../factions/cmd/arg/ARFaction.java | 23 ++++++++-- .../factions/cmd/arg/ARMFlag.java | 10 +++- .../factions/cmd/arg/ARMPerm.java | 10 +++- .../factions/cmd/arg/ARMPlayer.java | 6 +-- .../massivecraft/factions/cmd/arg/ARRank.java | 46 ++++++++++++++----- .../massivecraft/factions/cmd/arg/ARRel.java | 8 +++- .../factions/cmd/arg/ARSortMPlayer.java | 18 +++++++- 7 files changed, 96 insertions(+), 25 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/arg/ARFaction.java b/src/com/massivecraft/factions/cmd/arg/ARFaction.java index 9cacfb6d..27b142f4 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARFaction.java +++ b/src/com/massivecraft/factions/cmd/arg/ARFaction.java @@ -1,16 +1,20 @@ package com.massivecraft.factions.cmd.arg; +import java.util.Collection; +import java.util.List; + import org.bukkit.command.CommandSender; -import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.cmd.arg.ArgReaderAbstract; +import com.massivecraft.massivecore.cmd.arg.ARAbstract; +import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.util.IdUtil; -public class ARFaction extends ArgReaderAbstract +public class ARFaction extends ARAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -55,5 +59,18 @@ public class ARFaction extends ArgReaderAbstract throw new MassiveException().addMsg("No faction or player matching \"

%s\".", str); } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + List ret = new MassiveList(); + + for (Faction faction : FactionColl.get().getAll()) + { + ret.add(faction.getName()); + } + + return ret; + } } diff --git a/src/com/massivecraft/factions/cmd/arg/ARMFlag.java b/src/com/massivecraft/factions/cmd/arg/ARMFlag.java index 6e362fb5..0cc47b47 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARMFlag.java +++ b/src/com/massivecraft/factions/cmd/arg/ARMFlag.java @@ -24,7 +24,7 @@ public class ARMFlag extends ARAbstractSelect // -------------------------------------------- // @Override - public String typename() + public String getTypeName() { return "faction flag"; } @@ -70,6 +70,12 @@ public class ARMFlag extends ARAbstractSelect return ret; } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + return this.altNames(sender); + } // -------------------------------------------- // // UTIL @@ -84,5 +90,5 @@ public class ARMFlag extends ARAbstractSelect { return getComparable(mflag.getName()); } - + } diff --git a/src/com/massivecraft/factions/cmd/arg/ARMPerm.java b/src/com/massivecraft/factions/cmd/arg/ARMPerm.java index aa394ac7..0c13f508 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARMPerm.java +++ b/src/com/massivecraft/factions/cmd/arg/ARMPerm.java @@ -24,7 +24,7 @@ public class ARMPerm extends ARAbstractSelect // -------------------------------------------- // @Override - public String typename() + public String getTypeName() { return "faction permission"; } @@ -70,6 +70,12 @@ public class ARMPerm extends ARAbstractSelect return ret; } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + return this.altNames(sender); + } // -------------------------------------------- // // UTIL @@ -84,5 +90,5 @@ public class ARMPerm extends ARAbstractSelect { return getComparable(mperm.getName()); } - + } diff --git a/src/com/massivecraft/factions/cmd/arg/ARMPlayer.java b/src/com/massivecraft/factions/cmd/arg/ARMPlayer.java index 62c7156a..7ba7d85e 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARMPlayer.java +++ b/src/com/massivecraft/factions/cmd/arg/ARMPlayer.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd.arg; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.cmd.arg.ArgReader; +import com.massivecraft.massivecore.cmd.arg.AR; public class ARMPlayer { @@ -10,12 +10,12 @@ public class ARMPlayer // INSTANCE // -------------------------------------------- // - public static ArgReader getAny() + public static AR getAny() { return MPlayerColl.get().getAREntity(); } - public static ArgReader getOnline() + public static AR getOnline() { return MPlayerColl.get().getAREntity(true); } diff --git a/src/com/massivecraft/factions/cmd/arg/ARRank.java b/src/com/massivecraft/factions/cmd/arg/ARRank.java index 1e2788f0..80e0c6a2 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARRank.java +++ b/src/com/massivecraft/factions/cmd/arg/ARRank.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd.arg; import java.util.Collection; +import java.util.Collections; +import java.util.List; import org.bukkit.command.CommandSender; @@ -12,6 +14,19 @@ import com.massivecraft.massivecore.util.Txt; public class ARRank extends ARAbstractSelect { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final List ALT_NAMES = Collections.unmodifiableList(MUtil.list( + Txt.getNicedEnum(Rel.LEADER), + Txt.getNicedEnum(Rel.OFFICER), + Txt.getNicedEnum(Rel.MEMBER), + Txt.getNicedEnum(Rel.RECRUIT), + "Promote", + "Demote" + )); + // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // @@ -52,7 +67,7 @@ public class ARRank extends ARAbstractSelect // This is especially useful when one rank can have aliases. // In the case of promote/demote, // that would require 10 lines of code repeated for each alias. - arg = this.prepareArg(arg); + arg = getComparable(arg); // All the normal ranks if (arg.equals("leader")) return Rel.LEADER; @@ -91,27 +106,34 @@ public class ARRank extends ARAbstractSelect @Override public Collection altNames(CommandSender sender) { - return MUtil.list( - Txt.getNicedEnum(Rel.LEADER), - Txt.getNicedEnum(Rel.OFFICER), - Txt.getNicedEnum(Rel.MEMBER), - Txt.getNicedEnum(Rel.RECRUIT), - "Promote", - "Demote" - ); + return ALT_NAMES; + } + + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + return this.altNames(sender); } @Override - public String typename() + public boolean isValid(String arg, CommandSender sender) { - return "rank"; + try + { + return this.select(arg, sender) != null; + } + catch (MassiveException e) + { + return true; + } } // -------------------------------------------- // // ARG // -------------------------------------------- // - public String prepareArg(String str) + public static String getComparable(String str) { String ret = str.toLowerCase(); diff --git a/src/com/massivecraft/factions/cmd/arg/ARRel.java b/src/com/massivecraft/factions/cmd/arg/ARRel.java index 7d8f92be..36a912b9 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARRel.java +++ b/src/com/massivecraft/factions/cmd/arg/ARRel.java @@ -24,7 +24,7 @@ public class ARRel extends ARAbstractSelect // -------------------------------------------- // @Override - public String typename() + public String getTypeName() { return "role"; } @@ -47,5 +47,11 @@ public class ARRel extends ARAbstractSelect return ret; } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + return this.altNames(sender); + } } diff --git a/src/com/massivecraft/factions/cmd/arg/ARSortMPlayer.java b/src/com/massivecraft/factions/cmd/arg/ARSortMPlayer.java index 07e1c370..5bbb6dd2 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARSortMPlayer.java +++ b/src/com/massivecraft/factions/cmd/arg/ARSortMPlayer.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd.arg; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; +import java.util.List; import org.bukkit.command.CommandSender; @@ -14,6 +16,12 @@ import com.massivecraft.massivecore.util.MUtil; public class ARSortMPlayer extends ARAbstractSelect> { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final List ALT_NAMES = Collections.unmodifiableList(MUtil.list("rank", "power", "time")); + // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // @@ -26,7 +34,7 @@ public class ARSortMPlayer extends ARAbstractSelect> // -------------------------------------------- // @Override - public String typename() + public String getTypeName() { return "player sorter"; } @@ -58,7 +66,13 @@ public class ARSortMPlayer extends ARAbstractSelect> @Override public Collection altNames(CommandSender sender) { - return MUtil.list("rank", "power", "time"); + return ALT_NAMES; + } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + return this.altNames(sender); } }