mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
fix deprecation warning in DSRV integration
This commit is contained in:
2 files changed
+18
-10
No files matched your search
@@ -23,7 +23,6 @@ import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
public final class ChannelUtils {
|
||||
|
||||
@@ -31,14 +30,13 @@ public final class ChannelUtils {
|
||||
|
||||
}
|
||||
|
||||
public static void broadcastMessageToChannel(final String mmFormattedMessage, final ChatChannel channel) {
|
||||
final Component originalMessage = MiniMessage.miniMessage().deserialize(mmFormattedMessage);
|
||||
public static void broadcastMessageToChannel(final Component msg, final ChatChannel channel) {
|
||||
|
||||
// TODO: Emit events
|
||||
|
||||
for (final CarbonPlayer recipient : CarbonChatProvider.carbonChat().server().players()) {
|
||||
if (channel.hearingPermitted(recipient).permitted()) {
|
||||
recipient.sendMessage(originalMessage);
|
||||
recipient.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import github.scarsz.discordsrv.Debug;
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import github.scarsz.discordsrv.api.Subscribe;
|
||||
import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent;
|
||||
import github.scarsz.discordsrv.dependencies.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import github.scarsz.discordsrv.hooks.chat.ChatHook;
|
||||
import java.time.Duration;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -39,6 +38,7 @@ import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||
import net.draycia.carbon.common.util.ChannelUtils;
|
||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -95,10 +95,9 @@ public final class DSRVChatHook implements ChatHook {
|
||||
DiscordSRV.debug(Debug.MINECRAFT_TO_DISCORD, "Received a CarbonChatEvent (player: " + carbonPlayer.username() + ")");
|
||||
|
||||
final @Nullable Player player = ((CarbonPlayerPaper) carbonPlayer).bukkitPlayer();
|
||||
final String message = PlainTextComponentSerializer.plainText().serialize(eventMessage);
|
||||
|
||||
if (player != null) {
|
||||
DiscordSRV.getPlugin().processChatMessage(player, message, chatChannel.commandName(), event.cancelled());
|
||||
DiscordSRV.getPlugin().processChatMessage(player, toDsrv(eventMessage), chatChannel.commandName(), event.cancelled(), null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -116,13 +115,12 @@ public final class DSRVChatHook implements ChatHook {
|
||||
|
||||
@Override
|
||||
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
|
||||
final String mmFormattedMessage = MiniMessage.miniMessage().serialize(message);
|
||||
final ChatChannel chatChannel = this.channelRegistry.channelByValue(channel);
|
||||
final @Nullable ChatChannel chatChannel = this.channelRegistry.channelByValue(channel);
|
||||
|
||||
if (chatChannel == null) {
|
||||
this.plugin.getLogger().warning("Error sending message from Discord to Minecraft, no matching channel found for [" + channel + "]");
|
||||
} else {
|
||||
ChannelUtils.broadcastMessageToChannel(mmFormattedMessage, chatChannel);
|
||||
ChannelUtils.broadcastMessageToChannel(fromDsrv(message), chatChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,4 +129,16 @@ public final class DSRVChatHook implements ChatHook {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
private static github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component toDsrv(final Component component) {
|
||||
return github.scarsz.discordsrv.dependencies.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(
|
||||
GsonComponentSerializer.gson().serialize(component)
|
||||
);
|
||||
}
|
||||
|
||||
private static Component fromDsrv(final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component component) {
|
||||
return GsonComponentSerializer.gson().deserialize(
|
||||
github.scarsz.discordsrv.dependencies.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(component)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user