Whispers, part 1

This commit is contained in:
Draycia committed 2021-09-17 22:03:53 -07:00
1 parent bb68ba0923
commit 4693c0d55a
5 files changed
+85 -1

No files matched your search

@@ -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();
}
}