Fix error with mirroring

This commit is contained in:
Vankka 2024-07-20 18:04:36 +03:00
parent 7f3c4c958b
commit a28a55c9f0
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
20 changed files with 135 additions and 61 deletions

View File

@ -30,7 +30,7 @@ import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@PlaceholderPrefix("channel_") @PlaceholderPrefix("channel_")
public interface DiscordGuildChannel extends Snowflake { public interface DiscordGuildChannel extends DiscordChannel, Snowflake {
/** /**
* Gets the name of the channel. * Gets the name of the channel.

View File

@ -23,18 +23,29 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import com.discordsrv.api.event.events.Event; import com.discordsrv.api.event.events.Event;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class AbstractGameMessageForwardedEvent implements Event { public abstract class AbstractGameMessageForwardedEvent implements Event {
private final GameChannel originGameChannel;
private final ReceivedDiscordMessageCluster discordMessage; private final ReceivedDiscordMessageCluster discordMessage;
public AbstractGameMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public AbstractGameMessageForwardedEvent(
@Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
this.originGameChannel = originGameChannel;
this.discordMessage = discordMessage; this.discordMessage = discordMessage;
} }
public GameChannel getOriginGameChannel() {
return originGameChannel;
}
/** /**
* Gets the {@link ReceivedDiscordMessageCluster} containing the sent message(s). * Gets the {@link ReceivedDiscordMessageCluster} containing the sent message(s).
* @return the message cluster * @return the message cluster

View File

@ -23,15 +23,20 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Indicates that an advancement or achievement message was forwarded to Discord. * Indicates that an advancement or achievement message was forwarded to Discord.
*/ */
public class AwardMessageForwardedEvent extends AbstractGameMessageForwardedEvent { public class AwardMessageForwardedEvent extends AbstractGameMessageForwardedEvent {
public AwardMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public AwardMessageForwardedEvent(
super(discordMessage); @Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
super(originGameChannel, discordMessage);
} }
} }

View File

@ -23,15 +23,20 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Indicates that a death message was forwarded to Discord. * Indicates that a death message was forwarded to Discord.
*/ */
public class DeathMessageForwardedEvent extends AbstractGameMessageForwardedEvent { public class DeathMessageForwardedEvent extends AbstractGameMessageForwardedEvent {
public DeathMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public DeathMessageForwardedEvent(
super(discordMessage); @Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
super(originGameChannel, discordMessage);
} }
} }

View File

@ -23,15 +23,20 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Indicates that a chat message was forwarded to Discord. * Indicates that a chat message was forwarded to Discord.
*/ */
public class GameChatMessageForwardedEvent extends AbstractGameMessageForwardedEvent { public class GameChatMessageForwardedEvent extends AbstractGameMessageForwardedEvent {
public GameChatMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public GameChatMessageForwardedEvent(
super(discordMessage); @Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
super(originGameChannel, discordMessage);
} }
} }

View File

@ -23,15 +23,20 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Indicates that a join message was forwarded to Discord. * Indicates that a join message was forwarded to Discord.
*/ */
public class JoinMessageForwardedEvent extends AbstractGameMessageForwardedEvent { public class JoinMessageForwardedEvent extends AbstractGameMessageForwardedEvent {
public JoinMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public JoinMessageForwardedEvent(
super(discordMessage); @Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
super(originGameChannel, discordMessage);
} }
} }

View File

@ -23,15 +23,20 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Indicates that a leave message was forwarded to Discord. * Indicates that a leave message was forwarded to Discord.
*/ */
public class LeaveMessageForwardedEvent extends AbstractGameMessageForwardedEvent { public class LeaveMessageForwardedEvent extends AbstractGameMessageForwardedEvent {
public LeaveMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public LeaveMessageForwardedEvent(
super(discordMessage); @Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
super(originGameChannel, discordMessage);
} }
} }

View File

@ -23,15 +23,20 @@
package com.discordsrv.api.event.events.message.forward.game; package com.discordsrv.api.event.events.message.forward.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Indicates that a server switch message was forwarded to Discord. * Indicates that a server switch message was forwarded to Discord.
*/ */
public class ServerSwitchMessageForwardedEvent extends AbstractGameMessageForwardedEvent { public class ServerSwitchMessageForwardedEvent extends AbstractGameMessageForwardedEvent {
public ServerSwitchMessageForwardedEvent(@NotNull ReceivedDiscordMessageCluster discordMessage) { public ServerSwitchMessageForwardedEvent(
super(discordMessage); @Nullable GameChannel originGameChannel,
@NotNull ReceivedDiscordMessageCluster discordMessage
) {
super(originGameChannel, discordMessage);
} }
} }

View File

@ -18,6 +18,8 @@
package com.discordsrv.common.config.main.generic; package com.discordsrv.common.config.main.generic;
import com.discordsrv.api.discord.entity.channel.DiscordChannel;
import com.discordsrv.api.discord.entity.channel.DiscordThreadChannel;
import com.discordsrv.common.config.configurate.annotation.Constants; import com.discordsrv.common.config.configurate.annotation.Constants;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ -73,6 +75,21 @@ public class DestinationConfig {
} }
} }
public boolean contains(DiscordChannel channel) {
if (channel instanceof DiscordThreadChannel) {
long parentId = ((DiscordThreadChannel) channel).getParentChannel().getId();
String threadName = ((DiscordThreadChannel) channel).getName();
for (ThreadConfig thread : threads) {
if (thread.channelId == parentId && thread.threadName.equals(threadName)) {
return true;
}
}
return false;
}
return channelIds.contains(channel.getId());
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -22,7 +22,6 @@ import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.channel.DiscordGuildChannel; import com.discordsrv.api.discord.entity.channel.DiscordGuildChannel;
import com.discordsrv.api.discord.entity.channel.DiscordGuildMessageChannel; import com.discordsrv.api.discord.entity.channel.DiscordGuildMessageChannel;
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel; import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
import com.discordsrv.api.discord.entity.channel.DiscordThreadChannel;
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember; import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
@ -105,23 +104,7 @@ public class SingleConsoleHandler {
} }
DestinationConfig.Single destination = config.channel; DestinationConfig.Single destination = config.channel;
String threadName = destination.thread.threadName; if (!destination.asDestination().contains(channel)) {
DiscordGuildChannel checkChannel;
if (StringUtils.isNotEmpty(threadName)) {
if (!(channel instanceof DiscordThreadChannel)) {
return;
}
if (!channel.getName().equals(threadName)) {
return;
}
checkChannel = ((DiscordThreadChannel) channel).getParentChannel();
} else {
checkChannel = channel;
}
if (checkChannel.getId() != destination.channelId) {
return; return;
} }

View File

@ -330,12 +330,28 @@ public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
public void onGameMessageForwarded(AbstractGameMessageForwardedEvent event) { public void onGameMessageForwarded(AbstractGameMessageForwardedEvent event) {
Set<? extends ReceivedDiscordMessage> messages = event.getDiscordMessage().getMessages(); Set<? extends ReceivedDiscordMessage> messages = event.getDiscordMessage().getMessages();
GameChannel gameChannel = event.getOriginGameChannel();
BaseChannelConfig gameChannelConfig = gameChannel != null ? discordSRV.channelConfig().get(gameChannel) : null;
Map<ReceivedDiscordMessage, MessageReference> references = new LinkedHashMap<>(); Map<ReceivedDiscordMessage, MessageReference> references = new LinkedHashMap<>();
for (ReceivedDiscordMessage message : messages) { for (ReceivedDiscordMessage message : messages) {
DiscordMessageChannel channel = message.getChannel(); BaseChannelConfig channelConfig = gameChannelConfig;
if (channelConfig == null) {
DiscordMessageChannel channel = message.getChannel();
MirroringConfig config = discordSRV.channelConfig().resolve(channel).values().iterator().next().mirroring; // TODO: add channel to event channelConfig = discordSRV.channelConfig()
MessageReference reference = getReference(message, config); .resolve(channel)
.values()
.stream()
.filter(config -> config instanceof IChannelConfig && ((IChannelConfig) config).destination().contains(channel))
.findAny()
.orElse(null);
}
if (channelConfig == null) {
continue;
}
MessageReference reference = getReference(message, channelConfig.mirroring);
references.put(message, reference); references.put(message, reference);
} }

View File

@ -54,11 +54,11 @@ import java.util.concurrent.CompletableFuture;
* <p> * <p>
* Order of operations: * Order of operations:
* - Event (E generic) is received, implementation calls {@link #process(AbstractGameMessageReceiveEvent, DiscordSRVPlayer, GameChannel)} * - Event (E generic) is received, implementation calls {@link #process(AbstractGameMessageReceiveEvent, DiscordSRVPlayer, GameChannel)}
* - {@link IPlayer} and {@link BaseChannelConfig} (uses {@link #mapConfig(AbstractGameMessageReceiveEvent, BaseChannelConfig)} are resolved, then {@link #forwardToChannel(AbstractGameMessageReceiveEvent, IPlayer, BaseChannelConfig)} is called * - {@link IPlayer} and {@link BaseChannelConfig} (uses {@link #mapConfig(AbstractGameMessageReceiveEvent, BaseChannelConfig)} are resolved, then {@link #forwardToChannel(AbstractGameMessageReceiveEvent, IPlayer, BaseChannelConfig, GameChannel)} is called
* - Destinations are looked up and {@link #sendMessageToChannels} gets called * - Destinations are looked up and {@link #sendMessageToChannels} gets called
* - {@link #setPlaceholders(IMessageConfig, AbstractGameMessageReceiveEvent, SendableDiscordMessage.Formatter)} is called to set any additional placeholders * - {@link #setPlaceholders(IMessageConfig, AbstractGameMessageReceiveEvent, SendableDiscordMessage.Formatter)} is called to set any additional placeholders
* - {@link #sendMessageToChannel(DiscordGuildMessageChannel, SendableDiscordMessage)} is called (once per channel) to send messages to individual channels * - {@link #sendMessageToChannel(DiscordGuildMessageChannel, SendableDiscordMessage)} is called (once per channel) to send messages to individual channels
* - {@link #postClusterToEventBus(ReceivedDiscordMessageCluster)} is called with all messages that were sent (if any messages were sent) * - {@link #postClusterToEventBus(GameChannel, ReceivedDiscordMessageCluster)} is called with all messages that were sent (if any messages were sent)
* *
* @param <T> config model * @param <T> config model
* @param <E> the event indicating a message was received from in-game, of type {@link AbstractGameMessageReceiveEvent} * @param <E> the event indicating a message was received from in-game, of type {@link AbstractGameMessageReceiveEvent}
@ -84,7 +84,7 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
} }
public abstract T mapConfig(BaseChannelConfig channelConfig); public abstract T mapConfig(BaseChannelConfig channelConfig);
public abstract void postClusterToEventBus(ReceivedDiscordMessageCluster cluster); public abstract void postClusterToEventBus(@Nullable GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster);
public final CompletableFuture<?> process( public final CompletableFuture<?> process(
@Nullable E event, @Nullable E event,
@ -100,7 +100,7 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
// Send to all channels due to lack of specified channel // Send to all channels due to lack of specified channel
List<CompletableFuture<Void>> futures = new ArrayList<>(); List<CompletableFuture<Void>> futures = new ArrayList<>();
for (BaseChannelConfig channelConfig : discordSRV.channelConfig().getAllChannels()) { for (BaseChannelConfig channelConfig : discordSRV.channelConfig().getAllChannels()) {
CompletableFuture<Void> future = forwardToChannel(event, srvPlayer, channelConfig); CompletableFuture<Void> future = forwardToChannel(event, srvPlayer, channelConfig, null);
if (future != null) { if (future != null) {
futures.add(future); futures.add(future);
} }
@ -113,14 +113,15 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }
return forwardToChannel(event, srvPlayer, channelConfig); return forwardToChannel(event, srvPlayer, channelConfig, channel);
} }
@SuppressWarnings("unchecked") // Wacky generis @SuppressWarnings("unchecked") // Wacky generis
protected <CC extends BaseChannelConfig & IChannelConfig> CompletableFuture<Void> forwardToChannel( protected <CC extends BaseChannelConfig & IChannelConfig> CompletableFuture<Void> forwardToChannel(
@Nullable E event, @Nullable E event,
@Nullable IPlayer player, @Nullable IPlayer player,
@NotNull BaseChannelConfig config @NotNull BaseChannelConfig config,
@Nullable GameChannel channel
) { ) {
T moduleConfig = mapConfig(event, config); T moduleConfig = mapConfig(event, config);
if (!moduleConfig.enabled()) { if (!moduleConfig.enabled()) {
@ -158,7 +159,7 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
return; return;
} }
postClusterToEventBus(new ReceivedDiscordMessageClusterImpl(messages)); postClusterToEventBus(channel, new ReceivedDiscordMessageClusterImpl(messages));
}).exceptionally(t -> { }).exceptionally(t -> {
discordSRV.logger().error("Failed to publish to event bus", t); discordSRV.logger().error("Failed to publish to event bus", t);
TestHelper.fail(t); TestHelper.fail(t);

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
@ -33,6 +34,8 @@ import com.discordsrv.common.config.main.channels.base.server.ServerBaseChannelC
import com.discordsrv.common.config.main.channels.server.AwardMessageConfig; import com.discordsrv.common.config.main.channels.server.AwardMessageConfig;
import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Cache;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -81,8 +84,8 @@ public class AwardMessageModule extends AbstractGameMessageModule<AwardMessageCo
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) { public void postClusterToEventBus(@Nullable GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {
discordSRV.eventBus().publish(new AwardMessageForwardedEvent(cluster)); discordSRV.eventBus().publish(new AwardMessageForwardedEvent(channel, cluster));
} }
@Override @Override

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
@ -30,6 +31,7 @@ import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.config.main.channels.base.server.ServerBaseChannelConfig; import com.discordsrv.common.config.main.channels.base.server.ServerBaseChannelConfig;
import com.discordsrv.common.config.main.channels.server.DeathMessageConfig; import com.discordsrv.common.config.main.channels.server.DeathMessageConfig;
import org.jetbrains.annotations.NotNull;
public class DeathMessageModule extends AbstractGameMessageModule<DeathMessageConfig, DeathMessageReceiveEvent> { public class DeathMessageModule extends AbstractGameMessageModule<DeathMessageConfig, DeathMessageReceiveEvent> {
@ -53,8 +55,8 @@ public class DeathMessageModule extends AbstractGameMessageModule<DeathMessageCo
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) { public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {
discordSRV.eventBus().publish(new DeathMessageForwardedEvent(cluster)); discordSRV.eventBus().publish(new DeathMessageForwardedEvent(channel, cluster));
} }
@Override @Override

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
@ -65,7 +66,8 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
protected CompletableFuture<Void> forwardToChannel( protected CompletableFuture<Void> forwardToChannel(
@Nullable JoinMessageReceiveEvent event, @Nullable JoinMessageReceiveEvent event,
@Nullable IPlayer player, @Nullable IPlayer player,
@NotNull BaseChannelConfig config @NotNull BaseChannelConfig config,
@Nullable GameChannel channel
) { ) {
if (config.joinMessages().enableSilentPermission && player != null && player.hasPermission(Permission.SILENT_JOIN)) { if (config.joinMessages().enableSilentPermission && player != null && player.hasPermission(Permission.SILENT_JOIN)) {
logger().info(player.username() + " is joining silently, join message will not be sent"); logger().info(player.username() + " is joining silently, join message will not be sent");
@ -79,7 +81,7 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
CompletableFuture<Void> completableFuture = new CompletableFuture<>(); CompletableFuture<Void> completableFuture = new CompletableFuture<>();
synchronized (delayedTasks) { synchronized (delayedTasks) {
CompletableFuture<Void> future = discordSRV.scheduler() CompletableFuture<Void> future = discordSRV.scheduler()
.supplyLater(() -> super.forwardToChannel(event, player, config), Duration.ofMillis(delay)) .supplyLater(() -> super.forwardToChannel(event, player, config, channel), Duration.ofMillis(delay))
.thenCompose(r -> r) .thenCompose(r -> r)
.whenComplete((v, t) -> delayedTasks.remove(playerUUID)); .whenComplete((v, t) -> delayedTasks.remove(playerUUID));
@ -87,7 +89,7 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
} }
return completableFuture; return completableFuture;
} }
return super.forwardToChannel(event, player, config); return super.forwardToChannel(event, player, config, channel);
} }
@Subscribe @Subscribe
@ -111,8 +113,8 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) { public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {
discordSRV.eventBus().publish(new JoinMessageForwardedEvent(cluster)); discordSRV.eventBus().publish(new JoinMessageForwardedEvent(channel, cluster));
} }
@Override @Override

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
@ -88,7 +89,8 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
protected CompletableFuture<Void> forwardToChannel( protected CompletableFuture<Void> forwardToChannel(
@Nullable LeaveMessageReceiveEvent event, @Nullable LeaveMessageReceiveEvent event,
@Nullable IPlayer player, @Nullable IPlayer player,
@NotNull BaseChannelConfig config @NotNull BaseChannelConfig config,
@Nullable GameChannel channel
) { ) {
if (player != null) { if (player != null) {
Pair<Long, Future<?>> pair = playersJoinedRecently.remove(player.uniqueId()); Pair<Long, Future<?>> pair = playersJoinedRecently.remove(player.uniqueId());
@ -105,7 +107,7 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
logger().info(player.username() + " is leaving silently, leave message will not be sent"); logger().info(player.username() + " is leaving silently, leave message will not be sent");
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }
return super.forwardToChannel(event, player, config); return super.forwardToChannel(event, player, config, channel);
} }
@Override @Override
@ -114,8 +116,8 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) { public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {
discordSRV.eventBus().publish(new LeaveMessageForwardedEvent(cluster)); discordSRV.eventBus().publish(new LeaveMessageForwardedEvent(channel, cluster));
} }
@Override @Override

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
@ -31,6 +32,7 @@ import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.config.main.channels.base.proxy.ProxyBaseChannelConfig; import com.discordsrv.common.config.main.channels.base.proxy.ProxyBaseChannelConfig;
import com.discordsrv.common.config.main.channels.proxy.ServerSwitchMessageConfig; import com.discordsrv.common.config.main.channels.proxy.ServerSwitchMessageConfig;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
public class ServerSwitchMessageModule extends AbstractGameMessageModule<ServerSwitchMessageConfig, ServerSwitchMessageReceiveEvent> { public class ServerSwitchMessageModule extends AbstractGameMessageModule<ServerSwitchMessageConfig, ServerSwitchMessageReceiveEvent> {
@ -54,8 +56,8 @@ public class ServerSwitchMessageModule extends AbstractGameMessageModule<ServerS
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) { public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {
discordSRV.eventBus().publish(new ServerSwitchMessageForwardedEvent(cluster)); discordSRV.eventBus().publish(new ServerSwitchMessageForwardedEvent(channel, cluster));
} }
@Override @Override

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.channel.DiscordGuildMessageChannel; import com.discordsrv.api.discord.entity.channel.DiscordGuildMessageChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
@ -27,6 +28,7 @@ import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.main.channels.StartMessageConfig; import com.discordsrv.common.config.main.channels.StartMessageConfig;
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.player.IPlayer; import com.discordsrv.common.player.IPlayer;
import org.jetbrains.annotations.NotNull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -50,7 +52,7 @@ public class StartMessageModule extends AbstractGameMessageModule<StartMessageCo
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) {} public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {}
@Override @Override
public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels( public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels(

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.messageforwarding.game; package com.discordsrv.common.messageforwarding.game;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.discord.entity.channel.DiscordGuildMessageChannel; import com.discordsrv.api.discord.entity.channel.DiscordGuildMessageChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessageCluster;
@ -27,6 +28,7 @@ import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.main.channels.StopMessageConfig; import com.discordsrv.common.config.main.channels.StopMessageConfig;
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.player.IPlayer; import com.discordsrv.common.player.IPlayer;
import org.jetbrains.annotations.NotNull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -53,7 +55,7 @@ public class StopMessageModule extends AbstractGameMessageModule<StopMessageConf
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) {} public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {}
@Override @Override
public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels( public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels(

View File

@ -43,6 +43,7 @@ import com.discordsrv.common.player.IPlayer;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -73,8 +74,8 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
} }
@Override @Override
public void postClusterToEventBus(ReceivedDiscordMessageCluster cluster) { public void postClusterToEventBus(GameChannel channel, @NotNull ReceivedDiscordMessageCluster cluster) {
discordSRV.eventBus().publish(new GameChatMessageForwardedEvent(cluster)); discordSRV.eventBus().publish(new GameChatMessageForwardedEvent(channel, cluster));
} }
@Override @Override