Decouple logic for list permission check and avoiding spam.
This commit is contained in:
parent
49444c6fbf
commit
8b12cadf0a
@ -9,6 +9,12 @@ import com.massivecraft.massivecore.util.Txt;
|
|||||||
|
|
||||||
public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
|
public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static final int LIST_COUNT_MAX = 50;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// ABSTRACT
|
// ABSTRACT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -16,7 +22,7 @@ public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
|
|||||||
public abstract String typename();
|
public abstract String typename();
|
||||||
public abstract T select(String str, CommandSender sender);
|
public abstract T select(String str, CommandSender sender);
|
||||||
public abstract Collection<String> altNames(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
|
// OVERRIDE
|
||||||
@ -31,6 +37,7 @@ public abstract class ARAbstractSelect<T> extends ArgReaderAbstract<T>
|
|||||||
{
|
{
|
||||||
MassiveCommandException exception = new MassiveCommandException();
|
MassiveCommandException exception = new MassiveCommandException();
|
||||||
exception.addMsg("<b>No %s matches \"<h>%s<b>\".", this.typename(), arg);
|
exception.addMsg("<b>No %s matches \"<h>%s<b>\".", this.typename(), arg);
|
||||||
|
|
||||||
if (this.canList(sender))
|
if (this.canList(sender))
|
||||||
{
|
{
|
||||||
Collection<String> names = this.altNames(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());
|
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
|
else
|
||||||
{
|
{
|
||||||
String format = Txt.parse("<h>%s");
|
String format = Txt.parse("<h>%s");
|
||||||
|
Loading…
Reference in New Issue
Block a user