[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
|
||||
|
@@ -5,6 +5,7 @@ import com.hypherionmc.craterlib.compat.Vanish;
|
||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class FabricCompatHelper implements CompatUtils {
|
||||
|
||||
@@ -35,4 +36,14 @@ public class FabricCompatHelper implements CompatUtils {
|
||||
public boolean playerRevived(BridgedPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateMessage(BridgedPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getChannelPrefix(BridgedPlayer player) {
|
||||
return Component.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.hypherionmc.craterlib.common;
|
||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import team.creative.playerrevive.api.IBleeding;
|
||||
import team.creative.playerrevive.server.PlayerReviveServer;
|
||||
import redstonedubstep.mods.vanishmod.VanishUtil;
|
||||
@@ -47,4 +48,14 @@ public class ForgeCompatHelper implements CompatUtils {
|
||||
IBleeding bleeding = PlayerReviveServer.getBleeding(player.toMojangServerPlayer());
|
||||
return bleeding != null && bleeding.revived();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateMessage(BridgedPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getChannelPrefix(BridgedPlayer player) {
|
||||
return Component.empty();
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
@@ -1,13 +1,8 @@
|
||||
**Bug Fixes**:
|
||||
|
||||
- Fixed LuckPerms breaking commands on Paper
|
||||
- Fix Config watcher using too many threads and not detecting changes on Linux systems
|
||||
- Fix Adventure Serializer failing completely when serialization fails, causing game glitches
|
||||
|
||||
**New Features**:
|
||||
|
||||
- Added Nojang API to allow mods to access GameRules (SDLink)
|
||||
- Exposed Adventure JSON serializer to mods
|
||||
|
||||
**Dev Changes**:
|
||||
|
||||
- Bumped MoonConfig - `1.0.10` -> `1.0.12`
|
||||
- Allow commands to send feedback as chat messages, if command feedback is disabled
|
||||
- Added Compat API for Advanced Chat
|
@@ -1,8 +1,8 @@
|
||||
#Project
|
||||
version_major=2
|
||||
version_minor=1
|
||||
version_patch=4
|
||||
version_build=2
|
||||
version_patch=5
|
||||
version_build=0
|
||||
|
||||
#Mod
|
||||
mod_author=HypherionSA
|
||||
@@ -29,6 +29,7 @@ discord_formatter=2.0.0
|
||||
cloth_config=6.5.102
|
||||
|
||||
# Mod Dependencies
|
||||
advanced_chat=SNA4dye5
|
||||
player_revive=5335413
|
||||
creative_core=5335387
|
||||
ftb_ranks=1802.1.11-build.71
|
||||
|
Reference in New Issue
Block a user