From 958155e43c49e2b38337cd885176237786d6d764 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 16 Apr 2013 08:35:20 +0200 Subject: [PATCH] This would be all ArgReaders? --- .../factions/cmd/arg/ARFFlag.java | 51 ++++++++++++++++++ .../factions/cmd/arg/ARFPlayer.java | 26 ++++++++++ .../factions/cmd/arg/ARFaction.java | 52 +++++++++++++++++++ .../massivecraft/factions/cmd/arg/ARRel.java | 51 ++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 src/com/massivecraft/factions/cmd/arg/ARFFlag.java create mode 100644 src/com/massivecraft/factions/cmd/arg/ARFPlayer.java create mode 100644 src/com/massivecraft/factions/cmd/arg/ARFaction.java create mode 100644 src/com/massivecraft/factions/cmd/arg/ARRel.java diff --git a/src/com/massivecraft/factions/cmd/arg/ARFFlag.java b/src/com/massivecraft/factions/cmd/arg/ARFFlag.java new file mode 100644 index 00000000..1994c3e0 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/arg/ARFFlag.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd.arg; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.FFlag; +import com.massivecraft.mcore.cmd.arg.ARAbstractSelect; +import com.massivecraft.mcore.util.Txt; + +public class ARFFlag extends ARAbstractSelect +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARFFlag i = new ARFFlag(); + public static ARFFlag get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String typename() + { + return "faction flag"; + } + + @Override + public FFlag select(String str, CommandSender sender) + { + return FFlag.parse(str); + } + + @Override + public Collection altNames(CommandSender sender) + { + List ret = new ArrayList(); + + for (FFlag fflag : FFlag.values()) + { + ret.add(Txt.getNicedEnum(fflag)); + } + + return ret; + } + +} diff --git a/src/com/massivecraft/factions/cmd/arg/ARFPlayer.java b/src/com/massivecraft/factions/cmd/arg/ARFPlayer.java new file mode 100644 index 00000000..91facc72 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/arg/ARFPlayer.java @@ -0,0 +1,26 @@ +package com.massivecraft.factions.cmd.arg; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayerColl; +import com.massivecraft.mcore.cmd.arg.ARSenderEntity; +import com.massivecraft.mcore.cmd.arg.ArgReader; + +public class ARFPlayer +{ + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static ArgReader fullAny = ARSenderEntity.getFullAny(FPlayerColl.get()); + public static ArgReader getFullAny() { return fullAny; } + + private static ArgReader startAny = ARSenderEntity.getStartAny(FPlayerColl.get()); + public static ArgReader getStartAny() { return startAny; } + + private static ArgReader fullOnline = ARSenderEntity.getFullOnline(FPlayerColl.get()); + public static ArgReader getFullOnline() { return fullOnline; } + + private static ArgReader startOnline = ARSenderEntity.getStartOnline(FPlayerColl.get()); + public static ArgReader getStartOnline() { return startOnline; } + +} diff --git a/src/com/massivecraft/factions/cmd/arg/ARFaction.java b/src/com/massivecraft/factions/cmd/arg/ARFaction.java new file mode 100644 index 00000000..3620ac66 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/arg/ARFaction.java @@ -0,0 +1,52 @@ +package com.massivecraft.factions.cmd.arg; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayerColl; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionColl; +import com.massivecraft.mcore.cmd.arg.ArgReaderAbstract; +import com.massivecraft.mcore.cmd.arg.ArgResult; +import com.massivecraft.mcore.util.Txt; + +public class ARFaction extends ArgReaderAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARFaction i = new ARFaction(); + public static ARFaction get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ArgResult read(String str, CommandSender sender) + { + ArgResult result = new ArgResult(); + + // Faction Tag Exact + result.setResult(FactionColl.get().getByTag(str)); + if (result.hasResult()) return result; + + // Faction Tag Match + result.setResult(FactionColl.get().getBestTagMatch(str)); + if (result.hasResult()) return result; + + // FPlayer Name Exact + FPlayer fplayer = FPlayerColl.get().get(str); + if (fplayer != null) + { + result.setResult(fplayer.getFaction()); + return result; + } + + result.setErrors(Txt.parse("No faction or player matching \"

%s\".", str)); + return result; + + } + +} diff --git a/src/com/massivecraft/factions/cmd/arg/ARRel.java b/src/com/massivecraft/factions/cmd/arg/ARRel.java new file mode 100644 index 00000000..3f1d808c --- /dev/null +++ b/src/com/massivecraft/factions/cmd/arg/ARRel.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd.arg; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.Rel; +import com.massivecraft.mcore.cmd.arg.ARAbstractSelect; +import com.massivecraft.mcore.util.Txt; + +public class ARRel extends ARAbstractSelect +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARRel i = new ARRel(); + public static ARRel get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String typename() + { + return "role"; + } + + @Override + public Rel select(String str, CommandSender sender) + { + return Rel.parse(str); + } + + @Override + public Collection altNames(CommandSender sender) + { + List ret = new ArrayList(); + + for (Rel rel : Rel.values()) + { + ret.add(Txt.getNicedEnum(rel)); + } + + return ret; + } + +}