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
|
// 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
|
@Override
|
||||||
public T read(String arg, CommandSender sender) throws MassiveException
|
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;
|
boolean suggestLevenshtein = false;
|
||||||
|
|
||||||
// Nothing Found
|
// Nothing Found
|
||||||
|
String message;
|
||||||
if (matches.isEmpty())
|
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;
|
suggestLevenshtein = true;
|
||||||
}
|
}
|
||||||
// Ambiguous
|
// Ambiguous
|
||||||
else
|
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;
|
suggestAmbiguous = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,12 +168,12 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
|||||||
}
|
}
|
||||||
else if (suggestNone)
|
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
|
else
|
||||||
{
|
{
|
||||||
Collection<T> suggestions = null;
|
Collection<T> suggestions = null;
|
||||||
String msg = null;
|
|
||||||
String format = SUGGEST_FORMAT;
|
String format = SUGGEST_FORMAT;
|
||||||
String comma = SUGGEST_COMMMA;
|
String comma = SUGGEST_COMMMA;
|
||||||
String and = SUGGEST_AND;
|
String and = SUGGEST_AND;
|
||||||
@ -167,26 +182,27 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
|||||||
if (suggestAmbiguous)
|
if (suggestAmbiguous)
|
||||||
{
|
{
|
||||||
suggestions = matches;
|
suggestions = matches;
|
||||||
msg = "<aqua>Ambigous<silver>: %s";
|
message = MESSAGE_COLON_AMBIGUOUS;
|
||||||
}
|
}
|
||||||
else if (suggestAll)
|
else if (suggestAll)
|
||||||
{
|
{
|
||||||
suggestions = all;
|
suggestions = all;
|
||||||
msg = "<aqua>All<silver>: %s";
|
message = MESSAGE_COLON_ALL;
|
||||||
}
|
}
|
||||||
else if (suggestLevenshtein)
|
else if (suggestLevenshtein)
|
||||||
{
|
{
|
||||||
suggestions = this.getMatches(options, arg, true);;
|
suggestions = this.getMatches(options, arg, true);
|
||||||
msg = "<aqua>Similar<silver>: %s";
|
message = MESSAGE_COLON_SIMILAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suggestions.isEmpty())
|
if (suggestions.isEmpty())
|
||||||
{
|
{
|
||||||
exception.addMsg("<i>No suggestions found.");
|
exception.addMessage(MESSAGE_SUGGESTIONS_EMPTY);
|
||||||
}
|
}
|
||||||
else if (suggestions.size() > this.getListCountMax())
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -195,13 +211,13 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
|||||||
{
|
{
|
||||||
visuals.add(this.getVisual(value, sender));
|
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
|
// Help
|
||||||
String help = this.getHelp();
|
String help = this.getHelp();
|
||||||
if (help != null) exception.addMsg(help);
|
if (help != null) exception.addMessage(help);
|
||||||
|
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.massivecraft.massivecore.command.type.enumeration;
|
package com.massivecraft.massivecore.command.type.enumeration;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public class TypeMaterial extends TypeEnum<Material>
|
public class TypeMaterial extends TypeEnum<Material>
|
||||||
@ -19,5 +22,17 @@ public class TypeMaterial extends TypeEnum<Material>
|
|||||||
Txt.parse("<aqua>https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java")
|
Txt.parse("<aqua>https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 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 (id == null) throw new NullPointerException("id");
|
||||||
if (modification == null) throw new NullPointerException("modification");
|
if (modification == null) throw new NullPointerException("modification");
|
||||||
|
Loading…
Reference in New Issue
Block a user