Change Chatty & LunaChat send logic to Components

This commit is contained in:
Vankka 2023-07-15 14:32:37 +03:00
parent 74d661d523
commit 26c472d0b8
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
2 changed files with 11 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.logging.NamedLogger;
import com.discordsrv.common.module.type.PluginIntegration;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
@ -129,7 +130,10 @@ public class ChattyChatIntegration extends PluginIntegration<BukkitDiscordSRV> i
@Override
public void sendMessage(@NotNull MinecraftComponent component) {
chat.sendMessage(BukkitComponentSerializer.legacy().serialize(ComponentUtil.fromAPI(component)));
Component comp = ComponentUtil.fromAPI(component);
for (Player recipient : chat.getRecipients(null)) {
discordSRV.playerProvider().player(recipient).sendMessage(comp);
}
}
}
}

View File

@ -34,6 +34,8 @@ import com.github.ucchyocean.lc3.channel.Channel;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.member.ChannelMemberPlayer;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
@ -145,8 +147,10 @@ public class LunaChatIntegration extends PluginIntegration<BukkitDiscordSRV> imp
@Override
public void sendMessage(@NotNull MinecraftComponent component) {
String message = BukkitComponentSerializer.legacy().serialize(ComponentUtil.fromAPI(component));
channel.chatFromOtherSource("Discord", null, message);
BaseComponent[] baseComponent = BungeeComponentSerializer.get().serialize(ComponentUtil.fromAPI(component));
for (ChannelMember member : channel.getMembers()) {
member.sendMessage(baseComponent);
}
}
}