Update ArgReaders
This commit is contained in:
parent
6c61da2b8d
commit
43d2354f04
@ -1,16 +1,20 @@
|
|||||||
package com.massivecraft.factions.cmd.arg;
|
package com.massivecraft.factions.cmd.arg;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
|
||||||
import com.massivecraft.factions.entity.Faction;
|
import com.massivecraft.factions.entity.Faction;
|
||||||
import com.massivecraft.factions.entity.FactionColl;
|
import com.massivecraft.factions.entity.FactionColl;
|
||||||
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
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;
|
import com.massivecraft.massivecore.util.IdUtil;
|
||||||
|
|
||||||
public class ARFaction extends ArgReaderAbstract<Faction>
|
public class ARFaction extends ARAbstract<Faction>
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
@ -56,4 +60,17 @@ public class ARFaction extends ArgReaderAbstract<Faction>
|
|||||||
throw new MassiveException().addMsg("<b>No faction or player matching \"<p>%s<b>\".", str);
|
throw new MassiveException().addMsg("<b>No faction or player matching \"<p>%s<b>\".", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||||
|
{
|
||||||
|
List<String> ret = new MassiveList<String>();
|
||||||
|
|
||||||
|
for (Faction faction : FactionColl.get().getAll())
|
||||||
|
{
|
||||||
|
ret.add(faction.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class ARMFlag extends ARAbstractSelect<MFlag>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String typename()
|
public String getTypeName()
|
||||||
{
|
{
|
||||||
return "faction flag";
|
return "faction flag";
|
||||||
}
|
}
|
||||||
@ -71,6 +71,12 @@ public class ARMFlag extends ARAbstractSelect<MFlag>
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||||
|
{
|
||||||
|
return this.altNames(sender);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// UTIL
|
// UTIL
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -24,7 +24,7 @@ public class ARMPerm extends ARAbstractSelect<MPerm>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String typename()
|
public String getTypeName()
|
||||||
{
|
{
|
||||||
return "faction permission";
|
return "faction permission";
|
||||||
}
|
}
|
||||||
@ -71,6 +71,12 @@ public class ARMPerm extends ARAbstractSelect<MPerm>
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||||
|
{
|
||||||
|
return this.altNames(sender);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// UTIL
|
// UTIL
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd.arg;
|
|||||||
|
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.massivecraft.factions.entity.MPlayerColl;
|
import com.massivecraft.factions.entity.MPlayerColl;
|
||||||
import com.massivecraft.massivecore.cmd.arg.ArgReader;
|
import com.massivecraft.massivecore.cmd.arg.AR;
|
||||||
|
|
||||||
public class ARMPlayer
|
public class ARMPlayer
|
||||||
{
|
{
|
||||||
@ -10,12 +10,12 @@ public class ARMPlayer
|
|||||||
// INSTANCE
|
// INSTANCE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static ArgReader<MPlayer> getAny()
|
public static AR<MPlayer> getAny()
|
||||||
{
|
{
|
||||||
return MPlayerColl.get().getAREntity();
|
return MPlayerColl.get().getAREntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArgReader<MPlayer> getOnline()
|
public static AR<MPlayer> getOnline()
|
||||||
{
|
{
|
||||||
return MPlayerColl.get().getAREntity(true);
|
return MPlayerColl.get().getAREntity(true);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.massivecraft.factions.cmd.arg;
|
package com.massivecraft.factions.cmd.arg;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -12,6 +14,19 @@ import com.massivecraft.massivecore.util.Txt;
|
|||||||
|
|
||||||
public class ARRank extends ARAbstractSelect<Rel>
|
public class ARRank extends ARAbstractSelect<Rel>
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static final List<String> 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
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -52,7 +67,7 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
// This is especially useful when one rank can have aliases.
|
// This is especially useful when one rank can have aliases.
|
||||||
// In the case of promote/demote,
|
// In the case of promote/demote,
|
||||||
// that would require 10 lines of code repeated for each alias.
|
// that would require 10 lines of code repeated for each alias.
|
||||||
arg = this.prepareArg(arg);
|
arg = getComparable(arg);
|
||||||
|
|
||||||
// All the normal ranks
|
// All the normal ranks
|
||||||
if (arg.equals("leader")) return Rel.LEADER;
|
if (arg.equals("leader")) return Rel.LEADER;
|
||||||
@ -91,27 +106,34 @@ public class ARRank extends ARAbstractSelect<Rel>
|
|||||||
@Override
|
@Override
|
||||||
public Collection<String> altNames(CommandSender sender)
|
public Collection<String> altNames(CommandSender sender)
|
||||||
{
|
{
|
||||||
return MUtil.list(
|
return ALT_NAMES;
|
||||||
Txt.getNicedEnum(Rel.LEADER),
|
}
|
||||||
Txt.getNicedEnum(Rel.OFFICER),
|
|
||||||
Txt.getNicedEnum(Rel.MEMBER),
|
|
||||||
Txt.getNicedEnum(Rel.RECRUIT),
|
@Override
|
||||||
"Promote",
|
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||||
"Demote"
|
{
|
||||||
);
|
return this.altNames(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
// ARG
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public String prepareArg(String str)
|
public static String getComparable(String str)
|
||||||
{
|
{
|
||||||
String ret = str.toLowerCase();
|
String ret = str.toLowerCase();
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class ARRel extends ARAbstractSelect<Rel>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String typename()
|
public String getTypeName()
|
||||||
{
|
{
|
||||||
return "role";
|
return "role";
|
||||||
}
|
}
|
||||||
@ -48,4 +48,10 @@ public class ARRel extends ARAbstractSelect<Rel>
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||||
|
{
|
||||||
|
return this.altNames(sender);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.massivecraft.factions.cmd.arg;
|
package com.massivecraft.factions.cmd.arg;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -14,6 +16,12 @@ import com.massivecraft.massivecore.util.MUtil;
|
|||||||
|
|
||||||
public class ARSortMPlayer extends ARAbstractSelect<Comparator<MPlayer>>
|
public class ARSortMPlayer extends ARAbstractSelect<Comparator<MPlayer>>
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static final List<String> ALT_NAMES = Collections.unmodifiableList(MUtil.list("rank", "power", "time"));
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -26,7 +34,7 @@ public class ARSortMPlayer extends ARAbstractSelect<Comparator<MPlayer>>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String typename()
|
public String getTypeName()
|
||||||
{
|
{
|
||||||
return "player sorter";
|
return "player sorter";
|
||||||
}
|
}
|
||||||
@ -58,7 +66,13 @@ public class ARSortMPlayer extends ARAbstractSelect<Comparator<MPlayer>>
|
|||||||
@Override
|
@Override
|
||||||
public Collection<String> altNames(CommandSender sender)
|
public Collection<String> altNames(CommandSender sender)
|
||||||
{
|
{
|
||||||
return MUtil.list("rank", "power", "time");
|
return ALT_NAMES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||||
|
{
|
||||||
|
return this.altNames(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user