From 24c0d0fcd3ca9f29cbd9c6d9253b6fdd5f26a43c Mon Sep 17 00:00:00 2001 From: Ismael Hanbel Date: Wed, 19 Jun 2024 09:42:53 +0200 Subject: [PATCH] Avoid usage of Bukkit, instead use own version handler --- .../com/xism4/sternalboard/SternalBoardHandler.java | 6 +++++- .../java/com/xism4/sternalboard/utils/TextUtils.java | 10 +++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/com/xism4/sternalboard/SternalBoardHandler.java b/api/src/main/java/com/xism4/sternalboard/SternalBoardHandler.java index 590c310..26bde97 100644 --- a/api/src/main/java/com/xism4/sternalboard/SternalBoardHandler.java +++ b/api/src/main/java/com/xism4/sternalboard/SternalBoardHandler.java @@ -820,11 +820,15 @@ public enum ScoreboardAction { CHANGE, REMOVE } - public enum VersionType { + public enum VersionType { V1_7, V1_8, V1_13, V1_17; public boolean isHigherOrEqual() { return VERSION_TYPE.ordinal() >= ordinal(); } + + public boolean isLowerOrEqual() { + return VERSION_TYPE.ordinal() <= ordinal(); + } } } \ No newline at end of file diff --git a/plugin/src/main/java/com/xism4/sternalboard/utils/TextUtils.java b/plugin/src/main/java/com/xism4/sternalboard/utils/TextUtils.java index bf43875..f1fdbdb 100644 --- a/plugin/src/main/java/com/xism4/sternalboard/utils/TextUtils.java +++ b/plugin/src/main/java/com/xism4/sternalboard/utils/TextUtils.java @@ -1,11 +1,10 @@ package com.xism4.sternalboard.utils; +import com.xism4.sternalboard.SternalBoardHandler; import com.xism4.sternalboard.SternalBoardPlugin; import me.clip.placeholderapi.PlaceholderAPI; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.md_5.bungee.api.ChatColor; @@ -21,18 +20,15 @@ public class TextUtils { private static final String MINI_MESSAGE_HEX = ""; private static final Pattern HEX_PATTERN = Pattern.compile("(#|&#)([A-Fa-f0-9]){6}"); - private static final int SERVER_VERSION = Integer.parseInt( - Bukkit.getBukkitVersion().split("-")[0].split("\\.")[1] - ); public static String colorize(String text) { - if (SERVER_VERSION < 16) { + if (SternalBoardHandler.VersionType.V1_13.isLowerOrEqual()) { return ChatColor.translateAlternateColorCodes('&', text); } text = transformLegacyHex(text); - text = text.replaceAll("\u00a7", "&"); + text = text.replaceAll("ยง", "&"); MiniMessage mm = MiniMessage.miniMessage(); text = LegacyComponentSerializer.legacySection().serialize(mm.deserialize(text));