unify vanish and offline messages

This commit is contained in:
Draycia committed 2021-10-20 20:39:42 -07:00
1 parent e37bad3d92
commit d79b1fd24d
5 files changed
+56 -11

No files matched your search

@@ -10,7 +10,9 @@ 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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.draycia.carbon.common.util.CloudUtils;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -47,7 +49,10 @@ public class ContinueCommand {
}
if (!sender.awareOf(recipient) && !sender.hasPermission("carbon.seevanish.continue")) {
messageService.whisperTargetOffline(sender, CarbonPlayer.renderName(sender));
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.PlayerParseException(rawNameInput);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
}
@@ -10,7 +10,9 @@ 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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.draycia.carbon.common.util.CloudUtils;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -49,7 +51,10 @@ public class ReplyCommand {
}
if (!sender.awareOf(recipient) && !sender.hasPermission("carbon.seevanish.reply")) {
messageService.whisperTargetOffline(sender, CarbonPlayer.renderName(sender));
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.PlayerParseException(rawNameInput);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
}
@@ -9,6 +9,7 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.draycia.carbon.common.util.CloudUtils;
public class WhisperCommand {
@@ -40,7 +41,10 @@ public class WhisperCommand {
}
if (!sender.awareOf(recipient) && !sender.hasPermission("carbon.seevanish.whisper")) {
messageService.whisperTargetOffline(sender, CarbonPlayer.renderName(sender));
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.PlayerParseException(rawNameInput);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
}
@@ -0,0 +1,36 @@
package net.draycia.carbon.common.util;
import java.util.LinkedList;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.ComponentMessageThrowable;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public final class CloudUtils {
private static final Component NULL = Component.text("null");
private CloudUtils() {
}
public static Component message(final Throwable throwable) {
final @Nullable Component msg = ComponentMessageThrowable.getOrConvertMessage(throwable);
return msg == null ? NULL : msg;
}
public static String rawInputByMatchingName(
final LinkedList<String> rawInput,
final CarbonPlayer recipient
) {
return rawInput
.stream()
.filter(it -> it.equalsIgnoreCase(recipient.username()))
.findFirst()
.orElse(recipient.username());
}
}