[FEAT/BUG] Adventure parser backport and added Compat API for Advanced Chat
This commit is contained in:
@@ -2,6 +2,7 @@ package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public interface CompatUtils {
|
||||
|
||||
@@ -12,5 +13,7 @@ public interface CompatUtils {
|
||||
boolean isPlayerBleeding(BridgedPlayer player);
|
||||
boolean playerBledOut(BridgedPlayer player);
|
||||
boolean playerRevived(BridgedPlayer player);
|
||||
boolean isPrivateMessage(BridgedPlayer player);
|
||||
Component getChannelPrefix(BridgedPlayer player);
|
||||
|
||||
}
|
||||
|
@@ -9,13 +9,27 @@ import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraft.world.level.GameRules.RULE_SENDCOMMANDFEEDBACK;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedCommandSourceStack {
|
||||
|
||||
private final CommandSourceStack internal;
|
||||
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
internal.sendSuccess(ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
if (!internal.getServer().getGameRules().getBoolean(RULE_SENDCOMMANDFEEDBACK)) {
|
||||
try {
|
||||
internal.getPlayerOrException().displayClientMessage(ChatUtils.adventureToMojang(supplier.get()), false);
|
||||
} catch (Exception ignored) {}
|
||||
} else {
|
||||
internal.sendSuccess(ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Component text) {
|
||||
try {
|
||||
internal.getPlayerOrException().displayClientMessage(ChatUtils.adventureToMojang(text), false);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public void sendFailure(Component text) {
|
||||
|
@@ -31,8 +31,12 @@ public class ChatUtils {
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||
final String serialised = Component.Serializer.toJson(inComponent);
|
||||
return adventureSerializer.deserialize(serialised);
|
||||
try {
|
||||
final String serialised = Component.Serializer.toJson(inComponent);
|
||||
return adventureSerializer.deserialize(serialised);
|
||||
} catch (Exception e) {
|
||||
return net.kyori.adventure.text.Component.text(inComponent.getString());
|
||||
}
|
||||
}
|
||||
|
||||
// Some text components contain duplicate text, resulting in duplicate messages
|
||||
|
Reference in New Issue
Block a user