[FEAT/BUG] Adventure parser backport and added Compat API for Advanced Chat
This commit is contained in:
@@ -7,16 +7,29 @@
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -14,7 +15,7 @@
|
||||
private final CommandSourceStack internal;
|
||||
@@ -17,14 +18,18 @@
|
||||
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
- internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
+ internal.sendSuccess(ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
if (!internal.getServer().getGameRules().getBoolean(RULE_SENDCOMMANDFEEDBACK)) {
|
||||
- internal.sendSystemMessage(ChatUtils.adventureToMojang(supplier.get()));
|
||||
+ try {
|
||||
+ internal.getPlayerOrException().displayClientMessage(ChatUtils.adventureToMojang(supplier.get()), false);
|
||||
+ } catch (Exception ignored) {}
|
||||
} else {
|
||||
- internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
+ internal.sendSuccess(ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Component text) {
|
||||
- internal.sendSystemMessage(ChatUtils.adventureToMojang(text));
|
||||
+ try {
|
||||
+ internal.getPlayerOrException().displayClientMessage(ChatUtils.adventureToMojang(text), false);
|
||||
+ } catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public void sendFailure(Component text) {
|
||||
@@ -22,11 +23,22 @@
|
||||
@@ -32,11 +37,22 @@
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
|
@@ -8,7 +8,7 @@
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
import lombok.Getter;
|
||||
import me.hypherionmc.mcdiscordformatter.discord.DiscordSerializer;
|
||||
@@ -13,51 +11,36 @@
|
||||
@@ -13,55 +11,40 @@
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.Util;
|
||||
@@ -39,9 +39,13 @@
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||
- final String serialised = Component.Serializer.toJson(inComponent, getRegistryLookup());
|
||||
+ final String serialised = Component.Serializer.toJson(inComponent);
|
||||
return adventureSerializer.deserialize(serialised);
|
||||
try {
|
||||
- final String serialised = Component.Serializer.toJson(inComponent, getRegistryLookup());
|
||||
+ final String serialised = Component.Serializer.toJson(inComponent);
|
||||
return adventureSerializer.deserialize(serialised);
|
||||
} catch (Exception e) {
|
||||
return net.kyori.adventure.text.Component.text(inComponent.getString());
|
||||
}
|
||||
}
|
||||
|
||||
- private static HolderLookup.Provider getRegistryLookup() {
|
||||
@@ -66,7 +70,7 @@
|
||||
}
|
||||
|
||||
public static String strip(String inString, String... toStrip) {
|
||||
@@ -86,7 +69,7 @@
|
||||
@@ -90,7 +73,7 @@
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component resolve(String component, boolean formatted) {
|
||||
@@ -75,7 +79,7 @@
|
||||
if (formatted) {
|
||||
returnVal = MinecraftSerializer.INSTANCE.serialize(component);
|
||||
}
|
||||
@@ -114,7 +97,7 @@
|
||||
@@ -118,7 +101,7 @@
|
||||
if (identifier == null)
|
||||
return net.kyori.adventure.text.Component.text("Unknown");
|
||||
|
||||
|
Reference in New Issue
Block a user