Allow disabling cross-server broadcasting per-channel (#589)

* Add channel config option to individually disable cross-server

* Block incoming messages when channel cross-server is false
This commit is contained in:
Josua Parks authored and GitHub committed 2025-01-13 02:54:29 -08:00
1 parent 1ed9f4441e
commit 9380c13817
7 files changed
+39

No files matched your search

@@ -132,4 +132,12 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
*/
long startCooldown(CarbonPlayer player);
/**
* Whether messages from this channel should be broadcast and sent to other servers.
*
* @return if this channel's messages should be sent cross-server
* @since 3.0.0
*/
boolean shouldCrossServer();
}
@@ -117,6 +117,9 @@ public class ConfigChatChannel implements ChatChannel {
private long cooldown = -1;
@Comment("Whether this channel's messages should be sent cross-server.")
private boolean crossServer = true;
@Override
public @Nullable String quickPrefix() {
if (this.quickPrefix == null || this.quickPrefix.isBlank()) {
@@ -263,6 +266,11 @@ public class ConfigChatChannel implements ChatChannel {
return this.emptyRadiusRecipientsMessage;
}
@Override
public boolean shouldCrossServer() {
return this.crossServer;
}
@Override
public boolean equals(final Object other) {
if (!(other instanceof ConfigChatChannel otherChannel)) {
@@ -51,6 +51,10 @@ public class MessagePacketHandler implements Listener {
return;
}
if (!event.chatChannel().shouldCrossServer()) {
return;
}
messaging.get().queuePacket(() -> {
final CarbonPlayer sender = event.sender();
final Component networkMessage = e.renderFor(sender);
@@ -122,6 +122,10 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
return false;
}
if (!channel.shouldCrossServer()) {
return false;
}
final List<KeyedRenderer> renderers = new ArrayList<>();
final List<Audience> recipients = channel.recipients(sender);
@@ -63,4 +63,9 @@ abstract class AbstractFactionsChannel extends ConfigChatChannel {
return faction != null && faction.getRelationCount(relation) > 0;
}
@Override
public boolean shouldCrossServer() {
return false;
}
}
@@ -101,4 +101,9 @@ public class McmmoPartyChannel extends ConfigChatChannel {
return PartyManager.getParty(Bukkit.getPlayer(player.uuid()));
}
@Override
public boolean shouldCrossServer() {
return false;
}
}
@@ -91,4 +91,9 @@ abstract class ResidentListChannel<T extends ResidentList> extends ConfigChatCha
protected abstract Component cannotUseChannel(CarbonPlayer player);
@Override
public boolean shouldCrossServer() {
return false;
}
}