Ignore and Unignore commands

Adds API for ignored players
This commit is contained in:
Draycia authored and Josua Parks committed 2021-11-30 12:04:56 -08:00
1 parent 20e384522e
commit ad2b7be13d
6 files changed
+189 -2

No files matched your search

@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Commander> 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.<UUID>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);
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Commander> 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.<UUID>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);
}
}
@@ -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);
}
@@ -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<Class<?>> COMMAND_CLASSES = List.of(ClearChatCommand.class, ContinueCommand.class,
DebugCommand.class, HelpCommand.class, MuteCommand.class, NicknameCommand.class, ReplyCommand.class,
public static final List<Class<?>> 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() {