mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
Add support for named and legacy colors in color option
This commit is contained in:
1 parent
64f5598bf8
commit
b0a474c6ee
1 file changed
+24
-3
@@ -12,6 +12,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -340,10 +342,24 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.isOnline()) {
|
if (user.isOnline()) {
|
||||||
TextColor textColor = TextColor.fromHexString(PlaceholderAPI.setPlaceholders(user.asPlayer(), color));
|
color = PlaceholderAPI.setPlaceholders(user.asPlayer(), color);
|
||||||
|
}
|
||||||
|
|
||||||
if (textColor != null) {
|
for (NamedTextColor namedColor : NamedTextColor.values()) {
|
||||||
return textColor;
|
if (namedColor.toString().equalsIgnoreCase(color)) {
|
||||||
|
return namedColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color.startsWith("&")) {
|
||||||
|
LegacyFormat legacyFormat = LegacyComponentSerializer.parseChar(color.charAt(1));
|
||||||
|
|
||||||
|
if (legacyFormat != null) {
|
||||||
|
TextColor legacyColor = legacyFormat.color();
|
||||||
|
|
||||||
|
if (legacyColor != null) {
|
||||||
|
return legacyColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,6 +369,11 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return textColor;
|
return textColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (carbonChat.getConfig().getBoolean("show-tips")) {
|
||||||
|
carbonChat.getLogger().warning("Tip: Channel color found (" + color + ") is invalid!");
|
||||||
|
carbonChat.getLogger().warning("Falling back to #FFFFFF");
|
||||||
|
}
|
||||||
|
|
||||||
return NamedTextColor.WHITE;
|
return NamedTextColor.WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user