Compare commits

..

2 Commits

2 changed files with 39 additions and 30 deletions

View File

@ -1,65 +1,69 @@
package fr.pandacube.lib.paper.util; package fr.pandacube.lib.paper.util;
import org.bukkit.DyeColor;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.md_5.bungee.api.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
/**
* Utility class around chat coloring.
*/
public class BukkitChatColorUtil { public class BukkitChatColorUtil {
/** /**
* Returns the {@link ChatColor} that is visually the closest from the provided {@link DyeColor} when used on a sign. * Returns the {@link TextColor} that is visually the closest from the provided {@link DyeColor} when used on a sign.
*
* Multiple {@link DyeColor} may return the same
* @param dye the provided dye color * @param dye the provided dye color
* @return the closest chat color from {@code dye} * @return the closest chat color from {@code dye}
*/ */
public static ChatColor fromDyeToSignColor(DyeColor dye) { public static TextColor fromDyeToSignColor(DyeColor dye) {
//org.bukkit.Color col = dye.getColor(); //org.bukkit.Color col = dye.getColor();
//return ChatColor.of(new Color(col.asRGB())); //return ChatColor.of(new Color(col.asRGB()));
// hmmm this is not that simple, of course // hmmm this is not that simple, of course
// black // black
return switch (dye) { return switch (dye) {
case BLACK -> ChatColor.of("#000000"); case BLACK -> TextColor.fromHexString("#000000");
case RED -> ChatColor.of("#650000"); case RED -> TextColor.fromHexString("#650000");
case GREEN -> ChatColor.of("#006500"); case GREEN -> TextColor.fromHexString("#006500");
case BROWN -> ChatColor.of("#361B07"); case BROWN -> TextColor.fromHexString("#361B07");
case BLUE -> ChatColor.of("#000065"); case BLUE -> TextColor.fromHexString("#000065");
case PURPLE -> ChatColor.of("#3F0C5F"); case PURPLE -> TextColor.fromHexString("#3F0C5F");
case CYAN -> ChatColor.of("#006565"); case CYAN -> TextColor.fromHexString("#006565");
case LIGHT_GRAY -> ChatColor.of("#535353"); case LIGHT_GRAY -> TextColor.fromHexString("#535353");
case GRAY -> ChatColor.of("#323232"); case GRAY -> TextColor.fromHexString("#323232");
case PINK -> ChatColor.of("#652947"); case PINK -> TextColor.fromHexString("#652947");
case LIME -> ChatColor.of("#4B6500"); case LIME -> TextColor.fromHexString("#4B6500");
case YELLOW -> ChatColor.of("#656500"); case YELLOW -> TextColor.fromHexString("#656500");
case LIGHT_BLUE -> ChatColor.of("#3C4B51"); case LIGHT_BLUE -> TextColor.fromHexString("#3C4B51");
case MAGENTA -> ChatColor.of("#650065"); case MAGENTA -> TextColor.fromHexString("#650065");
case ORANGE -> ChatColor.of("#65280C"); case ORANGE -> TextColor.fromHexString("#65280C");
case WHITE -> ChatColor.of("#656565"); case WHITE -> TextColor.fromHexString("#656565");
}; };
} }
public static org.bukkit.ChatColor toBukkit(ChatColor color) { public static ChatColor toBukkit(net.md_5.bungee.api.ChatColor color) {
return org.bukkit.ChatColor.valueOf(color.getName().toUpperCase()); return ChatColor.valueOf(color.getName().toUpperCase());
} }
public static org.bukkit.ChatColor toBukkit(TextColor color) { public static ChatColor toBukkit(TextColor color) {
return toBukkit(NamedTextColor.nearestTo(color)); return toBukkit(NamedTextColor.nearestTo(color));
} }
public static org.bukkit.ChatColor toBukkit(NamedTextColor color) { public static ChatColor toBukkit(NamedTextColor color) {
return org.bukkit.ChatColor.valueOf(color.toString().toUpperCase()); return ChatColor.valueOf(color.toString().toUpperCase());
} }
public static NamedTextColor toAdventure(org.bukkit.ChatColor color) { public static NamedTextColor toAdventure(ChatColor color) {
return NamedTextColor.NAMES.value(color.name().toLowerCase()); return NamedTextColor.NAMES.value(color.name().toLowerCase());
} }
public static NamedTextColor toAdventure(net.md_5.bungee.api.ChatColor color) {
return NamedTextColor.NAMES.value(color.getName());
}
} }

View File

@ -106,6 +106,11 @@ public abstract class AbstractClientWS implements AbstractWS {
private void reconnectIfNecessary() { private void reconnectIfNecessary() {
synchronized (socket) { synchronized (socket) {
if (autoReconnect && !isConnecting && socket.get() == null) { if (autoReconnect && !isConnecting && socket.get() == null) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
connect(); connect();
} }
} }