mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Fully implement chat/whisper spying (#421)
* Add spy toggle command * Show whispers to spying players * Split enabled/disabled locale * Don't spy your own messages * Spy party chat messages Party spy adds a prefix to the message and whisper spy has its own entire format. One of these should probably be changed? * Add radius spying
This commit is contained in:
1 parent
494e4b6f70
commit
ef62f823e0
7 files changed
+234
-3
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
|
||||
@Inject
|
||||
public SpyCommand(
|
||||
final CommandManager<Commander> 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);
|
||||
}
|
||||
|
||||
}
|
||||
+22
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<UUID> 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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<CarbonPlayer> 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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in new issue
Block a user