Skip to content

Commit

Permalink
Avoid usage of Bukkit, instead use own version handler
Browse files Browse the repository at this point in the history
  • Loading branch information
xism4 committed Jun 19, 2024
1 parent 577dc1d commit 24c0d0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
10 changes: 3 additions & 7 deletions plugin/src/main/java/com/xism4/sternalboard/utils/TextUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,18 +20,15 @@ public class TextUtils {
private static final String MINI_MESSAGE_HEX = "<color:{color}>";
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));
Expand Down

0 comments on commit 24c0d0f

Please sign in to comment.