Remove usage of java.awt.Color (#4312)

This fixes issues on headless JREs which lack java.awt classes.
This commit is contained in:
Josh Roy 2021-07-03 15:46:09 -04:00 committed by GitHub
parent 409210ccde
commit 7e25570344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -2,8 +2,8 @@ package com.earth2me.essentials.utils;
import net.ess3.api.IUser;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import java.awt.Color;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Set;
@ -129,7 +129,9 @@ public final class FormatUtil {
if (hexColor.length() != 6) {
throw new NumberFormatException("Invalid hex length");
}
Color.decode("#" + hexColor);
//noinspection ResultOfMethodCallIgnored
Color.fromRGB(Integer.decode("#" + hexColor));
final StringBuilder assembledColorCode = new StringBuilder();
assembledColorCode.append(ChatColor.COLOR_CHAR + "x");
for (final char curChar : hexColor.toCharArray()) {

View File

@ -19,7 +19,6 @@ import net.essentialsx.discord.JDADiscordService;
import okhttp3.OkHttpClient;
import org.bukkit.Bukkit;
import java.awt.Color;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@ -129,17 +128,17 @@ public final class DiscordUtil {
* @return The bukkit color code or blank string.
*/
public static String getRoleColorFormat(Member member) {
final Color color = member.getColor();
final int rawColor = member.getColorRaw();
if (color == null) {
if (rawColor == Role.DEFAULT_COLOR_RAW) {
return "";
}
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_1_R01)) {
// Essentials' FormatUtil allows us to not have to use bungee's chatcolor since bukkit's own one doesn't support rgb
return FormatUtil.replaceFormat("&#" + Integer.toHexString(color.getRGB()).substring(2));
return FormatUtil.replaceFormat("&#" + Integer.toHexString(rawColor).substring(2));
}
return FormatUtil.replaceFormat("&" + DownsampleUtil.nearestTo(color.getRGB()));
return FormatUtil.replaceFormat("&" + DownsampleUtil.nearestTo(rawColor));
}
/**