Fixed version check on HEX

This commit is contained in:
Stephan 2022-08-24 17:51:52 -07:00
parent c9901ca9da
commit 8d1430f621
2 changed files with 60 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;
}
}