diff --git a/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java b/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java index 583333ae..8ebc1d22 100644 --- a/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java +++ b/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java @@ -57,6 +57,7 @@ import net.draycia.carbon.common.command.commands.MuteCommand; import net.draycia.carbon.common.command.commands.MuteInfoCommand; import net.draycia.carbon.common.command.commands.NicknameCommand; import net.draycia.carbon.common.command.commands.PartyCommands; +import net.draycia.carbon.common.command.commands.RealNameCommand; import net.draycia.carbon.common.command.commands.ReloadCommand; import net.draycia.carbon.common.command.commands.ReplyCommand; import net.draycia.carbon.common.command.commands.SpyCommand; @@ -269,6 +270,7 @@ public final class CarbonCommonModule extends AbstractModule { commands.addBinding().to(MuteInfoCommand.class).in(Scopes.SINGLETON); commands.addBinding().to(NicknameCommand.class).in(Scopes.SINGLETON); commands.addBinding().to(ReloadCommand.class).in(Scopes.SINGLETON); + commands.addBinding().to(RealNameCommand.class).in(Scopes.SINGLETON); commands.addBinding().to(ReplyCommand.class).in(Scopes.SINGLETON); commands.addBinding().to(SpyCommand.class).in(Scopes.SINGLETON); commands.addBinding().to(ToggleMessagesCommand.class).in(Scopes.SINGLETON); diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/RealNameCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/RealNameCommand.java new file mode 100644 index 00000000..a08ec14c --- /dev/null +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/RealNameCommand.java @@ -0,0 +1,101 @@ +/* + * CarbonChat + * + * Copyright (c) 2024 Josua Parks (Vicarious) + * Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.draycia.carbon.common.command.commands; + +import com.google.inject.Inject; +import java.util.Locale; +import net.draycia.carbon.api.CarbonServer; +import net.draycia.carbon.api.users.CarbonPlayer; +import net.draycia.carbon.common.command.CarbonCommand; +import net.draycia.carbon.common.command.CommandSettings; +import net.draycia.carbon.common.command.Commander; +import net.draycia.carbon.common.messages.CarbonMessages; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.parser.standard.StringParser; + +import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription; + +@DefaultQualifier(NonNull.class) +public final class RealNameCommand extends CarbonCommand { + + private final CommandManager commandManager; + private final CarbonMessages carbonMessages; + private final CarbonServer server; + + @Inject + public RealNameCommand( + final CommandManager commandManager, + final CarbonMessages carbonMessages, + final CarbonServer server + ) { + this.commandManager = commandManager; + this.carbonMessages = carbonMessages; + this.server = server; + } + + @Override + public CommandSettings defaultCommandSettings() { + return new CommandSettings("realname", "rn"); + } + + @Override + public Key key() { + return Key.key("carbon", "realname"); + } + + @Override + public void init() { + final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases()) + .required("player", StringParser.greedyStringParser(), + richDescription(this.carbonMessages.commandRealNameArgumentPlayer())) + .permission("carbon.realname") + .senderType(Commander.class) + .commandDescription(richDescription(this.carbonMessages.commandRealNameDescription())) + .handler(handler -> { + final String input = handler.get("player").split(" ")[0].toLowerCase(Locale.ENGLISH); + boolean found = false; + + for (final CarbonPlayer player : this.server.players()) { + if (player.vanished() && !handler.sender().hasPermission("carbon.realname.vanished")) { + continue; + } + + final String plainName = PlainTextComponentSerializer.plainText().serialize(player.displayName()).toLowerCase(Locale.ENGLISH); + + if (plainName.contains(input)) { + found = true; + this.carbonMessages.realName(handler.sender(), player.displayName(), player.username()); + } + } + + if (!found) { + this.carbonMessages.realNameTargetInvalid(handler.sender(), input); + } + }) + .build(); + + this.commandManager.command(command); + } + +} diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java index c37f4902..52c07e5a 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java @@ -266,6 +266,12 @@ public interface CarbonMessages { @Message("nickname.reset.others") void nicknameResetOthers(final Audience audience, final String target); + @Message("nickname.realname") + void realName(final Audience audience, final Component target, final String username); + + @Message("nickname.realname.target_invalid") + void realNameTargetInvalid(final Audience audience, final String input); + /* * ============================================================= * ========================== Ignore =========================== @@ -501,6 +507,12 @@ public interface CarbonMessages { @Message("command.whisper.description") Component commandWhisperDescription(); + @Message("command.realname.description") + Component commandRealNameDescription(); + + @Message("command.realname.argument.player") + Component commandRealNameArgumentPlayer(); + @Message("command.updateusername.description") Component commandUpdateUsernameDescription(); diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties index 8fb4d166..edb76b75 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -90,6 +90,8 @@ command.party.accept.description=Accept party invites. command.party.leave.description=Leave your current party. command.party.already_in_party= is already in your party. command.party.disband.description=Disband your current party. +command.realname.description=Shows the player's real name. +command.realname.argument.player=The player's display name. command.spy.enabled=Spying is now enabled. command.spy.disabled=Spying is now disabled. command.spy.description=Allows a player to view all private and channel messages they otherwise wouldn't see. @@ -141,6 +143,7 @@ nickname.show=Your nickname is nickname.error.character_limit=Nickname "" has exceeded the character limit. Must be set to ~ characters. nickname.error.blacklist=Nickname "" is not allowed. Please choose another name. nickname.error.filter=Nicknames must be alphanumeric! +nickname.realname='s real name is reply.target.missing=You have no-one to reply to reply.target.self=You cannot whisper to yourself whisper.console=[] -> []