[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;
|
||||
@@ -13,4 +14,4 @@ public class FTBEssentials {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -12,7 +12,9 @@ import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.Util;
|
||||
// @noplugin
|
||||
import net.minecraft.client.Minecraft;
|
||||
// #noplugin
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -37,8 +39,10 @@ public class ChatUtils {
|
||||
}
|
||||
|
||||
private static HolderLookup.Provider getRegistryLookup() {
|
||||
// @noplugin
|
||||
if (ModloaderEnvironment.INSTANCE.getEnvironment().isClient() && Minecraft.getInstance().level != null)
|
||||
return Minecraft.getInstance().level.registryAccess();
|
||||
// #noplugin
|
||||
|
||||
if (ModloaderEnvironment.INSTANCE.getEnvironment().isServer() && CommonPlatform.INSTANCE.getMCServer() != null)
|
||||
return CommonPlatform.INSTANCE.getMCServer().toMojang().registryAccess();
|
||||
@@ -113,7 +117,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