From e2b3b668af5a4e34d2b84c98ad3b53e6562ce79d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sun, 8 Nov 2015 20:22:46 +0100 Subject: [PATCH] Further TypeAbstractChoice optimizations. Forgot the Material ids. --- .../command/type/TypeAbstractChoice.java | 40 +++++++++++++------ .../type/enumeration/TypeMaterial.java | 15 +++++++ .../massivecraft/massivecore/store/Coll.java | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java b/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java index e061ead4..7427f30c 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java +++ b/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java @@ -98,6 +98,18 @@ public abstract class TypeAbstractChoice extends TypeAbstract implements A // OVERRIDE: TYPE // -------------------------------------------- // + protected static final String MESSAGE_MATCH_NOTHING = Txt.parse("No %s matches \"%s\"."); + protected static final String MESSAGE_MATCH_AMBIGUOUS = Txt.parse("%d %ss matches \"%s\"."); + protected static final String MESSAGE_AVAILABLE_EMPTY = Txt.parse("Note: There is no %s available."); + + protected static final String MESSAGE_COLON_AMBIGUOUS = Txt.parse("Ambigous: "); + protected static final String MESSAGE_COLON_ALL = Txt.parse("All: "); + protected static final String MESSAGE_COLON_SIMILAR = Txt.parse("Similar: "); + + protected static final String MESSAGE_SUGGESTIONS_EMPTY = Txt.parse("No suggestions found."); + protected static final String MESSAGE_SUGGESTIONS_MUCH = Txt.parse("Over %d suggestions found (hiding output)."); + + @Override public T read(String arg, CommandSender sender) throws MassiveException { @@ -131,15 +143,18 @@ public abstract class TypeAbstractChoice extends TypeAbstract implements A boolean suggestLevenshtein = false; // Nothing Found + String message; if (matches.isEmpty()) { - exception.addMsg("No %s matches \"%s\".", this.getTypeName(), arg); + message = String.format(MESSAGE_MATCH_NOTHING, this.getTypeName(), arg); + exception.addMessage(message); suggestLevenshtein = true; } // Ambiguous else { - exception.addMsg("%d %ss matches \"%s\".", 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 extends TypeAbstract implements A } else if (suggestNone) { - exception.addMsg("Note: There is no %s available.", this.getTypeName()); + message = String.format(MESSAGE_AVAILABLE_EMPTY, this.getTypeName()); + exception.addMessage(message); } else { Collection 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 extends TypeAbstract implements A if (suggestAmbiguous) { suggestions = matches; - msg = "Ambigous: %s"; + message = MESSAGE_COLON_AMBIGUOUS; } else if (suggestAll) { suggestions = all; - msg = "All: %s"; + message = MESSAGE_COLON_ALL; } else if (suggestLevenshtein) { - suggestions = this.getMatches(options, arg, true);; - msg = "Similar: %s"; + suggestions = this.getMatches(options, arg, true); + message = MESSAGE_COLON_SIMILAR; } if (suggestions.isEmpty()) { - exception.addMsg("No suggestions found."); + exception.addMessage(MESSAGE_SUGGESTIONS_EMPTY); } else if (suggestions.size() > this.getListCountMax()) { - exception.addMsg("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 extends TypeAbstract 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; } diff --git a/src/com/massivecraft/massivecore/command/type/enumeration/TypeMaterial.java b/src/com/massivecraft/massivecore/command/type/enumeration/TypeMaterial.java index c73d5ae3..d5d1d4ba 100644 --- a/src/com/massivecraft/massivecore/command/type/enumeration/TypeMaterial.java +++ b/src/com/massivecraft/massivecore/command/type/enumeration/TypeMaterial.java @@ -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 @@ -19,5 +22,17 @@ public class TypeMaterial extends TypeEnum Txt.parse("https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java") ); } + + @SuppressWarnings("deprecation") + @Override + public Set getIdsInner(Material value) + { + Set ret = new MassiveSet(super.getIdsInner(value)); + + String id = String.valueOf(value.getId()); + ret.add(id); + + return ret; + } } diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index 9a723e8b..83031b12 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -383,7 +383,7 @@ public class Coll> extends CollAbstract protected Map 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");