mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Whispers, part 1
This commit is contained in:
1 parent
bb68ba0923
commit
4693c0d55a
5 files changed
+85
-1
No files matched your search
@@ -3,7 +3,6 @@ package net.draycia.carbon.api.users;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
@@ -191,4 +190,20 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
*/
|
||||
boolean online();
|
||||
|
||||
/**
|
||||
* The UUID of the player that replies will be sent to.
|
||||
*
|
||||
* @return the player's reply target
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Nullable UUID whisperReplyTarget();
|
||||
|
||||
/**
|
||||
* Sets the whisper reply target for this player.
|
||||
*
|
||||
* @param uuid the uuid of the reply target
|
||||
* @since 2.0.0
|
||||
*/
|
||||
void whisperReplyTarget(final @Nullable UUID uuid);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
|
||||
public class WhisperCommand {
|
||||
|
||||
@Inject
|
||||
public WhisperCommand(
|
||||
final Injector injector,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessageService messageService
|
||||
) {
|
||||
var command = commandManager.commandBuilder("whisper", "w", "message", "msg")
|
||||
.argument(StringArgument.greedy("message"))
|
||||
.argument(/* Audience recipient argument */)
|
||||
.permission("carbon.whisper.send") // TODO: carbon.whisper.spy
|
||||
.senderType(CarbonPlayer.class)
|
||||
.handler(handler -> {
|
||||
final String message = handler.get("message");
|
||||
final CarbonPlayer sender = (CarbonPlayer) handler.getSender();
|
||||
final CarbonPlayer recipient = handler.get("recipient");
|
||||
|
||||
if (sender.equals(recipient)) {
|
||||
// TODO: send error message "you cannot whisper yourself!"
|
||||
return;
|
||||
}
|
||||
|
||||
messageService.whisperSender(new SourcedAudience(handler.getSender(), handler.getSender()),
|
||||
sender.displayName(), recipient.displayName());
|
||||
|
||||
messageService.whisperRecipient(new SourcedAudience(handler.getSender(), recipient),
|
||||
sender.displayName(), recipient.displayName());
|
||||
|
||||
sender.whisperReplyTarget(recipient.uuid());
|
||||
recipient.whisperReplyTarget(sender.uuid());
|
||||
})
|
||||
.build();
|
||||
|
||||
commandManager.command(command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.draycia.carbon.common.messages;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.annotation.Message;
|
||||
@@ -41,4 +42,18 @@ public interface CarbonMessageService {
|
||||
@Placeholder final String channel // TODO: allow MiniMessage based channel "names"
|
||||
);
|
||||
|
||||
@Message("whisper.to")
|
||||
void whisperSender(
|
||||
final SourcedAudience audience,
|
||||
@Placeholder Component senderDisplayName,
|
||||
@Placeholder Component recipientDisplayName
|
||||
);
|
||||
|
||||
@Message("whisper.from")
|
||||
void whisperRecipient(
|
||||
final SourcedAudience audience,
|
||||
@Placeholder Component senderDisplayName,
|
||||
@Placeholder Component recipientDisplayName
|
||||
);
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ package net.draycia.carbon.common.messages;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import javax.inject.Singleton;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.moonshine.receiver.IReceiverLocator;
|
||||
import net.kyori.moonshine.receiver.IReceiverLocatorResolver;
|
||||
@@ -45,6 +46,8 @@ public final class ReceiverResolver implements IReceiverLocatorResolver<Audience
|
||||
for (final Object parameter : parameters) {
|
||||
if (parameter instanceof Audience audience) {
|
||||
return audience;
|
||||
} else if (parameter instanceof SourcedAudience sourcedAudience) {
|
||||
return sourcedAudience.recipient();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,3 +4,5 @@ mute.spy.prefix=<red><hover:show_text:<red>Muted</red>M</hover></red>
|
||||
test.phrase=English: Has anyone really been far even as decided to use even go want to do look more like?
|
||||
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message: '<message>'
|
||||
channel.change=<green>You are now messaging </green><channel><green> chat!</green>
|
||||
whisper.to=<gold>[<green>You</green>] -> [<green><recipientDisplayName></green>] <message>
|
||||
whisper.from=<gold>[<green><senderDisplayName></green>] -> [<green>You</green>] <message>
|
||||
Reference in new issue
Block a user