[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);
|
||||
|
||||
}
|
||||
|
@@ -8,13 +8,23 @@ 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)) {
|
||||
internal.sendSystemMessage(ChatUtils.adventureToMojang(supplier.get()));
|
||||
} else {
|
||||
internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Component text) {
|
||||
internal.sendSystemMessage(ChatUtils.adventureToMojang(text));
|
||||
}
|
||||
|
||||
public void sendFailure(Component text) {
|
||||
|
@@ -36,8 +36,12 @@ public class ChatUtils {
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||
final String serialised = Component.Serializer.toJson(inComponent, getRegistryLookup());
|
||||
return adventureSerializer.deserialize(serialised);
|
||||
try {
|
||||
final String serialised = Component.Serializer.toJson(inComponent, getRegistryLookup());
|
||||
return adventureSerializer.deserialize(serialised);
|
||||
} catch (Exception e) {
|
||||
return net.kyori.adventure.text.Component.text(inComponent.getString());
|
||||
}
|
||||
}
|
||||
|
||||
private static HolderLookup.Provider getRegistryLookup() {
|
||||
|
@@ -15,6 +15,7 @@ dependencies {
|
||||
modImplementation("me.shedaniel.cloth:cloth-config-fabric:${cloth_config}")
|
||||
modImplementation "maven.modrinth:fabrictailor:${fabrictailor}"
|
||||
modImplementation "maven.modrinth:vanish:${vanish}"
|
||||
modImplementation("unimaven.modrinth:advanced-chat:${advanced_chat}")
|
||||
|
||||
// Do not edit or remove
|
||||
implementation project(":Common")
|
||||
|
@@ -5,6 +5,8 @@ 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 me.wesley1808.advancedchat.api.AdvancedChatAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class FabricCompatHelper implements CompatUtils {
|
||||
|
||||
@@ -35,4 +37,15 @@ public class FabricCompatHelper implements CompatUtils {
|
||||
public boolean playerRevived(BridgedPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateMessage(BridgedPlayer player) {
|
||||
return !AdvancedChatAPI.isPublicChat(player.toMojangServerPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getChannelPrefix(BridgedPlayer player) {
|
||||
net.minecraft.network.chat.Component c = AdvancedChatAPI.getChannelPrefix(player.toMojangServerPlayer());
|
||||
return c.getString().isBlank() ? Component.empty() : Component.text(c.getString());
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
@@ -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 redstonedubstep.mods.vanishmod.VanishUtil;
|
||||
import team.creative.playerrevive.api.IBleeding;
|
||||
import team.creative.playerrevive.server.PlayerReviveServer;
|
||||
@@ -47,4 +48,14 @@ public class NeoForgeCompatHelper 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();
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
@@ -89,4 +90,14 @@ public class PaperCompatHelper 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();
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -39,6 +39,7 @@ vanishmod=1.1.12.1
|
||||
vanishmod_neo=puxrKAMr
|
||||
ftb_essentials=2101.1.0
|
||||
ftb_ranks=2101.1.1
|
||||
advanced_chat=5ddOPqgR
|
||||
player_revive=6130248
|
||||
creative_core=6109912
|
||||
|
||||
|
Reference in New Issue
Block a user