diff --git a/api/src/main/java/net/draycia/carbon/api/users/CarbonPlayer.java b/api/src/main/java/net/draycia/carbon/api/users/CarbonPlayer.java index 0213c3dd..41746ee8 100644 --- a/api/src/main/java/net/draycia/carbon/api/users/CarbonPlayer.java +++ b/api/src/main/java/net/draycia/carbon/api/users/CarbonPlayer.java @@ -230,6 +230,24 @@ public interface CarbonPlayer extends Audience, Identified { final @Nullable String reason ); + /** + * Checks if the sender is being ignored by this player. + * + * @param sender the potential source of a message + * @return if this player is ignoring the sender + * @since 2.0.0 + */ + boolean ignoring(final CarbonPlayer sender); + + /** + * Adds the player to and removes the player from the ignore list. + * + * @param player the player to be added/removed + * @param nowIgnoring if the player should be ignored + * @since 2.0.0 + */ + void ignoring(final CarbonPlayer player, boolean nowIgnoring); + /** * Returns if the player is deafened and unable to read messages. * diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/IgnoreCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/IgnoreCommand.java new file mode 100644 index 00000000..35150b58 --- /dev/null +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/IgnoreCommand.java @@ -0,0 +1,80 @@ +/* + * CarbonChat + * + * Copyright (c) 2021 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 cloud.commandframework.CommandManager; +import cloud.commandframework.arguments.standard.UUIDArgument; +import com.google.inject.Inject; +import java.util.Objects; +import java.util.UUID; +import net.draycia.carbon.api.CarbonChat; +import net.draycia.carbon.api.users.CarbonPlayer; +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 org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; + +@DefaultQualifier(NonNull.class) +public class IgnoreCommand { + + @Inject + public IgnoreCommand( + final CommandManager commandManager, + final CarbonMessageService messageService, + final CarbonChat carbonChat, + final CarbonPlayerArgument carbonPlayerArgument + ) { + final var command = commandManager.commandBuilder("ignore") + .argument(carbonPlayerArgument.newInstance(false, "player", CarbonPlayerArgument.NO_SENDER)) + .flag(commandManager.flagBuilder("uuid") + .withAliases("u") + .withArgument(UUIDArgument.optional("uuid")) + ) + .permission("carbon.ignore.ignore") + .senderType(PlayerCommander.class) + .handler(handler -> { + final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer(); + final CarbonPlayer target; + + if (handler.contains("player")) { + target = handler.get("player"); + } else if (handler.flags().contains("uuid")) { + final var result = carbonChat.server().player(handler.get("uuid")).join(); + target = Objects.requireNonNull(result.player(), "No player found for UUID."); + } else { + throw new IllegalStateException("No target found to unmute."); + } + + if (target.hasPermission("carbon.ignore.exempt")) { + messageService.ignoreExempt(sender, CarbonPlayer.renderName(target)); + return; + } + + sender.ignoring(target, true); + messageService.nowIgnoring(sender, CarbonPlayer.renderName(target)); + }) + .build(); + + commandManager.command(command); + } + +} diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/UnignoreCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/UnignoreCommand.java new file mode 100644 index 00000000..e6a09415 --- /dev/null +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/UnignoreCommand.java @@ -0,0 +1,75 @@ +/* + * CarbonChat + * + * Copyright (c) 2021 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 cloud.commandframework.CommandManager; +import cloud.commandframework.arguments.standard.UUIDArgument; +import com.google.inject.Inject; +import java.util.Objects; +import java.util.UUID; +import net.draycia.carbon.api.CarbonChat; +import net.draycia.carbon.api.users.CarbonPlayer; +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 org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; + +@DefaultQualifier(NonNull.class) +public class UnignoreCommand { + + @Inject + public UnignoreCommand( + final CommandManager commandManager, + final CarbonMessageService messageService, + final CarbonChat carbonChat, + final CarbonPlayerArgument carbonPlayerArgument + ) { + final var command = commandManager.commandBuilder("unignore") + .argument(carbonPlayerArgument.newInstance(false, "player", CarbonPlayerArgument.NO_SENDER)) + .flag(commandManager.flagBuilder("uuid") + .withAliases("u") + .withArgument(UUIDArgument.optional("uuid")) + ) + .permission("carbon.ignore.unignore") + .senderType(PlayerCommander.class) + .handler(handler -> { + final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer(); + final CarbonPlayer target; + + if (handler.contains("player")) { + target = handler.get("player"); + } else if (handler.flags().contains("uuid")) { + final var result = carbonChat.server().player(handler.get("uuid")).join(); + target = Objects.requireNonNull(result.player(), "No player found for UUID."); + } else { + throw new IllegalStateException("No target found to unmute."); + } + + sender.ignoring(target, true); + messageService.noLongerIgnoring(sender, CarbonPlayer.renderName(target)); + }) + .build(); + + commandManager.command(command); + } + +} diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java index f4109b08..b1a8da2d 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java @@ -290,4 +290,13 @@ public interface CarbonMessageService { @Message("error.command.invalid_syntax") void errorCommandInvalidSyntax(final Audience audience, final @Placeholder Component syntax); + @Message("ignore.exempt") + void ignoreExempt(final Audience audience, final @Placeholder Component target); + + @Message("ignore.now_ignoring") + void nowIgnoring(final Audience audience, final @Placeholder Component target); + + @Message("ignore.no_longer_ignoring") + void noLongerIgnoring(final Audience audience, final @Placeholder Component target); + } diff --git a/common/src/main/java/net/draycia/carbon/common/util/CloudUtils.java b/common/src/main/java/net/draycia/carbon/common/util/CloudUtils.java index 869ca0bd..41767a52 100644 --- a/common/src/main/java/net/draycia/carbon/common/util/CloudUtils.java +++ b/common/src/main/java/net/draycia/carbon/common/util/CloudUtils.java @@ -37,9 +37,11 @@ import net.draycia.carbon.common.command.commands.ClearChatCommand; import net.draycia.carbon.common.command.commands.ContinueCommand; import net.draycia.carbon.common.command.commands.DebugCommand; import net.draycia.carbon.common.command.commands.HelpCommand; +import net.draycia.carbon.common.command.commands.IgnoreCommand; import net.draycia.carbon.common.command.commands.MuteCommand; import net.draycia.carbon.common.command.commands.NicknameCommand; import net.draycia.carbon.common.command.commands.ReplyCommand; +import net.draycia.carbon.common.command.commands.UnignoreCommand; import net.draycia.carbon.common.command.commands.UnmuteCommand; import net.draycia.carbon.common.command.commands.WhisperCommand; import net.draycia.carbon.common.messages.CarbonMessageService; @@ -56,8 +58,8 @@ public final class CloudUtils { private static final Component NULL = Component.text("null"); private static final Pattern SPECIAL_CHARACTERS_PATTERN = Pattern.compile("[^\\s\\w\\-]"); - public static final List> COMMAND_CLASSES = List.of(ClearChatCommand.class, ContinueCommand.class, - DebugCommand.class, HelpCommand.class, MuteCommand.class, NicknameCommand.class, ReplyCommand.class, + public static final List> COMMAND_CLASSES = List.of(ClearChatCommand.class, ContinueCommand.class, DebugCommand.class, + HelpCommand.class, IgnoreCommand.class, MuteCommand.class, NicknameCommand.class, ReplyCommand.class, UnignoreCommand.class, UnmuteCommand.class, WhisperCommand.class); private CloudUtils() { diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties index f1bc4279..093dac3e 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -52,3 +52,6 @@ command.help.click_to_show_help=Click to show help for this command command.help.page_out_of_range=Error: Page is not in range. Must be in range [1, ] command.help.click_for_next_page=Click for next page command.help.click_for_previous_page=Click for previous page +ignore.exempt=You cannot ignore +ignore.now_ignoring=You are now ignoring +ignore.no_longer_ignoring=You are no longer ignoring