Decouple logic for list permission check and avoiding spam.

This commit is contained in:
Olof Larsson 2015-02-04 14:04:41 +01:00
parent 49444c6fbf
commit 8b12cadf0a

View File

@ -9,6 +9,12 @@ import com.massivecraft.massivecore.util.Txt;
public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
{
// -------------------------------------------- //
// CONSTANT
// -------------------------------------------- //
public static final int LIST_COUNT_MAX = 50;
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
@ -16,7 +22,7 @@ public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
public abstract String typename();
public abstract T select(String str, CommandSender sender);
public abstract Collection<String> altNames(CommandSender sender);
public boolean canList(CommandSender sender) { return this.altNames(sender).size() < 50; }
public boolean canList(CommandSender sender) { return true; }
// -------------------------------------------- //
// OVERRIDE
@ -31,6 +37,7 @@ public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
{
MassiveCommandException exception = new MassiveCommandException();
exception.addMsg("<b>No %s matches \"<h>%s<b>\".", this.typename(), arg);
if (this.canList(sender))
{
Collection<String> names = this.altNames(sender);
@ -38,6 +45,10 @@ public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
{
exception.addMsg("<i>Note: There is no %s available.", this.typename());
}
else if (names.size() > LIST_COUNT_MAX)
{
exception.addMsg("<i>More than %d alternatives available.", LIST_COUNT_MAX);
}
else
{
String format = Txt.parse("<h>%s");