[FEAT] Paper Support
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// @excludeplugin
|
||||
package com.hypherionmc.craterlib.compat;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
|
@@ -9,7 +9,6 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
@@ -100,7 +99,15 @@ public class ChatUtils {
|
||||
|
||||
public static net.kyori.adventure.text.Component format(String value) {
|
||||
value = convertFormattingCodes(value);
|
||||
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
||||
|
||||
try {
|
||||
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
||||
} catch (Exception ignored) {
|
||||
// Mini message fails to format text that contain legacy formatting. Since we support both, that's bad.
|
||||
// We just ignore the exception here so that the whole format doesn't fail
|
||||
}
|
||||
|
||||
return net.kyori.adventure.text.Component.translatable(value);
|
||||
}
|
||||
|
||||
private static String convertFormattingCodes(String input) {
|
||||
|
@@ -10,6 +10,8 @@ import java.util.ServiceLoader;
|
||||
*/
|
||||
public class InternalServiceUtil {
|
||||
|
||||
public static ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
/**
|
||||
* Try to load a service
|
||||
*
|
||||
@@ -17,7 +19,7 @@ public class InternalServiceUtil {
|
||||
* @return The loaded class
|
||||
*/
|
||||
public static <T> T load(Class<T> clazz) {
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
final T loadedService = ServiceLoader.load(clazz, loader)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||
|
Reference in New Issue
Block a user