From 893d38960a6cac8c32b538243b6e3bc0e1897cd4 Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 27 Mar 2022 14:59:10 +0200 Subject: [PATCH 01/10] :sparkles: Added 'ask' section & 'last answer' expression --- .../skriptparser/expressions/ExprAnswer.java | 50 ++++++++++++++++ .../syst3ms/skriptparser/sections/SecAsk.java | 58 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java create mode 100644 src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java new file mode 100644 index 00000000..3f656790 --- /dev/null +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java @@ -0,0 +1,50 @@ +package io.github.syst3ms.skriptparser.expressions; + +import io.github.syst3ms.skriptparser.Parser; +import io.github.syst3ms.skriptparser.lang.Expression; +import io.github.syst3ms.skriptparser.lang.TriggerContext; +import io.github.syst3ms.skriptparser.lang.lambda.SectionValue; +import io.github.syst3ms.skriptparser.parsing.ParseContext; +import io.github.syst3ms.skriptparser.sections.SecAsk; + +/** + * Get back the last entered answer in a {@link SecAsk} section. + * This will return the last line of the console. + * + * @name Last Answer + * @type EXPRESSION + * @pattern [the] [last] (answer|response) + * @since ALPHA + * @author Mwexim + */ +public class ExprAnswer extends SectionValue { + + static { + Parser.getMainRegistration().addExpression( + ExprAnswer.class, + String.class, + true, + "[the] [last] (answer|response)" + ); + } + + @Override + public String toString(TriggerContext ctx, boolean debug) { + return "the answer"; + } + + @Override + public boolean preInitialize(Expression[] expressions, int matchedPattern, ParseContext parseContext) { + return true; + } + + @Override + public String[] getSectionValues(SecAsk section, TriggerContext ctx) { + return new String[]{section.getArguments()[0].toString()}; + } + + @Override + public Class getSectionClass() { + return SecAsk.class; + } +} diff --git a/src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java b/src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java new file mode 100644 index 00000000..2a4df585 --- /dev/null +++ b/src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java @@ -0,0 +1,58 @@ +package io.github.syst3ms.skriptparser.sections; + +import io.github.syst3ms.skriptparser.Parser; +import io.github.syst3ms.skriptparser.lang.Expression; +import io.github.syst3ms.skriptparser.lang.Statement; +import io.github.syst3ms.skriptparser.lang.TriggerContext; +import io.github.syst3ms.skriptparser.lang.base.TaggedExpression; +import io.github.syst3ms.skriptparser.lang.lambda.ArgumentSection; +import io.github.syst3ms.skriptparser.parsing.ParseContext; + +import java.util.Optional; +import java.util.Scanner; + +/** + * Ask in the system console a specific message and wait for the answer of the user. + * The code in the section will be executed once the user answer or enter any value. + * The code after the section will run even if the user haven't answered yet. + * + * @name Ask + * @type SECTION + * @pattern ask for %string% + * @since ALPHA + * @author Mwexim + */ +@SuppressWarnings("unchecked") +public class SecAsk extends ArgumentSection { + + static { + Parser.getMainRegistration().addSection( + SecAsk.class, + "ask for %string%" + ); + } + + private Expression message; + + @Override + public Optional walk(TriggerContext ctx) { + if (getNext().isPresent()) + getNext().get().run(ctx); + Scanner scanner = new Scanner(System.in); + System.out.println(TaggedExpression.apply(message, ctx, "console")[0]); + setArguments(scanner.nextLine()); + setNext(null); + return getFirst(); + } + + @Override + public boolean init(Expression[] expressions, int matchedPattern, ParseContext parseContext) { + message = (Expression) expressions[0]; + return true; + } + + @Override + public String toString(TriggerContext ctx, boolean debug) { + return "ask for " + message.toString(ctx, debug); + } +} From ace7e37387006fbb1bbdcdc43f925ef49f01e251 Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 27 Mar 2022 16:00:56 +0200 Subject: [PATCH 02/10] :zap: Moved toString method to the end of the class --- .../syst3ms/skriptparser/expressions/ExprAnswer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java index 3f656790..3574d3af 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java @@ -28,11 +28,6 @@ public class ExprAnswer extends SectionValue { ); } - @Override - public String toString(TriggerContext ctx, boolean debug) { - return "the answer"; - } - @Override public boolean preInitialize(Expression[] expressions, int matchedPattern, ParseContext parseContext) { return true; @@ -47,4 +42,9 @@ public String[] getSectionValues(SecAsk section, TriggerContext ctx) { public Class getSectionClass() { return SecAsk.class; } + + @Override + public String toString(TriggerContext ctx, boolean debug) { + return "the answer"; + } } From 735d12ab1180e960e382b6477a9cc9c7b604931b Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 27 Mar 2022 21:06:27 +0200 Subject: [PATCH 03/10] :zap: Changed ask section into effect --- .../SecAsk.java => effects/EffAsk.java} | 37 +++++++++---------- .../skriptparser/expressions/ExprAnswer.java | 32 ++++++++++------ 2 files changed, 38 insertions(+), 31 deletions(-) rename src/main/java/io/github/syst3ms/skriptparser/{sections/SecAsk.java => effects/EffAsk.java} (63%) diff --git a/src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java b/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java similarity index 63% rename from src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java rename to src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java index 2a4df585..1e3ec59e 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/sections/SecAsk.java +++ b/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java @@ -1,33 +1,32 @@ -package io.github.syst3ms.skriptparser.sections; +package io.github.syst3ms.skriptparser.effects; import io.github.syst3ms.skriptparser.Parser; +import io.github.syst3ms.skriptparser.expressions.ExprAnswer; +import io.github.syst3ms.skriptparser.lang.Effect; import io.github.syst3ms.skriptparser.lang.Expression; -import io.github.syst3ms.skriptparser.lang.Statement; import io.github.syst3ms.skriptparser.lang.TriggerContext; import io.github.syst3ms.skriptparser.lang.base.TaggedExpression; -import io.github.syst3ms.skriptparser.lang.lambda.ArgumentSection; import io.github.syst3ms.skriptparser.parsing.ParseContext; -import java.util.Optional; import java.util.Scanner; /** * Ask in the system console a specific message and wait for the answer of the user. * The code in the section will be executed once the user answer or enter any value. * The code after the section will run even if the user haven't answered yet. + * If you use the wait pattern, the next code outside the section will only be executed once the user answered. * * @name Ask - * @type SECTION + * @type EFFECT * @pattern ask for %string% * @since ALPHA * @author Mwexim */ -@SuppressWarnings("unchecked") -public class SecAsk extends ArgumentSection { +public class EffAsk extends Effect { static { - Parser.getMainRegistration().addSection( - SecAsk.class, + Parser.getMainRegistration().addEffect( + EffAsk.class, "ask for %string%" ); } @@ -35,22 +34,20 @@ public class SecAsk extends ArgumentSection { private Expression message; @Override - public Optional walk(TriggerContext ctx) { - if (getNext().isPresent()) - getNext().get().run(ctx); - Scanner scanner = new Scanner(System.in); - System.out.println(TaggedExpression.apply(message, ctx, "console")[0]); - setArguments(scanner.nextLine()); - setNext(null); - return getFirst(); - } - - @Override + @SuppressWarnings("unchecked") public boolean init(Expression[] expressions, int matchedPattern, ParseContext parseContext) { message = (Expression) expressions[0]; return true; } + @Override + protected void execute(TriggerContext ctx) { + Scanner scanner = new Scanner(System.in); + for (String line : TaggedExpression.apply(message, ctx, "console")) + System.out.println(line); + ExprAnswer.addAnswer(ctx, scanner.nextLine()); + } + @Override public String toString(TriggerContext ctx, boolean debug) { return "ask for " + message.toString(ctx, debug); diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java index 3574d3af..b27a3d7c 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java @@ -1,14 +1,16 @@ package io.github.syst3ms.skriptparser.expressions; import io.github.syst3ms.skriptparser.Parser; +import io.github.syst3ms.skriptparser.effects.EffAsk; import io.github.syst3ms.skriptparser.lang.Expression; import io.github.syst3ms.skriptparser.lang.TriggerContext; -import io.github.syst3ms.skriptparser.lang.lambda.SectionValue; import io.github.syst3ms.skriptparser.parsing.ParseContext; -import io.github.syst3ms.skriptparser.sections.SecAsk; + +import java.util.HashMap; +import java.util.Map; /** - * Get back the last entered answer in a {@link SecAsk} section. + * Get back the last entered answer in a {@link EffAsk} effect. * This will return the last line of the console. * * @name Last Answer @@ -17,7 +19,7 @@ * @since ALPHA * @author Mwexim */ -public class ExprAnswer extends SectionValue { +public class ExprAnswer implements Expression { static { Parser.getMainRegistration().addExpression( @@ -26,21 +28,29 @@ public class ExprAnswer extends SectionValue { true, "[the] [last] (answer|response)" ); + ANSWERS = new HashMap<>(); } - @Override - public boolean preInitialize(Expression[] expressions, int matchedPattern, ParseContext parseContext) { - return true; + private static final Map ANSWERS; + + public static void addAnswer(TriggerContext ctx, String answer) { + ANSWERS.put(ctx, answer); } @Override - public String[] getSectionValues(SecAsk section, TriggerContext ctx) { - return new String[]{section.getArguments()[0].toString()}; + public boolean init(Expression[] expressions, int matchedPattern, ParseContext context) { + return true; } @Override - public Class getSectionClass() { - return SecAsk.class; + public String[] getValues(TriggerContext ctx) { + if (ANSWERS.containsKey(ctx)) { + var answer = ANSWERS.get(ctx); + ANSWERS.remove(ctx); + return new String[] {answer}; + } else { + return new String[0]; + } } @Override From ef9bab219458126b2536e9efa930421345464847 Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 27 Mar 2022 21:08:30 +0200 Subject: [PATCH 04/10] :zap: Some requested changes --- .../java/io/github/syst3ms/skriptparser/effects/EffAsk.java | 3 +-- .../github/syst3ms/skriptparser/expressions/ExprAnswer.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java b/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java index 1e3ec59e..9dc20dd2 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java +++ b/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java @@ -14,13 +14,12 @@ * Ask in the system console a specific message and wait for the answer of the user. * The code in the section will be executed once the user answer or enter any value. * The code after the section will run even if the user haven't answered yet. - * If you use the wait pattern, the next code outside the section will only be executed once the user answered. * * @name Ask * @type EFFECT * @pattern ask for %string% * @since ALPHA - * @author Mwexim + * @author ItsTheSky */ public class EffAsk extends Effect { diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java index b27a3d7c..6c36fc66 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java @@ -17,7 +17,7 @@ * @type EXPRESSION * @pattern [the] [last] (answer|response) * @since ALPHA - * @author Mwexim + * @author ItsTheSky */ public class ExprAnswer implements Expression { @@ -55,6 +55,6 @@ public String[] getValues(TriggerContext ctx) { @Override public String toString(TriggerContext ctx, boolean debug) { - return "the answer"; + return "the last answer"; } } From 03bd6d6efd9a964cd74c1b71e23e97692b2fa91d Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 28 Jun 2022 18:54:22 +0200 Subject: [PATCH 05/10] :zap: Optimized & reworked the ask effect/expression --- .../skriptparser/expressions/ExprAnswer.java | 60 ------------------- .../EffAsk.java => expressions/ExprAsk.java} | 31 +++++----- 2 files changed, 15 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java rename src/main/java/io/github/syst3ms/skriptparser/{effects/EffAsk.java => expressions/ExprAsk.java} (56%) diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java deleted file mode 100644 index 6c36fc66..00000000 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAnswer.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.github.syst3ms.skriptparser.expressions; - -import io.github.syst3ms.skriptparser.Parser; -import io.github.syst3ms.skriptparser.effects.EffAsk; -import io.github.syst3ms.skriptparser.lang.Expression; -import io.github.syst3ms.skriptparser.lang.TriggerContext; -import io.github.syst3ms.skriptparser.parsing.ParseContext; - -import java.util.HashMap; -import java.util.Map; - -/** - * Get back the last entered answer in a {@link EffAsk} effect. - * This will return the last line of the console. - * - * @name Last Answer - * @type EXPRESSION - * @pattern [the] [last] (answer|response) - * @since ALPHA - * @author ItsTheSky - */ -public class ExprAnswer implements Expression { - - static { - Parser.getMainRegistration().addExpression( - ExprAnswer.class, - String.class, - true, - "[the] [last] (answer|response)" - ); - ANSWERS = new HashMap<>(); - } - - private static final Map ANSWERS; - - public static void addAnswer(TriggerContext ctx, String answer) { - ANSWERS.put(ctx, answer); - } - - @Override - public boolean init(Expression[] expressions, int matchedPattern, ParseContext context) { - return true; - } - - @Override - public String[] getValues(TriggerContext ctx) { - if (ANSWERS.containsKey(ctx)) { - var answer = ANSWERS.get(ctx); - ANSWERS.remove(ctx); - return new String[] {answer}; - } else { - return new String[0]; - } - } - - @Override - public String toString(TriggerContext ctx, boolean debug) { - return "the last answer"; - } -} diff --git a/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAsk.java similarity index 56% rename from src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java rename to src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAsk.java index 9dc20dd2..a0b80471 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/effects/EffAsk.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAsk.java @@ -1,8 +1,6 @@ -package io.github.syst3ms.skriptparser.effects; +package io.github.syst3ms.skriptparser.expressions; import io.github.syst3ms.skriptparser.Parser; -import io.github.syst3ms.skriptparser.expressions.ExprAnswer; -import io.github.syst3ms.skriptparser.lang.Effect; import io.github.syst3ms.skriptparser.lang.Expression; import io.github.syst3ms.skriptparser.lang.TriggerContext; import io.github.syst3ms.skriptparser.lang.base.TaggedExpression; @@ -11,40 +9,41 @@ import java.util.Scanner; /** - * Ask in the system console a specific message and wait for the answer of the user. - * The code in the section will be executed once the user answer or enter any value. - * The code after the section will run even if the user haven't answered yet. + * Ask for a specific input in the system console and wait for the answer of the user. + * This will therefore return what the user entered into a string. * * @name Ask - * @type EFFECT - * @pattern ask for %string% + * @type EXPRESSION + * @pattern ask [for] %string% * @since ALPHA * @author ItsTheSky */ -public class EffAsk extends Effect { +public class ExprAsk implements Expression { static { - Parser.getMainRegistration().addEffect( - EffAsk.class, - "ask for %string%" + Parser.getMainRegistration().addExpression( + ExprAsk.class, + String.class, + true, + "ask [for] %string%" ); } private Expression message; - @Override @SuppressWarnings("unchecked") - public boolean init(Expression[] expressions, int matchedPattern, ParseContext parseContext) { + @Override + public boolean init(Expression[] expressions, int matchedPattern, ParseContext context) { message = (Expression) expressions[0]; return true; } @Override - protected void execute(TriggerContext ctx) { + public String[] getValues(TriggerContext ctx) { Scanner scanner = new Scanner(System.in); for (String line : TaggedExpression.apply(message, ctx, "console")) System.out.println(line); - ExprAnswer.addAnswer(ctx, scanner.nextLine()); + return new String[]{scanner.nextLine()}; } @Override From 113302fdf0769a0fe2339263330a560fbea3ff54 Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 28 Jun 2022 18:55:20 +0200 Subject: [PATCH 06/10] :rocket: Implemented better console color system --- .../github/syst3ms/skriptparser/Parser.java | 4 +- .../syst3ms/skriptparser/tags/TagColor.java | 42 +++++++ .../syst3ms/skriptparser/tags/TagReset.java | 3 +- .../skriptparser/util/ConsoleColors.java | 87 -------------- .../util/color/ConsoleColors.java | 110 ++++++++++++++++++ 5 files changed, 156 insertions(+), 90 deletions(-) create mode 100644 src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java delete mode 100644 src/main/java/io/github/syst3ms/skriptparser/util/ConsoleColors.java create mode 100644 src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java diff --git a/src/main/java/io/github/syst3ms/skriptparser/Parser.java b/src/main/java/io/github/syst3ms/skriptparser/Parser.java index fb82bd2e..a3c2be28 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/Parser.java +++ b/src/main/java/io/github/syst3ms/skriptparser/Parser.java @@ -6,7 +6,7 @@ import io.github.syst3ms.skriptparser.registration.DefaultRegistration; import io.github.syst3ms.skriptparser.registration.SkriptAddon; import io.github.syst3ms.skriptparser.registration.SkriptRegistration; -import io.github.syst3ms.skriptparser.util.ConsoleColors; +import io.github.syst3ms.skriptparser.util.color.ConsoleColors; import io.github.syst3ms.skriptparser.util.FileUtils; import java.io.IOException; @@ -153,7 +153,7 @@ public static void printLogs(List logs, Calendar time, boolean tipsEna for (LogEntry log : logs) { ConsoleColors color = ConsoleColors.WHITE; if (log.getType() == LogType.WARNING) { - color = ConsoleColors.YELLOW; + color = ConsoleColors.ORANGE; } else if (log.getType() == LogType.ERROR) { color = ConsoleColors.RED; } else if (log.getType() == LogType.INFO) { diff --git a/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java b/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java new file mode 100644 index 00000000..b20d0e5a --- /dev/null +++ b/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java @@ -0,0 +1,42 @@ +package io.github.syst3ms.skriptparser.tags; + +import io.github.syst3ms.skriptparser.Parser; +import io.github.syst3ms.skriptparser.registration.tags.ContinuousTag; +import io.github.syst3ms.skriptparser.util.color.ConsoleColors; + +import java.util.Locale; +import java.util.Optional; + +public class TagColor implements ContinuousTag { + + static { + Parser.getMainRegistration().addTag(TagColor.class); + } + + private ConsoleColors color; + + @Override + public boolean init(String key, String[] parameters) { + final Optional optional; + if (key.equalsIgnoreCase("color") && parameters.length != 0) + optional = ConsoleColors.search(parameters[0].toUpperCase(Locale.ROOT)); + else + optional = ConsoleColors.search(key); + + if (optional.isEmpty()) + return false; + + color = optional.get(); + return color != ConsoleColors.RESET; + } + + @Override + public String getValue() { + return color.toString(); + } + + @Override + public String toString(boolean debug) { + return ""; + } +} diff --git a/src/main/java/io/github/syst3ms/skriptparser/tags/TagReset.java b/src/main/java/io/github/syst3ms/skriptparser/tags/TagReset.java index 31154fe1..eae8ed49 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/tags/TagReset.java +++ b/src/main/java/io/github/syst3ms/skriptparser/tags/TagReset.java @@ -2,6 +2,7 @@ import io.github.syst3ms.skriptparser.Parser; import io.github.syst3ms.skriptparser.registration.tags.Tag; +import io.github.syst3ms.skriptparser.util.color.ConsoleColors; /** * A tag that resets all currently ongoing tags. @@ -24,7 +25,7 @@ public boolean init(String key, String[] parameters) { } public String getValue(String affected) { - return affected; + return ConsoleColors.RESET + affected; } public String toString(boolean debug) { diff --git a/src/main/java/io/github/syst3ms/skriptparser/util/ConsoleColors.java b/src/main/java/io/github/syst3ms/skriptparser/util/ConsoleColors.java deleted file mode 100644 index d8b4d9a8..00000000 --- a/src/main/java/io/github/syst3ms/skriptparser/util/ConsoleColors.java +++ /dev/null @@ -1,87 +0,0 @@ -package io.github.syst3ms.skriptparser.util; - -public enum ConsoleColors { - // Reset - RESET("\033[0m"), // Text Reset - - // Regular Colors - BLACK("\033[0;30m"), // BLACK - RED("\033[0;31m"), // RED - GREEN("\033[0;32m"), // GREEN - YELLOW("\033[0;33m"), // YELLOW - BLUE("\033[0;34m"), // BLUE - PURPLE("\033[0;35m"), // PURPLE - CYAN("\033[0;36m"), // CYAN - WHITE("\033[0;37m"), // WHITE - - // Bold - BLACK_BOLD("\033[1;30m"), // BLACK - RED_BOLD("\033[1;31m"), // RED - GREEN_BOLD("\033[1;32m"), // GREEN - YELLOW_BOLD("\033[1;33m"), // YELLOW - BLUE_BOLD("\033[1;34m"), // BLUE - PURPLE_BOLD("\033[1;35m"), // PURPLE - CYAN_BOLD("\033[1;36m"), // CYAN - WHITE_BOLD("\033[1;37m"), // WHITE - - // Underline - BLACK_UNDERLINED("\033[4;30m"), // BLACK - RED_UNDERLINED("\033[4;31m"), // RED - GREEN_UNDERLINED("\033[4;32m"), // GREEN - YELLOW_UNDERLINED("\033[4;33m"), // YELLOW - BLUE_UNDERLINED("\033[4;34m"), // BLUE - PURPLE_UNDERLINED("\033[4;35m"), // PURPLE - CYAN_UNDERLINED("\033[4;36m"), // CYAN - WHITE_UNDERLINED("\033[4;37m"), // WHITE - - // Background - BLACK_BACKGROUND("\033[40m"), // BLACK - RED_BACKGROUND("\033[41m"), // RED - GREEN_BACKGROUND("\033[42m"), // GREEN - YELLOW_BACKGROUND("\033[43m"), // YELLOW - BLUE_BACKGROUND("\033[44m"), // BLUE - PURPLE_BACKGROUND("\033[45m"), // PURPLE - CYAN_BACKGROUND("\033[46m"), // CYAN - WHITE_BACKGROUND("\033[47m"), // WHITE - - // High Intensity - BLACK_BRIGHT("\033[0;90m"), // BLACK - RED_BRIGHT("\033[0;91m"), // RED - GREEN_BRIGHT("\033[0;92m"), // GREEN - YELLOW_BRIGHT("\033[0;93m"), // YELLOW - BLUE_BRIGHT("\033[0;94m"), // BLUE - PURPLE_BRIGHT("\033[0;95m"), // PURPLE - CYAN_BRIGHT("\033[0;96m"), // CYAN - WHITE_BRIGHT("\033[0;97m"), // WHITE - - // Bold High Intensity - BLACK_BOLD_BRIGHT("\033[1;90m"), // BLACK - RED_BOLD_BRIGHT("\033[1;91m"), // RED - GREEN_BOLD_BRIGHT("\033[1;92m"), // GREEN - YELLOW_BOLD_BRIGHT("\033[1;93m"), // YELLOW - BLUE_BOLD_BRIGHT("\033[1;94m"), // BLUE - PURPLE_BOLD_BRIGHT("\033[1;95m"), // PURPLE - CYAN_BOLD_BRIGHT("\033[1;96m"), // CYAN - WHITE_BOLD_BRIGHT("\033[1;97m"), // WHITE - - // High Intensity backgrounds - BLACK_BACKGROUND_BRIGHT("\033[0;100m"), // BLACK - RED_BACKGROUND_BRIGHT("\033[0;101m"), // RED - GREEN_BACKGROUND_BRIGHT("\033[0;102m"), // GREEN - YELLOW_BACKGROUND_BRIGHT("\033[0;103m"), // YELLOW - BLUE_BACKGROUND_BRIGHT("\033[0;104m"), // BLUE - PURPLE_BACKGROUND_BRIGHT("\033[0;105m"), // PURPLE - CYAN_BACKGROUND_BRIGHT("\033[0;106m"), // CYAN - WHITE_BACKGROUND_BRIGHT("\033[0;107m"); // WHITE - - private final String color; - - ConsoleColors(String color) { - this.color = color; - } - - public String toString() { - return this.color; - } - -} \ No newline at end of file diff --git a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java new file mode 100644 index 00000000..02cb3f91 --- /dev/null +++ b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java @@ -0,0 +1,110 @@ +package io.github.syst3ms.skriptparser.util.color; + +import java.util.Optional; +import java.util.stream.Stream; + +public enum ConsoleColors { + + // Reset + RESET("0", true), + + // Normal Colors + BLACK("30", false), + RED("31", false), + GREEN("32", false, "dark_green"), + ORANGE("33", false, "orange", "amber"), + BLUE("34", false, "dark_blue"), + PURPLE("35", false, "dark_pink"), + CYAN("36", false, "dark_aqua"), + WHITE("37", false, "dark_gray"), + + // Bright Colors + BLACK_BRIGHT("90", false, "gray", "grey"), + RED_BRIGHT("91", false, "pink"), + GREEN_BRIGHT("92", false, "lime", "light_green"), + ORANGE_BRIGHT("93", false, "yellow"), + BLUE_BRIGHT("94", false, "light_blue"), + PURPLE_BRIGHT("95", false, "light_purple"), + CYAN_BRIGHT("96", false, "light_aqua", "aqua"), + WHITE_BRIGHT("97", false), + + // Colors background + BLACK_BACKGROUND(BLACK, "40"), + RED_BACKGROUND(RED, "41"), + GREEN_BACKGROUND(GREEN, "42"), + ORANGE_BACKGROUND(ORANGE, "43"), + BLUE_BACKGROUND(BLUE, "44"), + PURPLE_BACKGROUND(PURPLE, "45"), + CYAN_BACKGROUND(CYAN, "46"), + WHITE_BACKGROUND(WHITE, "47"), + + // Styles + BOLD("1", true, "b"), + ITALIC("3", true, "o"), + UNDERLINE("4", true, "n", "u"), + STRICKTHROUGH("9", true, "m", "strike"), + ; + + private static final String ANSI_DELIMITER = "\033["; + + private final String code; + private final boolean style; + private final String[] aliases; + + /** + * Used for backgrounds colors only. + * It will generate values according to it. + * @param color + */ + ConsoleColors(ConsoleColors color, String code) { + this.code = code; + this.style = false; + this.aliases = Stream.of(color.getAliases()) + .map(alias -> alias + "_background") + .toArray(String[]::new); + } + + ConsoleColors(String code, boolean style, String... aliases) { + this.code = code; + this.style = style; + this.aliases = aliases; + } + + public static Optional search(String input) { + for (ConsoleColors color : values()) + if (color.match(input)) + return Optional.of(color); + return Optional.empty(); + } + + public String format() { + return ANSI_DELIMITER + code + "m"; + } + + public boolean match(String other) { + if (other.replace(" ", "_").equalsIgnoreCase(name())) + return true; + // Checking for aliases + for (String alias : aliases) + if (other.replace(" ", "_").equalsIgnoreCase(alias)) + return true; + + return false; + } + + public String toString() { + return format(); + } + + public String[] getAliases() { + return aliases; + } + + public String getCode() { + return code; + } + + public boolean isStyle() { + return style; + } +} \ No newline at end of file From 27ca17ffd1d3dc787dcef3c10cdeabc12c4dbcd2 Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 28 Jun 2022 21:47:19 +0200 Subject: [PATCH 07/10] :zap: Fixed wrong brackets definition --- .../java/io/github/syst3ms/skriptparser/tags/TagColor.java | 5 +++-- .../syst3ms/skriptparser/util/color/ConsoleColors.java | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java b/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java index b20d0e5a..e297ba51 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java +++ b/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java @@ -18,10 +18,11 @@ public class TagColor implements ContinuousTag { @Override public boolean init(String key, String[] parameters) { final Optional optional; - if (key.equalsIgnoreCase("color") && parameters.length != 0) + if (key.equalsIgnoreCase("color") && parameters.length != 0) { optional = ConsoleColors.search(parameters[0].toUpperCase(Locale.ROOT)); - else + } else { optional = ConsoleColors.search(key); + } if (optional.isEmpty()) return false; diff --git a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java index 02cb3f91..81cc8582 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java +++ b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java @@ -71,9 +71,10 @@ public enum ConsoleColors { } public static Optional search(String input) { - for (ConsoleColors color : values()) + for (ConsoleColors color : values()) { if (color.match(input)) return Optional.of(color); + } return Optional.empty(); } @@ -85,9 +86,10 @@ public boolean match(String other) { if (other.replace(" ", "_").equalsIgnoreCase(name())) return true; // Checking for aliases - for (String alias : aliases) + for (String alias : aliases) { if (other.replace(" ", "_").equalsIgnoreCase(alias)) return true; + } return false; } From cc263ccfea58eb0b5f0dfe6731e5bb8e1a820cc6 Mon Sep 17 00:00:00 2001 From: Sky <50667548+SkyCraft78@users.noreply.github.com> Date: Wed, 3 Aug 2022 20:22:39 +0200 Subject: [PATCH 08/10] Update src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java Co-authored-by: Mwexim <38397639+Mwexim@users.noreply.github.com> --- .../github/syst3ms/skriptparser/util/color/ConsoleColors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java index 81cc8582..fc9102c5 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java +++ b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java @@ -40,7 +40,7 @@ public enum ConsoleColors { // Styles BOLD("1", true, "b"), - ITALIC("3", true, "o"), + ITALIC("3", true, "o", "it", "i"), UNDERLINE("4", true, "n", "u"), STRICKTHROUGH("9", true, "m", "strike"), ; From 578bc75b18efc53187dbad8bc882a062e5f5d0c2 Mon Sep 17 00:00:00 2001 From: Sky <50667548+SkyCraft78@users.noreply.github.com> Date: Wed, 3 Aug 2022 20:22:55 +0200 Subject: [PATCH 09/10] Update src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java Co-authored-by: Mwexim <38397639+Mwexim@users.noreply.github.com> --- src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java b/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java index e297ba51..48e901de 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java +++ b/src/main/java/io/github/syst3ms/skriptparser/tags/TagColor.java @@ -19,7 +19,7 @@ public class TagColor implements ContinuousTag { public boolean init(String key, String[] parameters) { final Optional optional; if (key.equalsIgnoreCase("color") && parameters.length != 0) { - optional = ConsoleColors.search(parameters[0].toUpperCase(Locale.ROOT)); + optional = ConsoleColors.search(parameters[0]); } else { optional = ConsoleColors.search(key); } From dad941d8f47dce06a015d21ffa7f5828716862fc Mon Sep 17 00:00:00 2001 From: Sky <50667548+SkyCraft78@users.noreply.github.com> Date: Wed, 3 Aug 2022 20:23:09 +0200 Subject: [PATCH 10/10] Update src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java Co-authored-by: Mwexim <38397639+Mwexim@users.noreply.github.com> --- .../github/syst3ms/skriptparser/util/color/ConsoleColors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java index fc9102c5..6e553977 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java +++ b/src/main/java/io/github/syst3ms/skriptparser/util/color/ConsoleColors.java @@ -42,7 +42,7 @@ public enum ConsoleColors { BOLD("1", true, "b"), ITALIC("3", true, "o", "it", "i"), UNDERLINE("4", true, "n", "u"), - STRICKTHROUGH("9", true, "m", "strike"), + STRIKETHROUGH("9", true, "m", "strike", "s"), ; private static final String ANSI_DELIMITER = "\033[";