From a35b48910af592727e4cbd3e76a44c7148de6392 Mon Sep 17 00:00:00 2001 From: bensku Date: Fri, 15 Jul 2016 14:34:03 +0300 Subject: [PATCH] Make that sort actually work... --- .../skript/expressions/ExprAlphabetList.java | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprAlphabetList.java b/src/main/java/ch/njol/skript/expressions/ExprAlphabetList.java index 3286c78ee33..1be2e948533 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprAlphabetList.java +++ b/src/main/java/ch/njol/skript/expressions/ExprAlphabetList.java @@ -41,53 +41,47 @@ import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; -/** - * Sorts a list of texts/stirngs alphabetically - * @author xXAndrew28Xx - */ @Name("Alphabetical Sort") -@Description("Sort a list alphabetically") +@Description("Sorts given strings in alphabetical order.") @Examples({"set {_list::*} to alphabetically sorted {_list::*"}) -@Since("dev-18") +@Since("2.2-dev18b") public class ExprAlphabetList extends SimpleExpression{ + static{ Skript.registerExpression(ExprAlphabetList.class, String.class, ExpressionType.COMBINED, "alphabetically sorted %strings%"); } - private Expression exprTexts; + + @SuppressWarnings("null") + private Expression texts; + + @SuppressWarnings({"null", "unchecked"}) @Override - public boolean isSingle() { - return false; + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + texts = (Expression) exprs[0]; + return true; } - + + @Override + @Nullable + protected String[] get(Event e) { + String[] sorted = texts.getAll(e).clone(); // Not yet sorted + Arrays.sort(sorted); // Now sorted + return sorted; + } + @Override public Class getReturnType() { return String.class; } - - @SuppressWarnings("unchecked") + @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - exprTexts = (Expression) exprs[0]; - return true; + public boolean isSingle() { + return false; } @Override public String toString(@Nullable Event e, boolean debug) { - return "alphabetically sorted %strings%"; - } - - @Override - @Nullable - protected String[] get(Event e) { - String[] texts = exprTexts.getArray(e); - ArrayList alTexts = new ArrayList(Arrays.asList(texts)); - Collections.sort(alTexts, new Comparator(){ - - @Override - public int compare(String o1, String o2) { - return o1.compareTo(o2); - }}); - return alTexts.toArray(new String[alTexts.size()]); + return "alphabetically sorted strings"; } } \ No newline at end of file