diff --git a/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java b/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java
index 602920b6..7833e6d9 100644
--- a/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java
+++ b/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java
@@ -58,6 +58,7 @@ import net.draycia.carbon.common.command.commands.NicknameCommand;
import net.draycia.carbon.common.command.commands.PartyCommands;
import net.draycia.carbon.common.command.commands.ReloadCommand;
import net.draycia.carbon.common.command.commands.ReplyCommand;
+import net.draycia.carbon.common.command.commands.SpyCommand;
import net.draycia.carbon.common.command.commands.ToggleMessagesCommand;
import net.draycia.carbon.common.command.commands.UnignoreCommand;
import net.draycia.carbon.common.command.commands.UnmuteCommand;
@@ -73,6 +74,7 @@ import net.draycia.carbon.common.listeners.ItemLinkHandler;
import net.draycia.carbon.common.listeners.Listener;
import net.draycia.carbon.common.listeners.MessagePacketHandler;
import net.draycia.carbon.common.listeners.MuteHandler;
+import net.draycia.carbon.common.listeners.PartyChatSpyHandler;
import net.draycia.carbon.common.listeners.PingHandler;
import net.draycia.carbon.common.listeners.RadiusListener;
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
@@ -220,6 +222,7 @@ public final class CarbonCommonModule extends AbstractModule {
listeners.addBinding().to(ItemLinkHandler.class);
listeners.addBinding().to(MessagePacketHandler.class);
listeners.addBinding().to(MuteHandler.class);
+ listeners.addBinding().to(PartyChatSpyHandler.class);
listeners.addBinding().to(PingHandler.class);
listeners.addBinding().to(RadiusListener.class);
}
@@ -238,6 +241,7 @@ public final class CarbonCommonModule extends AbstractModule {
commands.addBinding().to(NicknameCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(ReloadCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(ReplyCommand.class).in(Scopes.SINGLETON);
+ commands.addBinding().to(SpyCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(ToggleMessagesCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(UnignoreCommand.class).in(Scopes.SINGLETON);
commands.addBinding().to(UnmuteCommand.class).in(Scopes.SINGLETON);
diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/SpyCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/SpyCommand.java
new file mode 100644
index 00000000..856752a5
--- /dev/null
+++ b/common/src/main/java/net/draycia/carbon/common/command/commands/SpyCommand.java
@@ -0,0 +1,90 @@
+/*
+ * CarbonChat
+ *
+ * Copyright (c) 2024 Josua Parks (Vicarious)
+ * Contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.draycia.carbon.common.command.commands;
+
+import com.google.inject.Inject;
+import net.draycia.carbon.api.users.CarbonPlayer;
+import net.draycia.carbon.common.command.CarbonCommand;
+import net.draycia.carbon.common.command.CommandSettings;
+import net.draycia.carbon.common.command.Commander;
+import net.draycia.carbon.common.command.PlayerCommander;
+import net.draycia.carbon.common.messages.CarbonMessages;
+import net.kyori.adventure.key.Key;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.framework.qual.DefaultQualifier;
+import org.incendo.cloud.CommandManager;
+
+import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
+import static org.incendo.cloud.parser.standard.BooleanParser.booleanParser;
+
+@DefaultQualifier(NonNull.class)
+public final class SpyCommand extends CarbonCommand {
+
+ private final CommandManager commandManager;
+ private final CarbonMessages carbonMessages;
+
+ @Inject
+ public SpyCommand(
+ final CommandManager commandManager,
+ final CarbonMessages carbonMessages
+ ) {
+ this.commandManager = commandManager;
+ this.carbonMessages = carbonMessages;
+ }
+
+ @Override
+ public CommandSettings defaultCommandSettings() {
+ return new CommandSettings("spy");
+ }
+
+ @Override
+ public Key key() {
+ return Key.key("carbon", "spy");
+ }
+
+ @Override
+ public void init() {
+ final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
+ .optional("enabled", booleanParser())
+ .permission("carbon.spy")
+ .senderType(PlayerCommander.class)
+ .commandDescription(richDescription(this.carbonMessages.commandSpyDescription()))
+ .handler(handler -> {
+ final CarbonPlayer sender = handler.sender().carbonPlayer();
+
+ boolean enabled = !sender.spying();
+
+ if (handler.contains("enabled")) {
+ enabled = handler.get("enabled");
+ }
+
+ sender.spying(enabled);
+ if (enabled) {
+ this.carbonMessages.commandSpyEnabled(sender);
+ } else {
+ this.carbonMessages.commandSpyDisabled(sender);
+ }
+ })
+ .build();
+
+ this.commandManager.command(command);
+ }
+
+}
diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java
index 8482acbb..9165d15b 100644
--- a/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java
+++ b/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java
@@ -226,7 +226,10 @@ public final class WhisperCommand extends CarbonCommand {
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message())
);
}
- this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message());
+ WhisperCommand.broadcastWhisperSpy(this.server, this.messages, senderUsername, senderDisplayName,
+ recipientUsername, recipientDisplayName, privateChatEvent.message());
+ this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName,
+ recipientUsername, recipientDisplayName, privateChatEvent.message());
final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound();
if (localRecipient && messageSound != null) {
@@ -260,6 +263,7 @@ public final class WhisperCommand extends CarbonCommand {
SourcedAudience.of(sender, recipient).sendMessage(
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message())
);
+ WhisperCommand.broadcastWhisperSpy(this.server, this.messages, senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message());
this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message());
final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound();
if (messageSound != null) {
@@ -272,4 +276,21 @@ public final class WhisperCommand extends CarbonCommand {
}
}
+ public static void broadcastWhisperSpy(
+ final CarbonServer server,
+ final CarbonMessages messages,
+ final String senderUsername,
+ final Component senderDisplayName,
+ final String recipientUsername,
+ final Component recipientDisplayName,
+ final Component message
+ ) {
+ for (final CarbonPlayer player : server.players()) {
+ if (player.spying() && !player.username().equals(senderUsername) && !player.username().equals(recipientUsername)) {
+ messages.whisperRecipientSpy(player, senderUsername,
+ senderDisplayName, recipientUsername, recipientDisplayName, message);
+ }
+ }
+ }
+
}
diff --git a/common/src/main/java/net/draycia/carbon/common/listeners/PartyChatSpyHandler.java b/common/src/main/java/net/draycia/carbon/common/listeners/PartyChatSpyHandler.java
new file mode 100644
index 00000000..b7e11e63
--- /dev/null
+++ b/common/src/main/java/net/draycia/carbon/common/listeners/PartyChatSpyHandler.java
@@ -0,0 +1,57 @@
+/*
+ * CarbonChat
+ *
+ * Copyright (c) 2024 Josua Parks (Vicarious)
+ * Contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.draycia.carbon.common.listeners;
+
+import com.google.inject.Inject;
+import java.util.Set;
+import java.util.UUID;
+import net.draycia.carbon.api.CarbonServer;
+import net.draycia.carbon.api.event.CarbonEventHandler;
+import net.draycia.carbon.api.event.events.CarbonChatEvent;
+import net.draycia.carbon.api.users.CarbonPlayer;
+import net.draycia.carbon.api.users.Party;
+import net.draycia.carbon.common.channels.PartyChatChannel;
+import net.draycia.carbon.common.messages.CarbonMessages;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
+
+@DefaultQualifier(NonNull.class)
+public class PartyChatSpyHandler implements Listener {
+
+ @Inject
+ public PartyChatSpyHandler(final CarbonEventHandler events, final CarbonMessages messages, final CarbonServer server) {
+ events.subscribe(CarbonChatEvent.class, 100, false, event -> {
+ if (!(event.chatChannel() instanceof PartyChatChannel)) {
+ return;
+ }
+
+ final @Nullable Party party = event.sender().party().get();
+ final Set members = party == null ? Set.of() : party.members();
+
+ for (final CarbonPlayer player : server.players()) {
+ if (player.spying() && !members.contains(player.uuid())) {
+ messages.partySpy(player, event.message());
+ }
+ }
+ });
+ }
+
+}
diff --git a/common/src/main/java/net/draycia/carbon/common/listeners/RadiusListener.java b/common/src/main/java/net/draycia/carbon/common/listeners/RadiusListener.java
index a85e007c..57d236cb 100644
--- a/common/src/main/java/net/draycia/carbon/common/listeners/RadiusListener.java
+++ b/common/src/main/java/net/draycia/carbon/common/listeners/RadiusListener.java
@@ -20,6 +20,8 @@
package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
@@ -46,6 +48,8 @@ public class RadiusListener implements Listener {
return;
}
+ final List spyingPlayers = new ArrayList<>();
+
if (radius == 0) {
event.recipients().removeIf(audience -> {
if (audience.equals(event.sender())) {
@@ -53,7 +57,13 @@ public class RadiusListener implements Listener {
}
if (audience instanceof CarbonPlayer carbonPlayer) {
- return !carbonPlayer.sameWorldAs(event.sender());
+ final boolean sameWorld = carbonPlayer.sameWorldAs(event.sender());
+
+ if (!sameWorld && carbonPlayer.spying()) {
+ spyingPlayers.add(carbonPlayer);
+ }
+
+ return !sameWorld;
}
return false;
@@ -66,11 +76,20 @@ public class RadiusListener implements Listener {
if (audience instanceof CarbonPlayer carbonPlayer) {
if (!event.sender().sameWorldAs(carbonPlayer)) {
+ if (carbonPlayer.spying()) {
+ spyingPlayers.add(carbonPlayer);
+ }
return true;
}
final double distance = carbonPlayer.distanceSquaredFrom(event.sender());
- return distance > (radius * radius);
+ final boolean outOfRange = distance > (radius * radius);
+
+ if (outOfRange && carbonPlayer.spying()) {
+ spyingPlayers.add(carbonPlayer);
+ }
+
+ return outOfRange;
}
return false;
@@ -78,6 +97,11 @@ public class RadiusListener implements Listener {
}
if (event.recipients().size() <= 2 && event.chatChannel().emptyRadiusRecipientsMessage()) { // the player and cosole
carbonMessages.emptyRecipients(event.sender());
+ return;
+ }
+
+ for (final CarbonPlayer player : spyingPlayers) {
+ carbonMessages.radiusSpy(player, event.message());
}
});
}
diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java
index 7c152879..996431f9 100644
--- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java
+++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java
@@ -38,6 +38,9 @@ public interface CarbonMessages {
@Message("channel.radius.empty_recipients")
void emptyRecipients(final Audience audience);
+ @Message("channel.radius.spy")
+ void radiusSpy(Audience audience, Component message);
+
@Message("channel.not_found")
void channelNotFound(final Audience audience);
@@ -130,6 +133,16 @@ public interface CarbonMessages {
Component message
);
+ @Message("whisper.from.spy")
+ void whisperRecipientSpy(
+ Audience audience,
+ String senderUsername,
+ Component senderDisplayName,
+ String recipientUsername,
+ Component recipientDisplayName,
+ Component message
+ );
+
@Message("whisper.console")
void whisperConsoleLog(
Audience audience,
@@ -257,6 +270,21 @@ public interface CarbonMessages {
@Message("config.reload.failed")
void configReloadFailed(final Audience audience);
+ /*
+ * =============================================================
+ * ========================== Spying ===========================
+ * =============================================================
+ */
+
+ @Message("command.spy.enabled")
+ void commandSpyEnabled(final Audience audience);
+
+ @Message("command.spy.disabled")
+ void commandSpyDisabled(final Audience audience);
+
+ @Message("command.spy.description")
+ Component commandSpyDescription();
+
/*
* =============================================================
* ====================== Cloud Messages =======================
@@ -525,6 +553,9 @@ public interface CarbonMessages {
@Message("party.cannot_use_channel")
Component cannotUsePartyChannel(Audience audience);
+ @Message("party.spy")
+ void partySpy(Audience audience, Component message);
+
@Message("deletemessage.prefix")
Component deleteMessagePrefix();
diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties
index 1d8435b8..1dbde113 100644
--- a/common/src/main/resources/locale/messages-en_US.properties
+++ b/common/src/main/resources/locale/messages-en_US.properties
@@ -86,9 +86,12 @@ command.party.accept.description=Accept party invites.
command.party.leave.description=Leave your current party.
command.party.already_in_party= is already in your party.
command.party.disband.description=Disband your current party.
+command.spy.enabled=Spying is now enabled.
+command.spy.disabled=Spying is now disabled.
party.player_joined= joined your party.
party.player_left= left your party.
party.cannot_use_channel=You must join a party to use this channel.
+party.spy=[Spy]
config.reload.failed=Config failed to reload
config.reload.success=Config reloaded successfully
error.command.argument_parsing=Invalid command argument:
@@ -134,6 +137,7 @@ whisper.console=[] -> [You have no one to whisper
whisper.error=Failed to send private message
whisper.from= '>[] -> [You]
+whisper.from.spy=SPY [] -> []
whisper.ignored_by_target= is ignoring you
whisper.ignoring_target=You are ignoring
whisper.ignoring_all=You cannot send messages while they are ignored!