Merge pull request #184 from Hexaoxide/feat/command-settings

This commit is contained in:
Josua Parks authored and GitHub committed 2022-01-01 19:42:03 -08:00
commit a35f012ef6
23 files changed
+754 -197

No files matched your search

@@ -111,7 +111,10 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
ListenerUtils.registerCommonListeners(this.injector);
// Commands
CloudUtils.registerCommands(this.injector);
// This is a bit awkward looking
CloudUtils.loadCommands(this.injector);
final var commandSettings = CloudUtils.loadCommandSettings(this.injector);
CloudUtils.registerCommands(commandSettings);
// Player data saving
final long saveDelay = 5 * 60 * 20;
@@ -0,0 +1,47 @@
/*
* 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;
import java.util.Objects;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public abstract class CarbonCommand {
private @Nullable CommandSettings commandSettings = null;
public CommandSettings commandSettings() {
return Objects.requireNonNullElseGet(this.commandSettings, this::_commandSettings);
}
public void commandSettings(final @NonNull CommandSettings commandSettings) {
this.commandSettings = commandSettings;
}
public abstract void init();
protected abstract CommandSettings _commandSettings();
public abstract Key key();
}
@@ -0,0 +1,57 @@
/*
* 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;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigSerializable
public class CommandSettings {
private boolean enabled = true;
private String name = "";
private String[] aliases = new String[0];
public CommandSettings() {
}
public CommandSettings(final boolean enabled, final String name, final String... aliases) {
this.enabled = enabled;
this.name = name;
this.aliases = aliases;
}
public CommandSettings(final String name, final String... aliases) {
this(true, name, aliases);
}
public boolean enabled() {
return this.enabled;
}
public String name() {
return this.name;
}
public String[] aliases() {
return this.aliases;
}
}
@@ -24,13 +24,24 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonChat;
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.command.PlayerCommander;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
public class ClearChatCommand {
@DefaultQualifier(NonNull.class)
public class ClearChatCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final ConfigFactory configFactory;
final CarbonMessageService messageService;
@Inject
public ClearChatCommand(
@@ -39,17 +50,35 @@ public class ClearChatCommand {
final ConfigFactory configFactory,
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("clearchat", "chatclear", "cc")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.configFactory = configFactory;
this.messageService = messageService;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("clearchat", "chatclear", "cc");
}
@Override
public Key key() {
return Key.key("carbon", "clearchat");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.permission("carbon.clearchat.clear")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandClearChatDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandClearChatDescription().component())
.handler(handler -> {
// Not fond of having to send 50 messages to each player
// Are we not able to just paste in 50 newlines and call it a day?
for (int i = 0; i < configFactory.primaryConfig().clearChatSettings().iterations(); i++) {
for (final var player : carbonChat.server().players()) {
for (int i = 0; i < this.configFactory.primaryConfig().clearChatSettings().iterations(); i++) {
for (final var player : this.carbonChat.server().players()) {
if (!player.hasPermission("carbon.clearchat.exempt")) {
player.sendMessage(configFactory.primaryConfig().clearChatSettings().message());
player.sendMessage(this.configFactory.primaryConfig().clearChatSettings().message());
}
}
}
@@ -65,12 +94,12 @@ public class ClearChatCommand {
username = "Console";
}
carbonChat.server().sendMessage(configFactory.primaryConfig().clearChatSettings()
this.carbonChat.server().sendMessage(this.configFactory.primaryConfig().clearChatSettings()
.broadcast(senderName, username));
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -29,34 +29,60 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.util.SourcedAudience;
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.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 net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
public class ContinueCommand {
@DefaultQualifier(NonNull.class)
public class ContinueCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
@Inject
public ContinueCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("continue", "c")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("continue", "c");
}
@Override
public Key key() {
return Key.key("carbon", "continue");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandContinueArgumentMessage().component()))
RichDescription.of(this.messageService.commandContinueArgumentMessage().component()))
.permission("carbon.whisper.continue")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandContinueDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandContinueDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
if (sender.muted()) {
messageService.muteCannotSpeak(sender);
this.messageService.muteCannotSpeak(sender);
return;
}
@@ -64,16 +90,16 @@ public class ContinueCommand {
final UUID whisperTarget = sender.lastWhisperTarget();
if (whisperTarget == null) {
messageService.whisperTargetNotSet(sender, CarbonPlayer.renderName(sender));
this.messageService.whisperTargetNotSet(sender, CarbonPlayer.renderName(sender));
return;
}
final ComponentPlayerResult<@NonNull CarbonPlayer> result = carbonChat.server()
final ComponentPlayerResult<@NonNull CarbonPlayer> result = this.carbonChat.server()
.player(whisperTarget).join();
final @MonotonicNonNull CarbonPlayer recipient = result.player();
if (sender.equals(recipient)) {
messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
this.messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
return;
}
@@ -82,28 +108,28 @@ public class ContinueCommand {
&& !sender.hasPermission("carbon.whisper.vanished"))
) {
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, messageService);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, this.messageService);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
this.messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
}
if (sender.ignoring(recipient)) {
messageService.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
this.messageService.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
return;
}
if (recipient.ignoring(sender)) {
messageService.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
this.messageService.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
return;
}
final Component senderName = CarbonPlayer.renderName(sender);
final Component recipientName = CarbonPlayer.renderName(recipient);
messageService.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, message);
messageService.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, message);
messageService.whisperConsoleLog(carbonChat.server().console(), senderName, recipientName, message);
this.messageService.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, message);
this.messageService.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, message);
this.messageService.whisperConsoleLog(this.carbonChat.server().console(), senderName, recipientName, message);
sender.lastWhisperTarget(recipient.uuid());
sender.whisperReplyTarget(recipient.uuid());
@@ -111,7 +137,7 @@ public class ContinueCommand {
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -25,29 +25,56 @@ import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.ArrayList;
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.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
public class DebugCommand {
@DefaultQualifier(NonNull.class)
public class DebugCommand extends CarbonCommand {
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public DebugCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("carbondebug", "cdebug")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandDebugArgumentPlayer().component()))
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("carbondebug", "cdebug");
}
@Override
public Key key() {
return Key.key("carbon", "debug");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional(),
RichDescription.of(this.messageService.commandDebugArgumentPlayer().component()))
.permission("carbon.debug")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandDebugDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandDebugDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -84,7 +111,7 @@ public class DebugCommand {
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -28,9 +28,12 @@ import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.List;
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.CarbonMessageService;
import net.draycia.carbon.common.messages.CarbonMessageSource;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
import net.kyori.adventure.text.minimessage.placeholder.PlaceholderResolver;
@@ -44,10 +47,11 @@ import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
import static net.kyori.adventure.text.format.TextColor.color;
@DefaultQualifier(NonNull.class)
public final class HelpCommand {
public final class HelpCommand extends CarbonCommand {
private final CommandManager<Commander> manager;
private final MinecraftHelp<Commander> help;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final MinecraftHelp<Commander> minecraftHelp;
@Inject
public HelpCommand(
@@ -55,28 +59,42 @@ public final class HelpCommand {
final CarbonMessageSource messageSource,
final CarbonMessageService messageService
) {
this.manager = commandManager;
this.help = createHelp(commandManager, messageSource);
this.commandManager = commandManager;
this.messageService = messageService;
this.minecraftHelp = createHelp(commandManager, messageSource);
}
final var command = commandManager.commandBuilder("carbon")
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("carbon");
}
@Override
public Key key() {
return Key.key("carbon", "help");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.literal("help",
RichDescription.of(messageService.commandHelpDescription().component()))
RichDescription.of(this.messageService.commandHelpDescription().component()))
.argument(StringArgument.<Commander>newBuilder("query")
.greedy().withSuggestionsProvider(this::suggestQueries).asOptional(),
RichDescription.of(messageService.commandHelpArgumentQuery().component()))
RichDescription.of(this.messageService.commandHelpArgumentQuery().component()))
.permission("carbon.help")
.handler(this::execute)
.build();
commandManager.command(command);
this.commandManager.command(command);
}
private void execute(final CommandContext<Commander> ctx) {
this.help.queryCommands(ctx.getOrDefault("query", ""), ctx.getSender());
this.minecraftHelp.queryCommands(ctx.getOrDefault("query", ""), ctx.getSender());
}
private List<String> suggestQueries(final CommandContext<Commander> ctx, final String input) {
final var topic = (CommandHelpHandler.IndexHelpTopic<Commander>) this.manager.getCommandHelpHandler().queryHelp(ctx.getSender(), "");
final var topic = (CommandHelpHandler.IndexHelpTopic<Commander>) this.commandManager.getCommandHelpHandler().queryHelp(ctx.getSender(), "");
return topic.getEntries().stream().map(CommandHelpHandler.VerboseHelpEntry::getSyntaxString).toList();
}
@@ -28,35 +28,61 @@ 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.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
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.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class IgnoreCommand {
public class IgnoreCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public IgnoreCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("ignore", "block")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandIgnoreArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("ignore", "block");
}
@Override
public Key key() {
return Key.key("carbon", "ignore");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional(),
RichDescription.of(this.messageService.commandIgnoreArgumentPlayer().component()))
.flag(this.commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(RichDescription.of(messageService.commandIgnoreArgumentUUID().component()))
.withDescription(RichDescription.of(this.messageService.commandIgnoreArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.ignore")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandIgnoreDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandIgnoreDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -64,24 +90,24 @@ public class IgnoreCommand {
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();
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
} else {
messageService.ignoreTargetInvalid(sender);
this.messageService.ignoreTargetInvalid(sender);
return;
}
if (target.hasPermission("carbon.ignore.exempt")) {
messageService.ignoreExempt(sender, CarbonPlayer.renderName(target));
this.messageService.ignoreExempt(sender, CarbonPlayer.renderName(target));
return;
}
sender.ignoring(target, true);
messageService.nowIgnoring(sender, CarbonPlayer.renderName(target));
this.messageService.nowIgnoring(sender, CarbonPlayer.renderName(target));
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -28,35 +28,61 @@ 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.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
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.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class MuteCommand {
public class MuteCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public MuteCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("mute")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandMuteArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("mute");
}
@Override
public Key key() {
return Key.key("carbon", "mute");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional(),
RichDescription.of(this.messageService.commandMuteArgumentPlayer().component()))
.flag(this.commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(RichDescription.of(messageService.commandMuteArgumentUUID().component()))
.withDescription(RichDescription.of(this.messageService.commandMuteArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.mute")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandMuteDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandMuteDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -64,34 +90,34 @@ public class MuteCommand {
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();
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
} else {
messageService.muteNoTarget(sender);
this.messageService.muteNoTarget(sender);
// TODO: send command syntax
return;
}
if (target.hasPermission("carbon.mute.exempt")) {
messageService.muteExempt(sender);
this.messageService.muteExempt(sender);
return;
}
messageService.muteAlertRecipient(target);
this.messageService.muteAlertRecipient(target);
for (final var player : carbonChat.server().players()) {
for (final var player : this.carbonChat.server().players()) {
if (!player.equals(sender) && !player.hasPermission("carbon.mute.notify")) {
continue;
}
messageService.muteAlertPlayers(player, CarbonPlayer.renderName(target));
this.messageService.muteAlertPlayers(player, CarbonPlayer.renderName(target));
}
target.muted(true);
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -28,35 +28,61 @@ 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.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
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.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class MuteInfoCommand {
public class MuteInfoCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public MuteInfoCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("muteinfo", "muted")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandMuteInfoArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("muteinfo", "muted");
}
@Override
public Key key() {
return Key.key("carbon", "muteinfo");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional(),
RichDescription.of(this.messageService.commandMuteInfoArgumentPlayer().component()))
.flag(this.commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(RichDescription.of(messageService.commandMuteInfoArgumentUUID().component()))
.withDescription(RichDescription.of(this.messageService.commandMuteInfoArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.mute.info")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandMuteInfoDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandMuteInfoDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -64,7 +90,7 @@ public class MuteInfoCommand {
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();
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
} else {
target = sender;
@@ -72,25 +98,25 @@ public class MuteInfoCommand {
if (!target.muted()) {
if (sender.equals(target)) {
messageService.muteInfoSelfNotMuted(sender);
this.messageService.muteInfoSelfNotMuted(sender);
} else {
messageService.muteInfoNotMuted(sender, CarbonPlayer.renderName(target));
this.messageService.muteInfoNotMuted(sender, CarbonPlayer.renderName(target));
}
return;
} else {
if (sender.equals(target)) {
messageService.muteInfoSelfMuted(sender);
this.messageService.muteInfoSelfMuted(sender);
} else {
messageService.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
this.messageService.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
}
}
messageService.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
this.messageService.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -26,48 +26,75 @@ import cloud.commandframework.minecraft.extras.RichDescription;
import cloud.commandframework.permission.Permission;
import com.google.inject.Inject;
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.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.OptionValueParser;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
public class NicknameCommand {
@DefaultQualifier(NonNull.class)
public class NicknameCommand extends CarbonCommand {
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public NicknameCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("nickname", "nick")
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("nickname", "nick");
}
@Override
public Key key() {
return Key.key("carbon", "nickname");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
// TODO: Allow UUID input for target player
.flag(commandManager.flagBuilder("player")
.flag(this.commandManager.flagBuilder("player")
.withAliases("p")
.withDescription(RichDescription.of(messageService.commandNicknameArgumentPlayer().component()))
.withArgument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional())
.withDescription(RichDescription.of(this.messageService.commandNicknameArgumentPlayer().component()))
.withArgument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional())
.withPermission(Permission.of("carbon.nickname.others"))
)
.flag(commandManager.flagBuilder("nickname")
.flag(this.commandManager.flagBuilder("nickname")
.withAliases("n")
.withDescription(RichDescription.of(messageService.commandNicknameArgumentNickname().component()))
.withDescription(RichDescription.of(this.messageService.commandNicknameArgumentNickname().component()))
.withArgument(FlagArgument.<Commander, String>ofType(String.class, "value")
.withParser(new OptionValueParser<>())
.asOptional()
.build())
.withPermission(Permission.of("carbon.nickname.set"))
)
.flag(commandManager.flagBuilder("reset")
.flag(this.commandManager.flagBuilder("reset")
.withAliases("r")
.withDescription(RichDescription.of(messageService.commandNicknameArgumentReset().component()))
.withDescription(RichDescription.of(this.messageService.commandNicknameArgumentReset().component()))
.withPermission(Permission.of("carbon.nickname.set"))
)
.permission("carbon.nickname")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandNicknameDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandNicknameDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
@@ -77,10 +104,10 @@ public class NicknameCommand {
target.displayName(null);
messageService.nicknameReset(target);
this.messageService.nicknameReset(target);
if (sender != target) {
messageService.nicknameResetOthers(sender, target.username());
this.messageService.nicknameResetOthers(sender, target.username());
}
return;
@@ -95,44 +122,44 @@ public class NicknameCommand {
// Setting other player's nickname
if (target != null && !target.equals(sender)) {
target.displayName(nickname);
messageService.nicknameSet(target, nickname);
messageService.nicknameSetOthers(sender, target.username(), nickname);
this.messageService.nicknameSet(target, nickname);
this.messageService.nicknameSetOthers(sender, target.username(), nickname);
} else {
// Setting own nickname
if (!sender.hasPermission("carbon.nickname.self")) {
messageService.nicknameCannotSetOwn(sender);
this.messageService.nicknameCannotSetOwn(sender);
return;
}
sender.displayName(nickname);
messageService.nicknameSet(sender, nickname);
this.messageService.nicknameSet(sender, nickname);
}
} else if (handler.flags().contains("player")) {
// Checking other player's nickname
final CarbonPlayer target = handler.flags().get("player");
if (target.displayName() != null) {
messageService.nicknameShowOthers(sender, target.username(), target.displayName());
this.messageService.nicknameShowOthers(sender, target.username(), target.displayName());
} else {
messageService.nicknameShowOthersUnset(sender, target.username());
this.messageService.nicknameShowOthersUnset(sender, target.username());
}
} else {
// Checking own nickname
if (!sender.hasPermission("carbon.nickname.self")) {
messageService.nicknameCannotSeeOwn(sender);
this.messageService.nicknameCannotSeeOwn(sender);
return;
}
if (sender.displayName() != null) {
messageService.nicknameShow(sender, sender.username(), sender.displayName());
this.messageService.nicknameShow(sender, sender.username(), sender.displayName());
} else {
messageService.nicknameShowUnset(sender, sender.username());
this.messageService.nicknameShowUnset(sender, sender.username());
}
}
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -23,14 +23,21 @@ import cloud.commandframework.CommandManager;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonChat;
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.events.CarbonReloadEvent;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class ReloadCommand {
public class ReloadCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
@Inject
public ReloadCommand(
@@ -38,18 +45,36 @@ public class ReloadCommand {
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("creload", "carbonreload")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("carbon");
}
@Override
public Key key() {
return Key.key("carbon", "reload");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.literal("reload")
.permission("carbon.reload")
.senderType(Commander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandReloadDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandReloadDescription().component())
.handler(handler -> {
// TODO: Check if all listeners succeeded
carbonChat.eventHandler().emit(new CarbonReloadEvent());
messageService.configReloaded(handler.getSender());
this.carbonChat.eventHandler().emit(new CarbonReloadEvent());
this.messageService.configReloaded(handler.getSender());
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -29,11 +29,14 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.util.SourcedAudience;
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.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 net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -41,25 +44,46 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class ReplyCommand {
public class ReplyCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
@Inject
public ReplyCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("reply", "r")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("reply", "r");
}
@Override
public Key key() {
return Key.key("carbon", "reply");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandReplyArgumentMessage().component()))
RichDescription.of(this.messageService.commandReplyArgumentMessage().component()))
.permission("carbon.whisper.reply")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandReplyDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandReplyDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
if (sender.muted()) {
messageService.muteCannotSpeak(sender);
this.messageService.muteCannotSpeak(sender);
return;
}
@@ -67,15 +91,15 @@ public class ReplyCommand {
final @Nullable UUID replyTarget = sender.whisperReplyTarget();
if (replyTarget == null) {
messageService.replyTargetNotSet(sender, CarbonPlayer.renderName(sender));
this.messageService.replyTargetNotSet(sender, CarbonPlayer.renderName(sender));
return;
}
final ComponentPlayerResult<CarbonPlayer> result = carbonChat.server().player(replyTarget).join();
final ComponentPlayerResult<CarbonPlayer> result = this.carbonChat.server().player(replyTarget).join();
final @MonotonicNonNull CarbonPlayer recipient = result.player();
if (sender.equals(recipient)) {
messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
this.messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
return;
}
@@ -84,28 +108,28 @@ public class ReplyCommand {
&& !sender.hasPermission("carbon.whisper.vanished"))
) {
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, messageService);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, this.messageService);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
this.messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
}
if (sender.ignoring(recipient)) {
messageService.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
this.messageService.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
return;
}
if (recipient.ignoring(sender)) {
messageService.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
this.messageService.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
return;
}
final Component senderName = CarbonPlayer.renderName(sender);
final Component recipientName = CarbonPlayer.renderName(recipient);
messageService.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, message);
messageService.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, message);
messageService.whisperConsoleLog(carbonChat.server().console(), senderName, recipientName, message);
this.messageService.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, message);
this.messageService.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, message);
this.messageService.whisperConsoleLog(this.carbonChat.server().console(), senderName, recipientName, message);
sender.lastWhisperTarget(recipient.uuid());
sender.whisperReplyTarget(recipient.uuid());
@@ -113,7 +137,7 @@ public class ReplyCommand {
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -28,36 +28,62 @@ 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.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
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.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class UnignoreCommand {
public class UnignoreCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public UnignoreCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("unignore", "unblock")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("unignore", "unblock");
}
@Override
public Key key() {
return Key.key("carbon", "unignore");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
// TODO: Filter, and only show muted players, but allow inputting any player name.
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandUnignoreArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional(),
RichDescription.of(this.messageService.commandUnignoreArgumentPlayer().component()))
.flag(this.commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(RichDescription.of(messageService.commandUnignoreArgumentUUID().component()))
.withDescription(RichDescription.of(this.messageService.commandUnignoreArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.ignore.unignore")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandUnignoreDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandUnignoreDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -65,19 +91,19 @@ public class UnignoreCommand {
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();
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
} else {
messageService.ignoreTargetInvalid(sender);
this.messageService.ignoreTargetInvalid(sender);
return;
}
sender.ignoring(target, false);
messageService.noLongerIgnoring(sender, CarbonPlayer.renderName(target));
this.messageService.noLongerIgnoring(sender, CarbonPlayer.renderName(target));
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -28,35 +28,61 @@ 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.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
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.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class UnmuteCommand {
public class UnmuteCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public UnmuteCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("unmute")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandUnmuteArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("unmute");
}
@Override
public Key key() {
return Key.key("carbon", "unmute");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asOptional(),
RichDescription.of(this.messageService.commandUnmuteArgumentPlayer().component()))
.flag(this.commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(RichDescription.of(messageService.commandUnmuteArgumentUUID().component()))
.withDescription(RichDescription.of(this.messageService.commandUnmuteArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.mute.unmute")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandUnmuteDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandUnmuteDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -64,29 +90,29 @@ public class UnmuteCommand {
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();
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
} else {
messageService.unmuteNoTarget(sender);
this.messageService.unmuteNoTarget(sender);
// TODO: send command syntax
return;
}
messageService.unmuteAlertRecipient(target);
this.messageService.unmuteAlertRecipient(target);
for (final var player : carbonChat.server().players()) {
for (final var player : this.carbonChat.server().players()) {
if (!player.equals(sender) && !player.hasPermission("carbon.mute.notify")) {
continue;
}
messageService.unmuteAlertPlayers(player, CarbonPlayer.renderName(target));
this.messageService.unmuteAlertPlayers(player, CarbonPlayer.renderName(target));
}
target.muted(false);
})
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -24,39 +24,68 @@ import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.SourcedAudience;
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.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.draycia.carbon.common.util.CloudUtils;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
public class WhisperCommand {
@DefaultQualifier(NonNull.class)
public class WhisperCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CommandManager<Commander> commandManager;
final CarbonMessageService messageService;
final PlayerSuggestions playerSuggestions;
@Inject
public WhisperCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonServer carbonServer,
final PlayerSuggestions suggestionsParser
final PlayerSuggestions playerSuggestions
) {
final var command = commandManager.commandBuilder("whisper", "w", "message", "msg", "m", "tell")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).withSuggestionsProvider(suggestionsParser).asRequired(),
RichDescription.of(messageService.commandWhisperArgumentPlayer().component()))
this.carbonChat = carbonChat;
this.commandManager = commandManager;
this.messageService = messageService;
this.playerSuggestions = playerSuggestions;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("whisper", "w", "message", "msg", "m", "tell");
}
@Override
public Key key() {
return Key.key("carbon", "whisper");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(this.messageService).withSuggestionsProvider(this.playerSuggestions).asRequired(),
RichDescription.of(this.messageService.commandWhisperArgumentPlayer().component()))
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandWhisperArgumentMessage().component()))
RichDescription.of(this.messageService.commandWhisperArgumentMessage().component()))
.permission("carbon.whisper.message")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandWhisperDescription().component())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandWhisperDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
if (sender.muted()) {
messageService.muteCannotSpeak(sender);
this.messageService.muteCannotSpeak(sender);
return;
}
@@ -64,7 +93,7 @@ public class WhisperCommand {
final CarbonPlayer recipient = handler.get("player");
if (sender.equals(recipient)) {
messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
this.messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
return;
}
@@ -73,28 +102,28 @@ public class WhisperCommand {
&& !sender.hasPermission("carbon.whisper.vanished"))
) {
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, messageService);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, this.messageService);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
this.messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
}
if (sender.ignoring(recipient)) {
messageService.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
this.messageService.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
return;
}
if (recipient.ignoring(sender)) {
messageService.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
this.messageService.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
return;
}
final Component senderName = CarbonPlayer.renderName(sender);
final Component recipientName = CarbonPlayer.renderName(recipient);
messageService.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, message);
messageService.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, message);
messageService.whisperConsoleLog(carbonServer.console(), senderName, recipientName, message);
this.messageService.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, message);
this.messageService.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, message);
this.messageService.whisperConsoleLog(this.carbonChat.server().console(), senderName, recipientName, message);
sender.lastWhisperTarget(recipient.uuid());
sender.whisperReplyTarget(recipient.uuid());
@@ -102,7 +131,7 @@ public class WhisperCommand {
}) // TODO: let command name and aliases be configurable, because why not
.build();
commandManager.command(command);
this.commandManager.command(command);
}
}
@@ -0,0 +1,48 @@
/*
* 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.config;
import java.util.Map;
import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.util.CloudUtils;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigSerializable
@DefaultQualifier(MonotonicNonNull.class)
public class CommandConfig {
private Map<Key, CommandSettings> settings = CloudUtils.defaultCommandSettings();
public CommandConfig() {
}
public CommandConfig(final Map<Key, CommandSettings> settings) {
this.settings = settings;
}
public Map<Key, CommandSettings> settings() {
return this.settings;
}
}
@@ -41,7 +41,9 @@ public class ConfigFactory {
private final Path dataDirectory;
private final LocaleSerializerConfigurate locale;
private @Nullable PrimaryConfig primaryConfig = null;
private @Nullable CommandConfig commandSettings = null;
@Inject
public ConfigFactory(
@@ -75,6 +77,24 @@ public class ConfigFactory {
return this.primaryConfig;
}
public @Nullable CommandConfig loadCommandSettings() {
try {
this.commandSettings = this.load(CommandConfig.class, "command-settings.conf");
} catch (final IOException exception) {
exception.printStackTrace();
}
return this.commandSettings;
}
public @Nullable CommandConfig commandSettings() {
if (this.commandSettings == null) {
return this.loadCommandSettings();
}
return this.commandSettings;
}
public ConfigurationLoader<?> configurationLoader(final Path file) {
return HoconConfigurationLoader.builder()
.prettyPrinting(true)
@@ -28,10 +28,15 @@ import cloud.commandframework.exceptions.NoPermissionException;
import com.google.inject.Injector;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
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.command.commands.ClearChatCommand;
import net.draycia.carbon.common.command.commands.ContinueCommand;
@@ -46,7 +51,10 @@ 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.config.CommandConfig;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.util.ComponentMessageThrowable;
@@ -60,18 +68,53 @@ 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, IgnoreCommand.class, MuteCommand.class, MuteInfoCommand.class,
NicknameCommand.class, ReloadCommand.class, ReplyCommand.class, UnignoreCommand.class, UnmuteCommand.class,
WhisperCommand.class);
public static final List<Class<? extends CarbonCommand>> COMMAND_CLASSES = List.of(ClearChatCommand.class,
ContinueCommand.class, DebugCommand.class, HelpCommand.class, IgnoreCommand.class, MuteCommand.class,
MuteInfoCommand.class, NicknameCommand.class, ReloadCommand.class, ReplyCommand.class, UnignoreCommand.class,
UnmuteCommand.class, WhisperCommand.class);
private static final List<CarbonCommand> CONSTRUCTED_COMMANDS = new ArrayList<>();
private CloudUtils() {
}
public static void registerCommands(final Injector injector) {
public static void loadCommands(final Injector injector) {
for (final var commandClass : COMMAND_CLASSES) {
injector.getInstance(commandClass);
final CarbonCommand commandInstance = injector.getInstance(commandClass);
CONSTRUCTED_COMMANDS.add(commandInstance);
// TODO: load from command-settings.conf
}
}
public static Map<Key, CommandSettings> defaultCommandSettings() {
final Map<Key, CommandSettings> settings = new HashMap<>();
for (final var command : CONSTRUCTED_COMMANDS) {
settings.put(command.key(), command.commandSettings());
}
return settings;
}
public static Map<Key, CommandSettings> loadCommandSettings(final Injector injector) {
final @Nullable CommandConfig commandConfig = injector.getInstance(ConfigFactory.class).loadCommandSettings();
if (commandConfig == null) {
return CloudUtils.defaultCommandSettings();
}
return commandConfig.settings();
}
public static void registerCommands(final Map<Key, CommandSettings> settings) {
for (final var command : CONSTRUCTED_COMMANDS) {
command.commandSettings(settings.get(command.key()));
if (command.commandSettings().enabled()) {
command.init();
}
}
}
@@ -99,7 +99,9 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
ListenerUtils.registerCommonListeners(this.injector);
// Commands
CloudUtils.registerCommands(this.injector);
CloudUtils.loadCommands(this.injector);
final var commandSettings = CloudUtils.loadCommandSettings(this.injector);
CloudUtils.registerCommands(commandSettings);
// Load channels
((CarbonChannelRegistry) this.channelRegistry()).loadConfigChannels();
@@ -214,7 +214,9 @@ public final class CarbonChatSponge implements CarbonChat {
});
// Commands
CloudUtils.registerCommands(this.injector);
CloudUtils.loadCommands(this.injector);
final var commandSettings = CloudUtils.loadCommandSettings(this.injector);
CloudUtils.registerCommands(commandSettings);
}
@Listener
@@ -120,9 +120,7 @@ public final class SpongeChatListener {
if (audience instanceof ForwardingAudience forwardingAudience) {
recipients = new ArrayList<>();
for (final var entry : forwardingAudience.audiences()) {
recipients.add(entry);
}
forwardingAudience.forEachAudience(recipients::add);
} else {
recipients = channel.recipients(sender);
}
@@ -114,7 +114,9 @@ public class CarbonChatVelocity implements CarbonChat {
((CarbonChannelRegistry) this.channelRegistry()).loadConfigChannels();
// Commands
CloudUtils.registerCommands(this.injector);
CloudUtils.loadCommands(this.injector);
final var commandSettings = CloudUtils.loadCommandSettings(this.injector);
CloudUtils.registerCommands(commandSettings);
}
@Override