whisper continue command

This commit is contained in:
Draycia committed 2021-09-21 20:20:31 -07:00
1 parent 662d327400
commit 44c58eeec4
9 files changed
+125 -2

No files matched your search

@@ -206,4 +206,20 @@ public interface CarbonPlayer extends Audience, Identified {
*/
void whisperReplyTarget(final @Nullable UUID uuid);
/**
* The last player this player has whispered.
*
* @return the player's last whisper target
* @since 2.0.0
*/
@Nullable UUID lastWhisperTarget();
/**
* Sets the last player this player has whispered.
*
* @param uuid the uuid of the whisper target
* @since 2.0.0
*/
void lastWhisperTarget(final @Nullable UUID uuid);
}
@@ -18,6 +18,7 @@ import net.draycia.carbon.bukkit.listeners.BukkitPlayerJoinListener;
import net.draycia.carbon.bukkit.users.CarbonPlayerBukkit;
import net.draycia.carbon.bukkit.util.BukkitMessageRenderer;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.commands.ContinueCommand;
import net.draycia.carbon.common.command.commands.ReplyCommand;
import net.draycia.carbon.common.command.commands.WhisperCommand;
import net.draycia.carbon.common.listeners.DeafenHandler;
@@ -90,12 +91,13 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
}
// Listeners
injector.getInstance(MuteHandler.class);
injector.getInstance(DeafenHandler.class);
injector.getInstance(MuteHandler.class);
// Commands
injector.getInstance(WhisperCommand.class);
injector.getInstance(ContinueCommand.class);
injector.getInstance(ReplyCommand.class);
injector.getInstance(WhisperCommand.class);
final long saveDelay = 5 * 60 * 20;
@@ -275,4 +275,14 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements Forw
return this.carbonPlayer.whisperReplyTarget();
}
@Override
public void lastWhisperTarget(@Nullable UUID uuid) {
this.carbonPlayer.lastWhisperTarget(uuid);
}
@Override
public @Nullable UUID lastWhisperTarget() {
return this.carbonPlayer.lastWhisperTarget();
}
}
@@ -0,0 +1,67 @@
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import com.google.inject.Inject;
import java.util.UUID;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.util.SourcedAudience;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class ContinueCommand {
@Inject
public ContinueCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
) {
var command = commandManager.commandBuilder("continue", "c")
.argument(StringArgument.greedy("message"))
.permission("carbon.whisper.continue") // TODO: carbon.whisper.spy
.senderType(PlayerCommander.class)
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander)handler.getSender()).carbonPlayer();
final String message = handler.get("message");
final UUID whisperTarget = sender.lastWhisperTarget();
if (whisperTarget == null) {
messageService.whisperTargetNotSet(sender, sender.displayName());
return;
}
final ComponentPlayerResult result = carbonChat.server().player(whisperTarget).join();
final @MonotonicNonNull CarbonPlayer recipient = result.player();
if (recipient == null) {
messageService.whisperTargetOffline(sender, sender.displayName());
return;
}
if (sender.equals(recipient)) {
messageService.whisperSelfError(sender, sender.displayName());
return;
}
messageService.whisperSender(new SourcedAudience(sender, sender),
sender.displayName(), recipient.displayName(), message);
messageService.whisperRecipient(new SourcedAudience(sender, recipient),
sender.displayName(), recipient.displayName(), message);
sender.lastWhisperTarget(recipient.uuid());
sender.whisperReplyTarget(recipient.uuid());
recipient.whisperReplyTarget(sender.uuid());
})
.build();
commandManager.command(command);
}
}
@@ -55,6 +55,7 @@ public class ReplyCommand {
messageService.whisperRecipient(new SourcedAudience(sender, recipient),
sender.displayName(), recipient.displayName(), message);
sender.lastWhisperTarget(recipient.uuid());
sender.whisperReplyTarget(recipient.uuid());
recipient.whisperReplyTarget(sender.uuid());
})
@@ -40,6 +40,7 @@ public class WhisperCommand {
messageService.whisperRecipient(new SourcedAudience(sender, recipient),
sender.displayName(), recipient.displayName(), message);
sender.lastWhisperTarget(recipient.uuid());
sender.whisperReplyTarget(recipient.uuid());
recipient.whisperReplyTarget(sender.uuid());
}) // TODO: let command name and aliases be configurable, because why not
@@ -76,4 +76,16 @@ public interface CarbonMessageService {
@Placeholder Component senderDisplayName
);
@Message("continue.target.missing")
void whisperTargetNotSet(
final Audience audience,
@Placeholder Component senderDisplayName
);
@Message("continue.target.offline")
void whisperTargetOffline(
final Audience audience,
@Placeholder Component senderDisplayName
);
}
@@ -27,6 +27,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
protected @MonotonicNonNull String username;
protected @MonotonicNonNull UUID uuid;
protected @Nullable UUID whisperReplyTarget = null;
protected @Nullable UUID lastWhisperTarget = null;
public CarbonPlayerCommon(
final @Nullable Component displayName,
@@ -141,6 +142,16 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
this.whisperReplyTarget = uuid;
}
@Override
public @Nullable UUID lastWhisperTarget() {
return this.lastWhisperTarget;
}
@Override
public void lastWhisperTarget(@Nullable UUID uuid) {
this.lastWhisperTarget = uuid;
}
@Override
public Identity identity() {
return Identity.identity(this.uuid);
@@ -9,3 +9,6 @@ whisper.from=<gold>[<green><senderDisplayName></green>] -> [<green>You</green>]
reply.target.missing=<red>You have no-one to reply to.
reply.target.offline=<red>That person is offline.
reply.target.self=<red>You cannot whisper to yourself.
continue.target.missing=<red>You have no one to whisper.
continue.target.offline=<red>That person is offline.
continue.target.self=<red>You cannot whisper to yourself.