[FEAT] Paper Support

This commit is contained in:
2024-10-22 20:13:32 +02:00
parent 86149ace11
commit e0e37685e2
352 changed files with 5772 additions and 1588 deletions

View File

@@ -14,8 +14,14 @@ public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player;
private final DamageSource damageSource;
private Component deathMessage;
public CraterPlayerDeathEvent(BridgedPlayer player, DamageSource source, Component deathMessage) {
this(player, source);
this.deathMessage = deathMessage;
}
public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
return deathMessage != null ? deathMessage : ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
}
}

View File

@@ -1,3 +1,4 @@
// @excludeplugin
package com.hypherionmc.craterlib.compat;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;

View File

@@ -12,6 +12,7 @@ import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
@@ -97,7 +98,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) {

View File

@@ -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);