Further TypeAbstractChoice optimizations. Forgot the Material ids.
This commit is contained in:
parent
92ec2c91f3
commit
e2b3b668af
@ -98,6 +98,18 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
||||
// OVERRIDE: TYPE
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected static final String MESSAGE_MATCH_NOTHING = Txt.parse("<b>No %s matches \"<h>%s<b>\".");
|
||||
protected static final String MESSAGE_MATCH_AMBIGUOUS = Txt.parse("<b>%d %ss matches \"<h>%s<b>\".");
|
||||
protected static final String MESSAGE_AVAILABLE_EMPTY = Txt.parse("<i>Note: There is no %s available.");
|
||||
|
||||
protected static final String MESSAGE_COLON_AMBIGUOUS = Txt.parse("<aqua>Ambigous<silver>: ");
|
||||
protected static final String MESSAGE_COLON_ALL = Txt.parse("<aqua>All<silver>: ");
|
||||
protected static final String MESSAGE_COLON_SIMILAR = Txt.parse("<aqua>Similar<silver>: ");
|
||||
|
||||
protected static final String MESSAGE_SUGGESTIONS_EMPTY = Txt.parse("<i>No suggestions found.");
|
||||
protected static final String MESSAGE_SUGGESTIONS_MUCH = Txt.parse("<i>Over %d suggestions found (hiding output).");
|
||||
|
||||
|
||||
@Override
|
||||
public T read(String arg, CommandSender sender) throws MassiveException
|
||||
{
|
||||
@ -131,15 +143,18 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
||||
boolean suggestLevenshtein = false;
|
||||
|
||||
// Nothing Found
|
||||
String message;
|
||||
if (matches.isEmpty())
|
||||
{
|
||||
exception.addMsg("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
|
||||
message = String.format(MESSAGE_MATCH_NOTHING, this.getTypeName(), arg);
|
||||
exception.addMessage(message);
|
||||
suggestLevenshtein = true;
|
||||
}
|
||||
// Ambiguous
|
||||
else
|
||||
{
|
||||
exception.addMsg("<b>%d %ss matches \"<h>%s<b>\".", matches.size(), this.getTypeName(), arg);
|
||||
message = String.format(MESSAGE_MATCH_AMBIGUOUS, matches.size(), this.getTypeName(), arg);
|
||||
exception.addMessage(message);
|
||||
suggestAmbiguous = true;
|
||||
}
|
||||
|
||||
@ -153,12 +168,12 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
||||
}
|
||||
else if (suggestNone)
|
||||
{
|
||||
exception.addMsg("<i>Note: There is no %s available.", this.getTypeName());
|
||||
message = String.format(MESSAGE_AVAILABLE_EMPTY, this.getTypeName());
|
||||
exception.addMessage(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<T> suggestions = null;
|
||||
String msg = null;
|
||||
String format = SUGGEST_FORMAT;
|
||||
String comma = SUGGEST_COMMMA;
|
||||
String and = SUGGEST_AND;
|
||||
@ -167,26 +182,27 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
||||
if (suggestAmbiguous)
|
||||
{
|
||||
suggestions = matches;
|
||||
msg = "<aqua>Ambigous<silver>: %s";
|
||||
message = MESSAGE_COLON_AMBIGUOUS;
|
||||
}
|
||||
else if (suggestAll)
|
||||
{
|
||||
suggestions = all;
|
||||
msg = "<aqua>All<silver>: %s";
|
||||
message = MESSAGE_COLON_ALL;
|
||||
}
|
||||
else if (suggestLevenshtein)
|
||||
{
|
||||
suggestions = this.getMatches(options, arg, true);;
|
||||
msg = "<aqua>Similar<silver>: %s";
|
||||
suggestions = this.getMatches(options, arg, true);
|
||||
message = MESSAGE_COLON_SIMILAR;
|
||||
}
|
||||
|
||||
if (suggestions.isEmpty())
|
||||
{
|
||||
exception.addMsg("<i>No suggestions found.");
|
||||
exception.addMessage(MESSAGE_SUGGESTIONS_EMPTY);
|
||||
}
|
||||
else if (suggestions.size() > this.getListCountMax())
|
||||
{
|
||||
exception.addMsg("<i>Over %d suggestions found (hiding output).", this.getListCountMax());
|
||||
message = String.format(MESSAGE_SUGGESTIONS_MUCH, this.getListCountMax());
|
||||
exception.addMessage(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -195,13 +211,13 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
||||
{
|
||||
visuals.add(this.getVisual(value, sender));
|
||||
}
|
||||
exception.addMsg(msg, Txt.implodeCommaAndDot(visuals, format, comma, and, dot));
|
||||
exception.addMessage(message + Txt.implodeCommaAndDot(visuals, format, comma, and, dot));
|
||||
}
|
||||
}
|
||||
|
||||
// Help
|
||||
String help = this.getHelp();
|
||||
if (help != null) exception.addMsg(help);
|
||||
if (help != null) exception.addMessage(help);
|
||||
|
||||
throw exception;
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.massivecraft.massivecore.command.type.enumeration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class TypeMaterial extends TypeEnum<Material>
|
||||
@ -20,4 +23,16 @@ public class TypeMaterial extends TypeEnum<Material>
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Set<String> getIdsInner(Material value)
|
||||
{
|
||||
Set<String> ret = new MassiveSet<String>(super.getIdsInner(value));
|
||||
|
||||
String id = String.valueOf(value.getId());
|
||||
ret.add(id);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
|
||||
|
||||
protected Map<String, Modification> identifiedModifications;
|
||||
|
||||
protected synchronized void putIdentifiedModificationFixed(String id, Modification modification)
|
||||
public synchronized void putIdentifiedModificationFixed(String id, Modification modification)
|
||||
{
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
if (modification == null) throw new NullPointerException("modification");
|
||||
|
Loading…
Reference in New Issue
Block a user