mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Compilation fixes & color util
This commit is contained in:
1 parent
1ce21395dd
commit
16affaaa35
4 files changed
+55
-14
No files matched your search
@@ -315,13 +315,13 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
|
||||
return HoconConfigurationLoader.builder()
|
||||
.setDefaultOptions(opts -> {
|
||||
return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
|
||||
.defaultOptions(opts -> {
|
||||
return opts.shouldCopyDefaults(true).serializers(builder -> {
|
||||
builder.register(Key.class, KeySerializer.INSTANCE)
|
||||
.register(Sound.class, SoundSerializer.INSTANCE);
|
||||
});
|
||||
})
|
||||
.setFile(configFile)
|
||||
.file(configFile)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class CarbonUtils {
|
||||
static {
|
||||
final List<String> colorList = new ArrayList<>();
|
||||
|
||||
for (final NamedTextColor color : NamedTextColor.values()) {
|
||||
for (final NamedTextColor color : NamedTextColor.NAMES.values()) {
|
||||
colorList.add(color.toString());
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -54,10 +54,10 @@ public final class SoundSerializer implements TypeSerializer<Sound> {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Key name = value.getNode(NAME).getValue(KeySerializer.INSTANCE.type());
|
||||
final Sound.Source source = (Sound.Source) value.getNode(SOURCE).getValue(SOURCE_TYPE); // unsure about this
|
||||
final float volume = value.getNode(VOLUME).getFloat(1.0f);
|
||||
final float pitch = value.getNode(PITCH).getFloat(1.0f);
|
||||
final Key name = value.node(NAME).get(KeySerializer.INSTANCE.type());
|
||||
final Sound.Source source = (Sound.Source) value.node(SOURCE).get(SOURCE_TYPE); // unsure about this
|
||||
final float volume = value.node(VOLUME).getFloat(1.0f);
|
||||
final float pitch = value.node(PITCH).getFloat(1.0f);
|
||||
|
||||
if (name == null || source == null) {
|
||||
throw new ObjectMappingException("A name and source are required to deserialize a Sound");
|
||||
@@ -69,14 +69,14 @@ public final class SoundSerializer implements TypeSerializer<Sound> {
|
||||
@Override
|
||||
public void serialize(@NonNull final Type type, @Nullable final Sound obj, @NonNull final ConfigurationNode value) throws ObjectMappingException {
|
||||
if (obj == null) {
|
||||
value.setValue(null);
|
||||
value.set(null);
|
||||
return;
|
||||
}
|
||||
|
||||
value.getNode(NAME).setValue(KeySerializer.INSTANCE.type(), obj.name());
|
||||
value.getNode(SOURCE).setValue(SOURCE_TYPE, obj.source());
|
||||
value.getNode(VOLUME).setValue(obj.volume());
|
||||
value.getNode(PITCH).setValue(obj.pitch());
|
||||
value.node(NAME).set(KeySerializer.INSTANCE.type(), obj.name());
|
||||
value.node(SOURCE).set(SOURCE_TYPE, obj.source());
|
||||
value.node(VOLUME).set(obj.volume());
|
||||
value.node(PITCH).set(obj.pitch());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,9 +3,14 @@ package net.draycia.carbon.common.utils;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class ColorUtils {
|
||||
|
||||
private ColorUtils() {
|
||||
@@ -31,7 +36,7 @@ public final class ColorUtils {
|
||||
// }
|
||||
// }
|
||||
|
||||
for (final NamedTextColor namedColor : NamedTextColor.values()) {
|
||||
for (final NamedTextColor namedColor : NamedTextColor.NAMES.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
}
|
||||
@@ -46,4 +51,40 @@ public final class ColorUtils {
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
private static final @NonNull Pattern spigotLegacyRGB =
|
||||
Pattern.compile("[§&]x[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])");
|
||||
|
||||
private static final @NonNull Pattern pluginRGB =
|
||||
Pattern.compile("[§&]#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])");
|
||||
|
||||
@NonNull
|
||||
public static String translateAlternateColors(@NonNull final String input) {
|
||||
// TODO: check if MiniMessage or MineDown
|
||||
String output = input;
|
||||
|
||||
// Legacy RGB
|
||||
output = spigotLegacyRGB.matcher(output).replaceAll("<#$1$2$3$4$5$6>");
|
||||
|
||||
// Alternate RGB, TAB (neznamy) && KiteBoard
|
||||
output = pluginRGB.matcher(output).replaceAll("<#$1$2$3$4$5$6>");
|
||||
|
||||
// Legacy Colors
|
||||
for (final char c : "0123456789abcdef".toCharArray()) {
|
||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
||||
final TextColor color = format.color();
|
||||
|
||||
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
||||
}
|
||||
|
||||
// Legacy Formatting
|
||||
for (final char c : "klmno".toCharArray()) {
|
||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
||||
final TextDecoration decoration = format.decoration();
|
||||
|
||||
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user