Allow configuration of commands

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