mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Ignore and Unignore commands
Adds API for ignored players
This commit is contained in:
1 parent
20e384522e
commit
ad2b7be13d
6 files changed
+189
-2
No files matched your search
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 <page> is not in range. Must be in range [1, <max_pages>]
|
||||
command.help.click_for_next_page=Click for next page
|
||||
command.help.click_for_previous_page=Click for previous page
|
||||
ignore.exempt=<red>You cannot ignore <target>
|
||||
ignore.now_ignoring=<green>You are now ignoring <target>
|
||||
ignore.no_longer_ignoring=<green>You are no longer ignoring <target>
|
||||
Reference in new issue
Block a user