From 8d1430f621ab7df6b093ca84538005b71fcd95f9 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 24 Aug 2022 17:51:52 -0700 Subject: [PATCH] Fixed version check on HEX --- .../playerbalanceraddon/util/Color.java | 20 ++++---- .../util/VersionCheck.java | 48 +++++++++++++++++++ 2 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/VersionCheck.java diff --git a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/Color.java b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/Color.java index 5a6fcd0..30fef31 100644 --- a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/Color.java +++ b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/Color.java @@ -12,15 +12,19 @@ public class Color { private static final Pattern HEX_PATTERN = Pattern.compile("(&#[0-9a-fA-F]{6})"); public static String translate(String message) { - Matcher matcher = HEX_PATTERN.matcher(message); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String hex = matcher.group(1).substring(1); - matcher.appendReplacement(sb, net.md_5.bungee.api.ChatColor.of(hex) + ""); - } - matcher.appendTail(sb); + String hexColored = message; - String hexColored = sb.toString(); + if (VersionCheck.isOnePointSixteenPlus()) { + Matcher matcher = HEX_PATTERN.matcher(message); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String hex = matcher.group(1).substring(1); + matcher.appendReplacement(sb, net.md_5.bungee.api.ChatColor.of(hex) + ""); + } + matcher.appendTail(sb); + + hexColored = sb.toString(); + } return ChatColor.translateAlternateColorCodes('&', hexColored); } diff --git a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/VersionCheck.java b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/VersionCheck.java new file mode 100644 index 0000000..fdcc918 --- /dev/null +++ b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/util/VersionCheck.java @@ -0,0 +1,48 @@ +package com.jaimemartz.playerbalanceraddon.util; + +import org.bukkit.Bukkit; + +public class VersionCheck { + + public static boolean isOnePointEightPlus() { + if (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11") || Bukkit.getVersion().contains("1.12") || Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { + return true; + } + return false; + } + + public static boolean isOnePointNinePlus() { + if (Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11") || Bukkit.getVersion().contains("1.12") || Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { + return true; + } + return false; + } + + public static boolean isOnePointThirteenPlus() { + if (Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { + return true; + } + return false; + } + + public static boolean isOnePointFourteenPlus() { + if (Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { + return true; + } + return false; + } + + public static boolean isOnePointSixteenPlus() { + if (Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18") || Bukkit.getVersion().contains("1.19")) { + return true; + } + return false; + } + + public static boolean isOnePointSeven() { + if (Bukkit.getVersion().contains("1.7")) { + return true; + } + return false; + } +}