From 3dbcaa059cd65c43618e5f5a987e66076787a840 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 16 Feb 2024 03:58:50 +0500 Subject: [PATCH] v2.5.1 --- pom.xml | 11 +- .../nightcore/command/api/NightCommand.java | 11 -- .../nightcore/core/CoreConfig.java | 2 +- .../language/legacy/LegacyLangMessage.java | 179 ------------------ .../language/legacy/LegacyLangString.java | 53 ------ .../language/legacy/LegacyLangText.java | 68 ------- .../language/legacy/LegacyMessageOption.java | 26 --- .../language/legacy/LegacyMessageOptions.java | 86 --------- .../nightcore/menu/impl/EditorMenu.java | 11 -- .../nightexpress/nightcore/util/Colors.java | 29 --- .../nightcore/util/NumberUtil.java | 6 + .../nightexpress/nightcore/util/Players.java | 2 +- .../nightcore/util/text/NightMessage.java | 2 +- .../util/text/decoration/ColorDecorator.java | 21 ++ .../nightcore/util/text/tag/StandardTags.java | 27 --- .../nightcore/util/text/tag/Tags.java | 15 +- .../util/text/tag/impl/GradientTag.java | 4 +- .../util/text/tag/impl/HexColorTag.java | 19 +- .../util/text/tag/impl/ShortHexColorTag.java | 42 ++++ 19 files changed, 101 insertions(+), 513 deletions(-) delete mode 100644 src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangMessage.java delete mode 100644 src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangString.java delete mode 100644 src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangText.java delete mode 100644 src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOption.java delete mode 100644 src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOptions.java delete mode 100644 src/main/java/su/nightexpress/nightcore/util/Colors.java create mode 100644 src/main/java/su/nightexpress/nightcore/util/text/decoration/ColorDecorator.java delete mode 100644 src/main/java/su/nightexpress/nightcore/util/text/tag/StandardTags.java create mode 100644 src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java diff --git a/pom.xml b/pom.xml index 35451a2..4d05ceb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ su.nightexpress.nightcore nightcore - 2.5.0 + 2.5.1 17 @@ -18,10 +18,12 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - + + + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -29,14 +31,17 @@ false + opencollab-snapshot https://repo.opencollab.dev/maven-snapshots/ + minecraft-repo https://libraries.minecraft.net/ + jitpack.io https://jitpack.io diff --git a/src/main/java/su/nightexpress/nightcore/command/api/NightCommand.java b/src/main/java/su/nightexpress/nightcore/command/api/NightCommand.java index 0fd567d..279283e 100644 --- a/src/main/java/su/nightexpress/nightcore/command/api/NightCommand.java +++ b/src/main/java/su/nightexpress/nightcore/command/api/NightCommand.java @@ -7,7 +7,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nightexpress.nightcore.command.CommandFlag; import su.nightexpress.nightcore.language.entry.LangString; -import su.nightexpress.nightcore.language.legacy.LegacyLangString; import su.nightexpress.nightcore.util.placeholder.Placeholder; import java.util.Collection; @@ -69,11 +68,6 @@ public interface NightCommand extends Placeholder { @NotNull String getUsage(); - @Deprecated - default void setUsage(@NotNull LegacyLangString string) { - this.setUsage(string.getString()); - } - default void setUsage(@NotNull LangString string) { this.setUsage(string.getString()); } @@ -82,11 +76,6 @@ public interface NightCommand extends Placeholder { @NotNull String getDescription(); - @Deprecated - default void setDescription(@NotNull LegacyLangString string) { - this.setDescription(string.getString()); - } - default void setDescription(@NotNull LangString string) { this.setDescription(string.getString()); } diff --git a/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java b/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java index e16dd06..0306945 100644 --- a/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java +++ b/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java @@ -68,7 +68,7 @@ public class CoreConfig { "[Default is true]"); public static final ConfigValue LEGACY_COLOR_SUPPORT = ConfigValue.create("Engine.Legacy_Color_Support", - false, + true, "Allows to use legacy color codes (such as '&7', '&l', etc.) in plugin configurations.", "This setting exist for backwards compatibility only! There are NO GUARANTEES that it will persist for future updates!", "You should NOT use it unless you need to add support for your custom language configurations & translations with legacy codes.", diff --git a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangMessage.java b/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangMessage.java deleted file mode 100644 index db59b50..0000000 --- a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangMessage.java +++ /dev/null @@ -1,179 +0,0 @@ -package su.nightexpress.nightcore.language.legacy; - -import me.clip.placeholderapi.PlaceholderAPI; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.NightCorePlugin; -import su.nightexpress.nightcore.language.message.OutputType; -import su.nightexpress.nightcore.util.Colorizer; -import su.nightexpress.nightcore.util.Players; -import su.nightexpress.nightcore.util.message.NexParser; -import su.nightexpress.nightcore.util.regex.TimedMatcher; -import su.nightexpress.nightcore.util.wrapper.UniSound; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.regex.Pattern; - -@Deprecated -public class LegacyLangMessage { - - private static final Pattern OPTIONS_PATTERN = Pattern.compile("<\\!(.*?)\\!>"); - - private final NightCorePlugin plugin; - private final LegacyMessageOptions options; - private final List defaultText; - - private List text; - - public LegacyLangMessage(@NotNull NightCorePlugin plugin, @NotNull List defaultText) { - this.plugin = plugin; - this.options = new LegacyMessageOptions(); - this.defaultText = defaultText; - this.setText(defaultText); - this.setOptions(); - } - - private LegacyLangMessage(@NotNull LegacyLangMessage from) { - this.plugin = from.plugin; - this.options = from.options.copy(); - this.defaultText = new ArrayList<>(from.defaultText); - this.text = new ArrayList<>(from.text); - } - - private void setOptions() { - List text = this.getText(); - if (text.isEmpty()) return; - - String msg = text.get(0); - TimedMatcher matcher = TimedMatcher.create(OPTIONS_PATTERN, msg); - if (!matcher.find()) return; - - String optionTag = matcher.getMatcher().group(0); - String optionArgs = matcher.getMatcher().group(1).trim(); - this.text.set(0, msg.replace(optionTag, "")); - this.text.removeIf(String::isEmpty); - this.options.read(optionArgs); - } - - @NotNull - public List getDefaultText() { - return this.defaultText; - } - - @NotNull - public List getText() { - return this.text; - } - - @NotNull - public List getText(@NotNull CommandSender sender) { - if (!this.options.hasPlaceholderAPI() || !(sender instanceof Player player)) return this.getText(); - - List text = new ArrayList<>(this.getText()); - text.replaceAll(line -> PlaceholderAPI.setPlaceholders(player, line)); - return text; - } - - private void setText(@NotNull List text) { - this.text = Colorizer.apply(text); - this.text.removeIf(String::isEmpty); - } - - @NotNull - public LegacyLangMessage replace(@NotNull String var, @NotNull Object replacer) { - return this.replace(str -> str.replace(var, String.valueOf(replacer))); - } - - @NotNull - public LegacyLangMessage replace(@NotNull UnaryOperator replacer) { - if (this.isEmpty()) return this; - - LegacyLangMessage msgCopy = new LegacyLangMessage(this); - msgCopy.getText().replaceAll(replacer); - return msgCopy; - } - - @NotNull - public LegacyLangMessage replace(@NotNull Predicate predicate, @NotNull BiConsumer> replacer) { - if (this.isEmpty()) return this; - - LegacyLangMessage msgCopy = new LegacyLangMessage(this); - List replaced = new ArrayList<>(); - msgCopy.getText().forEach(line -> { - if (predicate.test(line)) { - replacer.accept(line, replaced); - return; - } - replaced.add(line); - }); - msgCopy.setText(replaced); - return msgCopy; - } - - public boolean isEmpty() { - return (this.options.getType() == OutputType.NONE || this.getText().isEmpty()); - } - - public void broadcast() { - if (this.isEmpty()) return; - - Bukkit.getServer().getOnlinePlayers().forEach(this::send); - this.send(Bukkit.getServer().getConsoleSender()); - } - - public void send(@NotNull CommandSender sender) { - if (this.isEmpty()) return; - - if (this.options.getSound() != null && sender instanceof Player player) { - UniSound.of(this.options.getSound()).play(player); - } - - if (this.options.getType() == OutputType.CHAT) { - String prefix = this.options.hasPrefix() ? plugin.getPrefix() : ""; - this.getText(sender).forEach(line -> { - Players.sendRichMessage(sender, prefix + line); - }); - return; - } - - if (sender instanceof Player player) { - if (this.options.getType() == OutputType.ACTION_BAR) { - Players.sendActionBar(player, String.join(" ", this.getText(player))); - } - else if (this.options.getType() == OutputType.TITLES) { - List list = this.getText(player); - String title = list.size() > 0 ? NexParser.toPlainText(list.get(0)) : ""; - String subtitle = list.size() > 1 ? NexParser.toPlainText(list.get(1)) : ""; - player.sendTitle(title, subtitle, this.options.getTitleTimes()[0], this.options.getTitleTimes()[1], this.options.getTitleTimes()[2]); - } - } - } - - /*@NotNull - public List asList() { - return this.asList(this.getText()); - } - - @NotNull - public List asList(@NotNull CommandSender sender) { - return this.asList(this.getText(sender)); - } - - @NotNull - private List asList(@NotNull String localized) { - return this.isEmpty() ? Collections.emptyList() : Stream.of(localized.split("\\\\n")) - .filter(Predicate.not(String::isEmpty)).toList(); - } - - @NotNull - @Deprecated - public String normalizeLines() { - return String.join("\n", this.asList()); - }*/ -} diff --git a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangString.java b/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangString.java deleted file mode 100644 index e70294c..0000000 --- a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangString.java +++ /dev/null @@ -1,53 +0,0 @@ -package su.nightexpress.nightcore.language.legacy; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.NightCorePlugin; -import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.language.entry.LangEntry; -import su.nightexpress.nightcore.util.Colorizer; - -@Deprecated -public class LegacyLangString extends LangEntry { - - private String string; - - public LegacyLangString(@NotNull String path, @NotNull String defaultText) { - super(path, defaultText); - } - - @NotNull - public static LegacyLangString of(@NotNull String path, @NotNull String defaultText) { - return new LegacyLangString(path, defaultText); - } - - @Override - public boolean write(@NotNull FileConfig config) { - if (!config.contains(this.getPath())) { - String textDefault = this.getDefaultText(); - config.set(this.getPath(), textDefault); - return true; - } - return false; - } - - @Override - @NotNull - public String load(@NotNull NightCorePlugin plugin) { - FileConfig config = plugin.getLang(); - - this.write(config); - String text = config.getString(this.getPath(), "<" + this.getPath() + ">"); - this.setString(text); - - return this.getString(); - } - - @NotNull - public String getString() { - return string; - } - - public void setString(@NotNull String string) { - this.string = Colorizer.apply(string); - } -} diff --git a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangText.java b/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangText.java deleted file mode 100644 index 3e4d6f3..0000000 --- a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyLangText.java +++ /dev/null @@ -1,68 +0,0 @@ -package su.nightexpress.nightcore.language.legacy; - -import org.jetbrains.annotations.NotNull; -import su.nightexpress.nightcore.NightCorePlugin; -import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.language.entry.LangEntry; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Deprecated -public class LegacyLangText extends LangEntry { - - private LegacyLangMessage message; - - public LegacyLangText(@NotNull String path, @NotNull String... defaultText) { - super(path, String.join("\n", defaultText)); - } - - @NotNull - public static LegacyLangText of(@NotNull String path, @NotNull String defaultText) { - return new LegacyLangText(path, defaultText); - } - - @NotNull - public static LegacyLangText of(@NotNull String path, @NotNull String... defaultText) { - return new LegacyLangText(path, defaultText); - } - - @Override - public boolean write(@NotNull FileConfig config) { - if (!config.contains(this.getPath())) { - String textDefault = this.getDefaultText(); - String[] textSplit = textDefault.split("\n"); - config.set(this.getPath(), textSplit.length > 1 ? Arrays.asList(textSplit) : textDefault); - return true; - } - return false; - } - - @Override - @NotNull - public LegacyLangMessage load(@NotNull NightCorePlugin plugin) { - FileConfig config = plugin.getLang(); - - this.write(config); - - List text = new ArrayList<>(config.getStringList(this.getPath())); - if (text.isEmpty()) { - text.add(config.getString(this.getPath(), "<" + this.getPath() + ">")); - } - - //String text = !list.isEmpty() ? String.join("\\n", list) : config.getString(this.getPath(), "<" + this.getPath() + ">"); - this.setMessage(new LegacyLangMessage(plugin, text)); - - return this.getMessage(); - } - - @NotNull - public LegacyLangMessage getMessage() { - return message; - } - - public void setMessage(@NotNull LegacyLangMessage message) { - this.message = message; - } -} diff --git a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOption.java b/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOption.java deleted file mode 100644 index 6a7617c..0000000 --- a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOption.java +++ /dev/null @@ -1,26 +0,0 @@ -package su.nightexpress.nightcore.language.legacy; - -import org.jetbrains.annotations.NotNull; - -import java.util.regex.Pattern; - -@Deprecated -public enum LegacyMessageOption { - - PREFIX("prefix"), - SOUND("sound"), - TYPE("type"), - PAPI("papi"), - ; - - private final Pattern pattern; - - LegacyMessageOption(@NotNull String name) { - this.pattern = Pattern.compile(name + ":(?:'|\")(.*?)(?:'|\")(?=>|\\s|$)"); - } - - @NotNull - public Pattern getPattern() { - return pattern; - } -} diff --git a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOptions.java b/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOptions.java deleted file mode 100644 index f62a985..0000000 --- a/src/main/java/su/nightexpress/nightcore/language/legacy/LegacyMessageOptions.java +++ /dev/null @@ -1,86 +0,0 @@ -package su.nightexpress.nightcore.language.legacy; - -import org.bukkit.Sound; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import su.nightexpress.nightcore.language.message.OutputType; -import su.nightexpress.nightcore.util.NumberUtil; -import su.nightexpress.nightcore.util.Plugins; -import su.nightexpress.nightcore.util.StringUtil; -import su.nightexpress.nightcore.util.regex.TimedMatcher; - -@Deprecated -public class LegacyMessageOptions { - - private OutputType type; - private boolean hasPrefix; - private boolean papi; - private Sound sound; - private int[] titleTimes; - - public LegacyMessageOptions() { - this.type = OutputType.CHAT; - this.hasPrefix = true; - } - - @NotNull - public LegacyMessageOptions copy() { - LegacyMessageOptions copy = new LegacyMessageOptions(); - copy.type = this.type; - copy.hasPrefix = this.hasPrefix; - copy.papi = this.papi; - copy.sound = this.sound; - copy.titleTimes = this.titleTimes; - return copy; - } - - public void read(@NotNull String matchOptions) { - for (LegacyMessageOption option : LegacyMessageOption.values()) { - TimedMatcher matcherParam = TimedMatcher.create(option.getPattern(), matchOptions); - if (!matcherParam.find()) continue; - - String optionValue = matcherParam.getMatcher().group(1).stripLeading(); - switch (option) { - case TYPE -> { - String[] split = optionValue.split(":"); - this.type = StringUtil.getEnum(split[0], OutputType.class).orElse(OutputType.CHAT); - if (this.type == OutputType.TITLES) { - this.titleTimes = new int[3]; - if (split.length >= 4) { - this.titleTimes[0] = NumberUtil.getInteger(split[1]); - this.titleTimes[1] = NumberUtil.getAnyInteger(split[2], -1); - this.titleTimes[2] = NumberUtil.getInteger(split[3]); - } - - if (this.titleTimes[1] < 0) this.titleTimes[1] = Short.MAX_VALUE; - } - } - case PREFIX -> this.hasPrefix = Boolean.parseBoolean(optionValue); - case PAPI -> this.papi = Boolean.parseBoolean(optionValue) && Plugins.hasPlaceholderAPI(); - case SOUND -> this.sound = StringUtil.getEnum(optionValue, Sound.class).orElse(null); - } - } - } - - @NotNull - public OutputType getType() { - return type; - } - - public boolean hasPrefix() { - return this.hasPrefix; - } - - public boolean hasPlaceholderAPI() { - return this.papi; - } - - @Nullable - public Sound getSound() { - return sound; - } - - public int[] getTitleTimes() { - return titleTimes; - } -} diff --git a/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java b/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java index 9e80fad..fdb6ead 100644 --- a/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java +++ b/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java @@ -10,7 +10,6 @@ import su.nightexpress.nightcore.dialog.Dialog; import su.nightexpress.nightcore.dialog.DialogHandler; import su.nightexpress.nightcore.language.entry.LangItem; import su.nightexpress.nightcore.language.entry.LangString; -import su.nightexpress.nightcore.language.legacy.LegacyLangString; import su.nightexpress.nightcore.menu.MenuViewer; import su.nightexpress.nightcore.menu.item.ItemHandler; import su.nightexpress.nightcore.menu.item.MenuItem; @@ -85,16 +84,6 @@ public abstract class EditorMenu

extends AbstractM return menuItem; } - @Deprecated - public void handleInput(@NotNull MenuViewer viewer, @NotNull LegacyLangString prompt, @NotNull DialogHandler handler) { - this.handleInput(viewer.getPlayer(), prompt, handler); - } - - @Deprecated - public void handleInput(@NotNull Player player, @NotNull LegacyLangString prompt, @NotNull DialogHandler handler) { - this.handleInput(player, prompt.getString(), handler); - } - @NotNull public Dialog handleInput(@NotNull MenuViewer viewer, @NotNull LangString prompt, @NotNull DialogHandler handler) { return this.handleInput(viewer.getPlayer(), prompt, handler); diff --git a/src/main/java/su/nightexpress/nightcore/util/Colors.java b/src/main/java/su/nightexpress/nightcore/util/Colors.java deleted file mode 100644 index 5ac3c48..0000000 --- a/src/main/java/su/nightexpress/nightcore/util/Colors.java +++ /dev/null @@ -1,29 +0,0 @@ -package su.nightexpress.nightcore.util; - -@Deprecated -public class Colors { - - public static final String BOLD = "&l"; - public static final String WHITE = "#e8f2f2"; - public static final String GRAY = "#aaa8a8"; - public static final String GREEN = "#74ea31"; - public static final String YELLOW = "#ead931"; - public static final String ORANGE = "#ea9631"; - public static final String RED = "#ea3131"; - public static final String BLUE = "#3196ea"; - public static final String CYAN = "#31eace"; - public static final String PURPLE = "#bd31ea"; - public static final String PINK = "#ea31b2"; - - public static final String DARK_GRAY = "#6c6c62"; - public static final String LIGHT_GRAY = "#d4d9d8"; - public static final String LIGHT_GREEN = "#aefd5e"; - public static final String LIGHT_YELLOW = "#ffeea2"; - public static final String LIGHT_ORANGE = "#fdba5e"; - public static final String LIGHT_RED = "#fd5e5e"; - public static final String LIGHT_BLUE = "#5e9dfd"; - public static final String LIGHT_CYAN = "#5edefd"; - public static final String LIGHT_PURPLE = "#e39fff"; - public static final String LIGHT_PINK = "#fd8ddb"; - -} diff --git a/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java b/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java index aa77476..6e44e07 100644 --- a/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java +++ b/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java @@ -41,6 +41,12 @@ public class NumberUtil { return CoreConfig.NUMBER_FORMAT.get().format(value); } + @NotNull + public static String compact(double value) { + Pair pair = formatCompact(value); + return pair.getFirst() + pair.getSecond(); + } + @NotNull public static Pair formatCompact(double value) { boolean negative = false; diff --git a/src/main/java/su/nightexpress/nightcore/util/Players.java b/src/main/java/su/nightexpress/nightcore/util/Players.java index bb3c286..e81936a 100644 --- a/src/main/java/su/nightexpress/nightcore/util/Players.java +++ b/src/main/java/su/nightexpress/nightcore/util/Players.java @@ -133,7 +133,7 @@ public class Players { @Deprecated public static void sendRichMessage(@NotNull CommandSender sender, @NotNull String message) { - if (!(sender instanceof Player player)) { + if (!(sender instanceof Player)) { sender.sendMessage(Colorizer.apply(NexParser.toPlainText(message))); return; } diff --git a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java b/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java index 9c17f1f..cb26637 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java @@ -38,7 +38,7 @@ public class NightMessage { registerTags(Tags.BOLD, Tags.ITALIC, Tags.OBFUSCATED, Tags.STRIKETHROUGH, Tags.UNDERLINED); registerTags( - Tags.FONT, Tags.HEX_COLOR, Tags.GRADIENT, + Tags.FONT, Tags.HEX_COLOR, Tags.HEX_COLOR_SHORT, Tags.GRADIENT, Tags.HOVER, Tags.CLICK, Tags.LINE_BREAK, Tags.RESET ); diff --git a/src/main/java/su/nightexpress/nightcore/util/text/decoration/ColorDecorator.java b/src/main/java/su/nightexpress/nightcore/util/text/decoration/ColorDecorator.java new file mode 100644 index 0000000..b8c3415 --- /dev/null +++ b/src/main/java/su/nightexpress/nightcore/util/text/decoration/ColorDecorator.java @@ -0,0 +1,21 @@ +package su.nightexpress.nightcore.util.text.decoration; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public class ColorDecorator implements Decorator { + + private final Color color; + + public ColorDecorator(@NotNull Color color) { + this.color = color; + } + + @Override + public void decorate(@NotNull BaseComponent component) { + component.setColor(ChatColor.of(this.color)); + } +} diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/StandardTags.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/StandardTags.java deleted file mode 100644 index ea13422..0000000 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/StandardTags.java +++ /dev/null @@ -1,27 +0,0 @@ -package su.nightexpress.nightcore.util.text.tag; - -@Deprecated -public class StandardTags { - - /*public static final String WHITE = Tags.WHITE.getFullName(); - public static final String GRAY = Tags.GRAY.getFullName(); - public static final String GREEN = Tags.GREEN.getFullName(); - public static final String YELLOW = Tags.YELLOW.getFullName(); - public static final String ORANGE = Tags.ORANGE.getFullName(); - public static final String RED = Tags.RED.getFullName(); - public static final String BLUE = Tags.BLUE.getFullName(); - public static final String CYAN = Tags.CYAN.getFullName(); - public static final String PURPLE = Tags.PURPLE.getFullName(); - public static final String PINK = Tags.PINK.getFullName(); - - public static final String DARK_GRAY = Tags.DARK_GRAY.getFullName(); - public static final String LIGHT_GRAY = Tags.LIGHT_GRAY.getFullName(); - public static final String LIGHT_GREEN = Tags.LIGHT_GREEN.getFullName(); - public static final String LIGHT_YELLOW = Tags.LIGHT_YELLOW.getFullName(); - public static final String LIGHT_ORANGE = Tags.LIGHT_ORANGE.getFullName(); - public static final String LIGHT_RED = Tags.LIGHT_RED.getFullName(); - public static final String LIGHT_BLUE = Tags.LIGHT_BLUE.getFullName(); - public static final String LIGHT_CYAN = Tags.LIGHT_CYAN.getFullName(); - public static final String LIGHT_PURPLE = Tags.LIGHT_PURPLE.getFullName(); - public static final String LIGHT_PINK = Tags.LIGHT_PINK.getFullName();*/ -} diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java index f2dc2e1..4c44229 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java @@ -4,13 +4,14 @@ import su.nightexpress.nightcore.util.text.tag.impl.*; public class Tags { - public static final ClickTag CLICK = new ClickTag(); - public static final FontTag FONT = new FontTag(); - public static final GradientTag GRADIENT = new GradientTag(); - public static final HexColorTag HEX_COLOR = new HexColorTag(); - public static final HoverTag HOVER = new HoverTag(); - public static final LineBreakTag LINE_BREAK = new LineBreakTag(); - public static final ResetTag RESET = new ResetTag(); + public static final ClickTag CLICK = new ClickTag(); + public static final FontTag FONT = new FontTag(); + public static final GradientTag GRADIENT = new GradientTag(); + public static final HexColorTag HEX_COLOR = new HexColorTag(); + public static final ShortHexColorTag HEX_COLOR_SHORT = new ShortHexColorTag(); + public static final HoverTag HOVER = new HoverTag(); + public static final LineBreakTag LINE_BREAK = new LineBreakTag(); + public static final ResetTag RESET = new ResetTag(); public static final FontStyleTag BOLD = new FontStyleTag("b", FontStyleTag.Style.BOLD); public static final FontStyleTag ITALIC = new FontStyleTag("i", FontStyleTag.Style.ITALIC); diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java index 28afed5..67b735a 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java @@ -24,7 +24,7 @@ public class GradientTag extends Tag implements DecoratorParser { @Override public boolean conflictsWith(@NotNull Tag tag) { - return super.conflictsWith(tag) || tag instanceof ColorTag || tag instanceof HexColorTag; + return super.conflictsWith(tag) || tag instanceof ColorTag || tag instanceof ShortHexColorTag || tag instanceof HexColorTag; } @Override @@ -55,6 +55,6 @@ public class GradientTag extends Tag implements DecoratorParser { GradientDecorator decorator = new GradientDecorator(from, to); - return new ParsedDecorator(decorator, 15 + tagLength); + return new ParsedDecorator(decorator, 15 + tagLength); // x2 hex (7+7), +1 for semicolon between } } diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java index 6fc52d6..103adc1 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java @@ -2,16 +2,17 @@ package su.nightexpress.nightcore.util.text.tag.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import su.nightexpress.nightcore.util.text.decoration.DecoratorParser; -import su.nightexpress.nightcore.util.text.decoration.ParsedDecorator; +import su.nightexpress.nightcore.util.text.decoration.*; import su.nightexpress.nightcore.util.text.tag.api.Tag; import java.awt.*; public class HexColorTag extends Tag implements DecoratorParser { + public static final String NAME = "color"; + public HexColorTag() { - super("#"); + super(NAME); } @Override @@ -21,21 +22,23 @@ public class HexColorTag extends Tag implements DecoratorParser { @Override public boolean conflictsWith(@NotNull Tag tag) { - return super.conflictsWith(tag) || tag instanceof ColorTag || tag instanceof GradientTag; + return tag instanceof ColorTag || tag instanceof HexColorTag; } @Override @Nullable public ParsedDecorator parse(@NotNull String content) { - Color color; + int tagLength = this.getName().length() + 1; // 1 for semicolon + content = content.substring(tagLength); try { - color = Color.decode(content); + Color color = Color.decode(content); + ColorDecorator decorator = new ColorDecorator(color); + + return new ParsedDecorator(decorator, 7 + tagLength); } catch (NumberFormatException exception) { return null; } - - return new ParsedDecorator(new ColorTag(color), 7); } } diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java new file mode 100644 index 0000000..d711e6f --- /dev/null +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java @@ -0,0 +1,42 @@ +package su.nightexpress.nightcore.util.text.tag.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import su.nightexpress.nightcore.util.text.decoration.DecoratorParser; +import su.nightexpress.nightcore.util.text.decoration.ParsedDecorator; +import su.nightexpress.nightcore.util.text.tag.api.Tag; + +import java.awt.*; + +@Deprecated +public class ShortHexColorTag extends Tag implements DecoratorParser { + + public ShortHexColorTag() { + super("#"); + } + + @Override + public int getWeight() { + return 10; + } + + @Override + public boolean conflictsWith(@NotNull Tag tag) { + return super.conflictsWith(tag) || tag instanceof ColorTag || tag instanceof GradientTag; + } + + @Override + @Nullable + public ParsedDecorator parse(@NotNull String content) { + Color color; + + try { + color = Color.decode(content); + } + catch (NumberFormatException exception) { + return null; + } + + return new ParsedDecorator(new ColorTag(color), 7); + } +}