channels: global: format: "&7[Global] &f%player%: %message%" discord-channel-id: "000000000000000000" # Put your real ID here staff: format: "&4[Staff] &c%player%: %message%" discord-channel-id: "111111111111111111" trade: format: "&6[Trade] &e%player%: %message%" discord-channel-id: "" # Empty means it uses global bridge
My request is that I want the InteractiveDiscordSRV to make my message of [item], [ender], [inv] and others visible in the different channel, not just in global channel.
I also want that If I am in another channel and message there, my message should also not be seen in global since I am already in another channel.
๐5 files
17,937 chars
๐
pasted-code-1776610171094.txt
txt69 lines
โถ
package org.kingcueio.manticore;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.kingcueio.manticore.api.DiscordBridge;
import org.kingcueio.manticore.commands.ManticCommand;
import org.kingcueio.manticore.listeners.ChatListener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Getter
public class Manticore extends JavaPlugin {
private final Map playerChannels = new HashMap<>();
private DiscordBridge discordBridge;
@Override
public void onEnable() {
this.saveDefaultConfig();
this.discordBridge = new DiscordBridge(this);
// Register the listener regardless of other plugins
// This ensures Manticore ALWAYS handles Minecraft-to-Minecraft channel filtering
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
if (Bukkit.getPluginManager().getPlugin("InteractiveChatDiscordSrvAddon") != null) {
this.getLogger().info("ICDSA detected - Manticore will handle game channels, ICDSA handles Discord formatting.");
}
ManticCommand manticCommand = new ManticCommand(this);
getCommand("mantic").setExecutor(manticCommand);
getCommand("mantic").setTabCompleter(manticCommand);
for (Player player : Bukkit.getOnlinePlayers()) {
playerChannels.put(player.getUniqueId(), "global");
}
getLogger().info("Manticore v1.2 enabled!");
}
@Override
public void onDisable() {
if (discordBridge != null) {
discordBridge.shutdown();
}
getLogger().info("Manticore disabled!");
}
public String getPlayerChannel(UUID uuid) {
return playerChannels.getOrDefault(uuid, "global");
}
public void setPlayerChannel(UUID uuid, String channel) {
playerChannels.put(uuid, channel);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
// Ensure every new player is explicitly put into the global channel
if (!this.playerChannels.containsKey(event.getPlayer().getUniqueId())) {
this.playerChannels.put(event.getPlayer().getUniqueId(), "global");
}
}
}
๐
pasted-code-1776610174775.txt
txt70 lines
โถ
package org.kingcueio.manticore.listeners;
import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.kingcueio.manticore.Manticore;
import org.jetbrains.annotations.NotNull;
public class ChatListener implements Listener {
private final Manticore plugin;
public ChatListener(Manticore plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChat(AsyncChatEvent event) {
Player player = event.getPlayer();
final String channelName = this.plugin.getPlayerChannel(player.getUniqueId()).toLowerCase();
// 1. Minecraft Appearance
String format = this.plugin.getConfig().getString("channels." + channelName + ".format", "&7[%channel%] &f%player%: %message%");
event.renderer((source, sourceDisplayName, message, viewer) -> {
String plainMsg = PlainTextComponentSerializer.plainText().serialize(message);
String formatted = format
.replace("%player%", source.getName())
.replace("%message%", plainMsg)
.replace("%channel%", channelName);
return LegacyComponentSerializer.legacyAmpersand().deserialize(formatted);
});
// 2. Who sees the message (The Filter)
// We must ensure that viewers only include people in the same channel
event.viewers().removeIf(audience -> {
if (audience instanceof Player recipient) {
return !this.plugin.getPlayerChannel(recipient.getUniqueId()).equalsIgnoreCase(channelName);
}
return false;
});
// 3. Discord Coordination
// If ICDSA is present, it will try to send the message to DiscordSRV's main channel.
// If you are in "trade" and ICDSA is active, we need to STOP ICDSA from sending to Global
// and manually send to Trade.
if (Bukkit.getPluginManager().getPlugin("InteractiveChatDiscordSrvAddon") != null) {
// If not in global, we usually want to cancel the event for ICDSA
// so it doesn't post to the main Discord channel.
if (!channelName.equals("global")) {
// Optional: If you want ICDSA to ignore this, some versions require
// the event to be cancelled, but that stops MC chat too.
// Instead, we manually bridge for non-global channels:
this.plugin.getDiscordBridge().sendToDiscord(channelName, player, PlainTextComponentSerializer.plainText().serialize(event.message()));
}
} else {
// No ICDSA - standard bridge logic
String rawMessage = PlainTextComponentSerializer.plainText().serialize(event.message());
this.plugin.getDiscordBridge().sendToDiscord(channelName, player, rawMessage);
}
}
}
๐
pasted-code-1776610177996.txt
txt78 lines
โถ
package org.kingcueio.manticore.commands;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kingcueio.manticore.Manticore;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ManticCommand implements CommandExecutor, TabCompleter {
private final Manticore plugin;
public ManticCommand(Manticore plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
if (args.length == 2 && args[0].equalsIgnoreCase("join")) {
String targetChannel = args[1].toLowerCase();
if (plugin.getConfig().contains("channels." + targetChannel)) {
plugin.setPlayerChannel(player.getUniqueId(), targetChannel);
player.sendMessage(Component.text("Joined channel: " + targetChannel, NamedTextColor.GREEN));
} else {
player.sendMessage(Component.text("Channel not found!", NamedTextColor.RED));
}
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("manticore.admin")) {
sender.sendMessage(Component.text("No permission!", NamedTextColor.RED));
return true;
}
plugin.reloadConfig();
sender.sendMessage(Component.text("Manticore configuration reloaded!", NamedTextColor.GREEN));
return true;
}
sender.sendMessage(Component.text("Manticore v1.2 by KingCueio", NamedTextColor.AQUA));
return true;
}
@Override
public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
List completions = new ArrayList<>();
if (args.length == 1) {
completions.add("join");
if (sender.hasPermission("manticore.admin")) {
completions.add("reload");
}
} else if (args.length == 2 && args[0].equalsIgnoreCase("join")) {
var channelSection = plugin.getConfig().getConfigurationSection("channels");
if (channelSection != null) {
completions.addAll(channelSection.getKeys(false));
}
}
String lastArg = args[args.length - 1].toLowerCase();
return completions.stream()
.filter(s -> s.toLowerCase().startsWith(lastArg))
.collect(Collectors.toList());
}
}
๐
pasted-code-1776610180819.txt
txt112 lines
โถ
package org.kingcueio.manticore.api;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.api.Subscribe;
import github.scarsz.discordsrv.api.events.DiscordGuildMessageReceivedEvent;
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import github.scarsz.discordsrv.util.DiscordUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.kingcueio.manticore.Manticore;
public class DiscordBridge {
private final Manticore plugin;
public DiscordBridge(Manticore plugin) {
this.plugin = plugin;
DiscordSRV.api.subscribe(this);
}
public void sendToDiscord(String channelName, Player player, String rawMessage) {
// If it's global and ICDSA is active, let ICDSA/DiscordSRV handle it.
if (channelName.equalsIgnoreCase("global") && Bukkit.getPluginManager().getPlugin("InteractiveChatDiscordSrvAddon") != null) {
return;
}
String path = "channels." + channelName.toLowerCase() + ".discord-channel-id";
String channelId = this.plugin.getConfig().getString(path);
TextChannel channel = null;
if (channelId != null && !channelId.isEmpty()) {
try {
channel = DiscordSRV.getPlugin().getJda().getTextChannelById(channelId);
} catch (Exception e) {
this.plugin.getLogger().warning("Could not find Discord channel ID: " + channelId + " for channel: " + channelName);
}
}
// Fallback to Main Channel if no ID is found or ID is invalid
if (channel == null) {
channel = DiscordSRV.getPlugin().getMainTextChannel();
}
if (channel != null) {
// Format: [Staff] PlayerName: Message
String channelLabel = channelName.substring(0, 1).toUpperCase() + channelName.substring(1);
String formatted = String.format("**[%s] %s**: %s", channelLabel, player.getName(), rawMessage);
DiscordUtil.sendMessage(channel, formatted);
}
}
public void sendSystemMessage(String message) {
TextChannel channel = DiscordSRV.getPlugin().getMainTextChannel();
if (channel != null) {
DiscordUtil.sendMessage(channel, message);
}
}
@Subscribe
public void onDiscordMessage(DiscordGuildMessageReceivedEvent event) {
if (event.getAuthor().isBot()) return;
String discordChannelId = event.getChannel().getId();
String targetMcChannel = null;
// 1. Find which MC channel this Discord ID belongs to
var channelSection = plugin.getConfig().getConfigurationSection("channels");
if (channelSection != null) {
for (String key : channelSection.getKeys(false)) {
if (discordChannelId.equals(channelSection.getString(key + ".discord-channel-id"))) {
targetMcChannel = key;
break;
}
}
}
// 2. Fallback to global if it's the main channel
boolean isMainChannel = event.getChannel().equals(DiscordSRV.getPlugin().getMainTextChannel());
if (targetMcChannel == null && isMainChannel) {
targetMcChannel = "global";
}
if (targetMcChannel == null) return; // Not a managed channel
// 3. Get Format
String format = plugin.getConfig().getString("channels." + targetMcChannel + ".format",
plugin.getConfig().getString("discord-to-mc-format", "&9[D] &f%name%&7: &f%message%"));
String author = event.getMember().getEffectiveName();
String content = event.getMessage().getContentDisplay();
String rawMsg = format.replace("%name%", author).replace("%message%", content);
Component mcComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(rawMsg);
// 4. Send to the right players
for (Player recipient : Bukkit.getOnlinePlayers()) {
String playerChan = plugin.getPlayerChannel(recipient.getUniqueId());
// Logical OR: Send if player is in that specific channel OR if it's a global announcement
if (playerChan.equalsIgnoreCase(targetMcChannel) || targetMcChannel.equalsIgnoreCase("global")) {
recipient.sendMessage(mcComponent);
}
}
Bukkit.getConsoleSender().sendMessage(mcComponent);
}
public void shutdown() {
DiscordSRV.api.unsubscribe(this);
}
}
Iโll help you fix the InteractiveChat Discord integration so that [item], [ender], [inv] etc. work in all channels and messages go to the correct Discord channels.
Manticore
Multi-channel chat system with Discord integration via DiscordSRV and InteractiveChatDiscordSrvAddon. Players can join separate channels (global, staff, trade, etc.) with isolated chat visibility. Features full InteractiveChat component support ([item], [inv], [ender]) in all channels, channel-based Discord routing, and automatic Discord-to-Minecraft message distribution. Includes admin commands for configuration management.
The issue is that your current code manually bridges non-global channels to Discord, which bypasses InteractiveChatDiscordSrvAddonโs processing. ICDSA never gets to convert [item] tags into Discord embeds for non-global channels.
I need to read your files first to create a proper solution:
Since this is a new project, Iโll create the complete structure with the fixes for InteractiveChat Discord integration:
Solution:
Let ICDSA process ALL messages (donโt bypass it for non-global channels)
Use DiscordSRVโs event API to route messages to correct Discord channels
Prevent duplicate messages in global Discord channel when user is in another channel
Routes messages to correct Discord channel based on Manticore channel
Uses event.setChannel(discordChannelId) to tell DiscordSRV which Discord channel to use
Prevents non-global messages from appearing in global Discord channel
ICDSA now processes [item], [ender], [inv] for ALL channels
ChatListener.java - Simplified to only handle manual bridging when ICDSA is NOT present
Manticore.java - Added icdsaPresent flag and getter for cleaner detection
config.yml - Added debug option and updated Discord channel IDs for all channels
How it works:
When a player sends a message with [item] in the trade channel, ICDSA processes it and creates the Discord embed
The GameChatMessagePreProcessEvent intercepts and routes it to the trade Discord channel instead of global
Minecraft viewers are still filtered by channel (existing behavior)
Discord messages from specific channels only go to players in that Minecraft channel
Configuration:
Replace the placeholder Discord channel IDs in config.yml with your actual Discord channel IDs from Discord (right-click channel โ Copy ID).
Whenever I chat in the minecraft chat now, It doesn't send any in the discord
KodariApr 19 at 3:05 pm 4,159 (v2)
Iโll examine the project files to diagnose why Minecraft chat messages arenโt being sent to Discord.
I found the issue! The problem is in the ChatListener.java - it only sends to Discord when InteractiveChatDiscordSrvAddon is NOT present:
Java
if (this.plugin.getDiscordBridge() != null && !this.plugin.isIcdsaPresent()) {
// Only sends when ICDSA is absent
}
When ICDSA is present, it relies on the GameChatMessagePreProcessEvent to handle Discord sending, but that event might not be firing properly. This creates a situation where messages donโt get sent to Discord at all.
The fix: Remove the ICDSA check and always send to Discord manually. The ICDSA integration can enhance the experience (with item previews), but shouldnโt block basic functionality.
The chat messages will now always be sent to Discord regardless of whether InteractiveChatDiscordSrvAddon is installed. If ICDSA is present, it can still enhance the messages with item previews through the GameChatMessagePreProcessEvent, but basic chat relay will work even without it.
Now, the problem is that the when I use [item] or [inv] or [ender] or other
I get this in discord: <chat=0ea1542b-478a-37e2-a0b4-79f9261438a2:[i]:>
You should let the InteractiveChatDiscordSRVAddon do the processing, but it should go through channel when you are currently in that channel only
KodariApr 19 at 3:11 pm 4,391 (v2)
I need to examine the channel system and ICDSA integration to understand how to properly route messages.
Now I understand the issue! The problem is:
Current behavior: ChatListener always calls sendToDiscord() with plain text, bypassing ICDSAโs processing
What happens: ICDSA creates placeholders like <chat=UUID:[i]:> but they never get converted because the message doesnโt go through ICDSAโs flow
What should happen: When ICDSA is present AND the player is in a channel with Discord integration, let ICDSA handle it through GameChatMessagePreProcessEvent (which processes [item] tags properly)
Now the flow works correctly:
With ICDSA + configured Discord channel: The message goes through ICDSAโs GameChatMessagePreProcessEvent, which processes [item]/[inv]/[ender] tags and converts them to Discord embeds
Without ICDSA or no Discord channel: Falls back to manual sending with plain text
This way [item] tags will display properly as Discord embeds instead of raw UUID placeholders!
Now, whenever I chat in minecraft chat again, it doesn't send any in the discord. Fix it while not disturbing the last fixed changes for the InteractiveChatDiscordSRVAddon
KodariApr 19 at 3:21 pm 24,044 (v2)
I need to examine the current state of ChatListener to fix this properly.
I need to check the DiscordBridge API and understand the full flow:
Now I understand the issue! The problem is in DiscordBridge - itโs cancelling DiscordSRVโs event and manually sending messages, which bypasses ICDSAโs [item] processing. Also, ChatListener isnโt sending at all when ICDSA is present.
The fix:
DiscordBridge: Just route the channel using setChannel(), donโt cancel and manually send (let DiscordSRV + ICDSA handle it naturally)
ChatListener: Only rely on DiscordSRV when the channel has Discord integration configured, otherwise fallback to manual send
Fixed! Now:
Messages from all channels are sent to Discord (no more missing messages)
When a channel has Discord integration configured, DiscordSRV handles sending (with ICDSA enhancement if present)
ICDSAโs [item], [inv], [ender] tags will work properly in Discord (as embeds instead of raw UUID placeholders)
Channels without Discord integration fall back to manual sending to DiscordSRVโs main channel
Now I really can't see any message from minecraft chat from any channels
KodariApr 19 at 3:26 pm 8,671 (v2)
I need to check the current state of all the files to diagnose why no messages are being sent:
I see the problem! The code is relying on DiscordSRVโs GameChatMessagePreProcessEvent to automatically fire for channels with configured Discord IDs, but DiscordSRV might not be processing Paperโs AsyncChatEvent at all (it likely only listens to the legacy AsyncPlayerChatEvent).
The fix is simple: Always manually send to Discord. The sendToDiscord() method already handles routing to the correct Discord channel based on config.
Fixed! All Minecraft chat messages will now be sent to Discord:
Messages route to the correct Discord channel based on discord-channel-id in config
Falls back to DiscordSRVโs main channel if no specific channel is configured (ID is โ000000000000000000โ)
Works reliably without depending on DiscordSRVโs automatic chat processing
Note: InteractiveChatโs [item]/[inv]/[ender] tags will appear as plain text (not fancy embeds) because weโre manually sending instead of using ICDSAโs processing. This is the tradeoff for reliable message delivery.
now it goes back for being <chat=0ea1542b-478a-37e2-a0b4-79f9261438a2:[i]:> in the discord channels
KodariApr 19 at 3:30 pm 6,508 (v2)
I see the issue now. When we manually send messages to Discord, InteractiveChat has already converted [item] tags into placeholder codes like <chat=UUID:[i]:>. These placeholders are meant to be processed by ICDSA, but since weโre bypassing that flow, they appear raw in Discord.
The solution: Strip InteractiveChat placeholders before manually sending to Discord, since ICDSA wonโt process them in our custom channel flow.
Fixed! Now InteractiveChat placeholders like <chat=UUID:[i]:> are stripped and replaced with [item] before sending to Discord. Messages will show cleanly in Discord without the raw placeholder codes.
Note: This wonโt show fancy item embeds in Discord (thatโs what ICDSA would provide), but it will show clean [item] text instead of confusing UUID codes.
Let InteractiveChatDiscordSRVAddon handle the [item] through discord channel since they are the only one who can message them
KodariApr 19 at 3:34 pm 8,417 (v2)
I understand now! We need to let DiscordSRVโs event flow happen naturally so that ICDSA can intercept and process the [item] tags. The fix:
DiscordBridge: Call processChatMessage() to trigger DiscordSRVโs event system
Event handler: Just route to the correct channel, but DONโT cancel the event
Let ICDSA do its magic: The message flows through DiscordSRV โ ICDSA processes [item] โ sends to Discord
Fixed! Now the flow works properly:
ChatListener captures the chat and calls sendToDiscord()
DiscordBridge.sendToDiscord() triggers DiscordSRVโs chat processing with processChatMessage()
DiscordSRV fires GameChatMessagePreProcessEvent
Our event handler routes the message to the correct Discord channel based on the playerโs current Minecraft channel
ICDSA intercepts the event and processes [item], [inv], [ender] tags into Discord embeds
DiscordSRV sends the message to Discord with ICDSAโs enhancements
The [item] tags will now show as proper Discord embeds with item previews instead of raw placeholder codes!
and now the minecraft chats are not going through discord channel again
KodariApr 19 at 3:38 pm 9,211 (v2)
I need to check the current state of the files to diagnose the issue:
I see the issue! When we call processChatMessage() with "global" as the channel parameter, DiscordSRV might not be sending anything because it doesnโt recognize the channel or has other conditions. Let me check if we need to add a fallback:
Let me try a different approach. The issue is that processChatMessage() isnโt actually sending messages. Let me use a hybrid approach that triggers ICDSA processing but also ensures messages get sent:
Fixed! Now the flow works like this:
Fire the event first: GameChatMessagePreProcessEvent is called so ICDSA can intercept and process [item] tags
Get the modified message: After ICDSA processes it, we get the enhanced message from the event
Send to Discord: Use DiscordUtil.sendMessage() to send to the correct channel
ICDSAโs processing works: Because we fired the event that ICDSA listens to, [item] tags get converted to Discord embeds
Messages will now appear in Discord with proper ICDSA support for [item], [inv], and [ender] tags!
[23:40:51 ERROR]: Could not pass event AsyncChatEvent to Manticore v1.4.0-SNAPSHOT java.lang.NullPointerException: Cannot invoke "org.bukkit.configuration.file.FileConfiguration.getString(String)" because the return value of "github.scarsz.discordsrv.DiscordSRV.getConfig()" is null at Manticore-1.4.0-SNAPSHOT.jar/org.kingcueio.manticore.api.DiscordBridge.sendToDiscord(DiscordBridge.java:70) ~[Manticore-1.4.0-SNAPSHOT.jar:?] at Manticore-1.4.0-SNAPSHOT.jar/org.kingcueio.manticore.listeners.ChatListener.onChat(ChatListener.java:44) ~[Manticore-1.4.0-SNAPSHOT.jar:?] at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.21.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.21.4-R0.1-SNAPSHOT.jar:?] at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:54) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:131) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:628) ~[paper-api-1.21.4-R0.1-SNAPSHOT.jar:?] at io.papermc.paper.adventure.ChatProcessor.post(ChatProcessor.java:378) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at io.papermc.paper.adventure.ChatProcessor.processModern(ChatProcessor.java:151) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at io.papermc.paper.adventure.ChatProcessor.process(ChatProcessor.java:106) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at net.minecraft.server.network.ServerGamePacketListenerImpl.chat(ServerGamePacketListenerImpl.java:2391) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at InteractiveChat-4.3.5.0.jar/com.loohp.interactivechat.nms.V1_21_4.chatAsPlayerAsync(V1_21_4.java:594) ~[InteractiveChat-4.3.5.0.jar:?] at InteractiveChat-4.3.5.0.jar/com.loohp.interactivechat.utils.PlayerUtils.chatAsPlayer(PlayerUtils.java:76) ~[InteractiveChat-4.3.5.0.jar:?] at InteractiveChat-4.3.5.0.jar/com.loohp.interactivechat.listeners.packet.RedispatchedSignPacketHandler.lambda$redispatchChatMessage$3(RedispatchedSignPacketHandler.java:62) ~[InteractiveChat-4.3.5.0.jar:?] at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:78) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at org.bukkit.craftbukkit.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.21.4.jar:1.21.4-229-e2ca477] at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.21.4.jar:?] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?] at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
KodariApr 19 at 3:41 pm 6,396 (v2)
I see the issue! DiscordSRV.getPlugin().getConfig() is returning null, which means DiscordSRV isnโt fully initialized yet. We need to add null safety checks:
Fixed! Added comprehensive null safety checks for DiscordSRV:
Checks if DiscordSRV plugin instance is available
Checks if JDA (Discord connection) is initialized
Safely handles when DiscordSRV config is null
Returns early with debug warnings instead of crashing
The plugin will now gracefully handle cases where DiscordSRV isnโt fully loaded yet.
now the problem is that I can't see the [channel] [name]: in the discord message
there's nothing like DiscordChatChannelMinecraftToDiscordMessageFormat
๐1 file
6,137 chars
๐
pasted-code-1776613949227.txt
txt138 lines
โถ
package org.kingcueio.manticore.api;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.api.Subscribe;
import github.scarsz.discordsrv.api.events.DiscordGuildMessageReceivedEvent;
import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent;
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import github.scarsz.discordsrv.util.DiscordUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.kingcueio.manticore.Manticore;
public class DiscordBridge {
private final Manticore plugin;
public DiscordBridge(Manticore plugin) {
this.plugin = plugin;
DiscordSRV.api.subscribe(this);
this.plugin.getLogger().info("DiscordBridge initialized with channel routing");
}
@Subscribe
public void onGameChatPreProcess(GameChatMessagePreProcessEvent event) {
Player player = event.getPlayer();
if (player == null) {
return;
}
String channelName = this.plugin.getPlayerChannel(player.getUniqueId());
String discordChannelId = this.plugin.getConfig().getString("channels." + channelName + ".discord-channel-id");
if (discordChannelId != null && !discordChannelId.isEmpty() && !discordChannelId.equals("000000000000000000")) {
event.setChannel(discordChannelId);
if (this.plugin.getConfig().getBoolean("debug", false)) {
this.plugin.getLogger().info("Routing " + player.getName() + "'s message from " + channelName + " to Discord channel " + discordChannelId);
}
}
}
public void sendToDiscord(Player player, String message, String channelName) {
if (DiscordSRV.getPlugin() == null || DiscordSRV.getPlugin().getJda() == null) {
if (this.plugin.getConfig().getBoolean("debug", false)) {
this.plugin.getLogger().warning("DiscordSRV not ready, cannot send message");
}
return;
}
String discordChannelId = this.plugin.getConfig().getString("channels." + channelName + ".discord-channel-id");
if (discordChannelId == null || discordChannelId.isEmpty() || discordChannelId.equals("000000000000000000")) {
TextChannel mainChannel = DiscordSRV.getPlugin().getMainTextChannel();
discordChannelId = mainChannel != null ? mainChannel.getId() : null;
}
if (discordChannelId == null) {
if (this.plugin.getConfig().getBoolean("debug", false)) {
this.plugin.getLogger().warning("Cannot send message to Discord: no channel configured");
}
return;
}
TextChannel channel = DiscordSRV.getPlugin().getJda().getTextChannelById(discordChannelId);
if (channel == null) {
if (this.plugin.getConfig().getBoolean("debug", false)) {
this.plugin.getLogger().warning("Discord channel " + discordChannelId + " not found");
}
return;
}
GameChatMessagePreProcessEvent event = new GameChatMessagePreProcessEvent(discordChannelId, message, player);
DiscordSRV.api.callEvent(event);
if (!event.isCancelled()) {
String finalMessage = event.getMessage();
String format = null;
if (DiscordSRV.getPlugin().getConfig() != null) {
format = DiscordSRV.getPlugin().getConfig().getString("DiscordChatChannelMinecraftToDiscordMessageFormat");
}
if (format != null) {
finalMessage = format
.replace("%username%", player.getName())
.replace("%displayname%", player.getDisplayName())
.replace("%message%", finalMessage);
}
DiscordUtil.sendMessage(channel, finalMessage);
}
if (this.plugin.getConfig().getBoolean("debug", false)) {
this.plugin.getLogger().info("Sent message from " + player.getName() + " to Discord channel " + discordChannelId);
}
}
@Subscribe
public void onDiscordMessage(DiscordGuildMessageReceivedEvent event) {
if (event.getAuthor().isBot()) return;
String discordChannelId = event.getChannel().getId();
String targetMcChannel = null;
var channelSection = plugin.getConfig().getConfigurationSection("channels");
if (channelSection != null) {
for (String key : channelSection.getKeys(false)) {
String configChannelId = channelSection.getString(key + ".discord-channel-id");
if (discordChannelId.equals(configChannelId)) {
targetMcChannel = key;
break;
}
}
}
boolean isMainChannel = event.getChannel().equals(DiscordSRV.getPlugin().getMainTextChannel());
if (targetMcChannel == null && isMainChannel) {
targetMcChannel = "global";
}
if (targetMcChannel == null) return;
String format = plugin.getConfig().getString("discord-to-mc-format", "&9[Discord] &f%name%&7: &f%message%");
String author = event.getMember().getEffectiveName();
String content = event.getMessage().getContentDisplay();
String rawMsg = format.replace("%name%", author).replace("%message%", content);
Component mcComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(rawMsg);
for (Player recipient : Bukkit.getOnlinePlayers()) {
String playerChan = plugin.getPlayerChannel(recipient.getUniqueId());
if (playerChan.equalsIgnoreCase(targetMcChannel)) {
recipient.sendMessage(mcComponent);
}
}
Bukkit.getConsoleSender().sendMessage(mcComponent);
}
public void shutdown() {
DiscordSRV.api.unsubscribe(this);
}
}
Kodari can make mistakes. Review important code before using.