mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
whisper continue command
This commit is contained in:
1 parent
662d327400
commit
44c58eeec4
9 files changed
+125
-2
No files matched your search
@@ -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.
|
||||
Reference in new issue
Block a user