Skip to content

Commit

Permalink
Add set subcommand to the tags admin command
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolai committed Feb 21, 2021
1 parent 1af1598 commit a273f7c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface MessageService extends Service {

Component commandAdminList(@NonNull Collection<Tag> tags);

Component commandAdminSet(@NonNull Tag tag, @NonNull TagsUser target);

Component commandErrorUserNotFound(@NonNull String input);

Component commandErrorTagNotFound(@NonNull String input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import cloud.commandframework.CommandManager;
import cloud.commandframework.context.CommandContext;
import com.google.inject.Inject;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Collection;

import org.checkerframework.checker.nullness.qual.NonNull;

public final class TagsAdminCommand implements PluginCommand {

private final @NonNull CloudArgumentFactory argumentFactory;
Expand Down Expand Up @@ -65,6 +66,14 @@ public void register(
.argument(this.argumentFactory.user("target", false))
.handler(this::handleList)
);

commandManager.command(tagsCommand
.literal("set")
.permission("tags.command.admin.set")
.argument(this.argumentFactory.user("target", true))
.argument(this.argumentFactory.tag("tag", TagParserMode.TARGET))
.handler(this::handleSet)
);
}

private void handleGive(final @NonNull CommandContext<CommandUser> context) {
Expand Down Expand Up @@ -94,4 +103,13 @@ private void handleList(final @NonNull CommandContext<CommandUser> context) {
sender.sendMessage(this.messageService.commandAdminList(tags));
}

private void handleSet(final @NonNull CommandContext<CommandUser> context) {
CommandUser sender = context.getSender();
TagsUser target = context.get("target");
Tag tag = context.get("tag");

target.setCurrent(tag);
sender.sendMessage(this.messageService.commandAdminSet(tag, target));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static final class AdminFeedbackLocaleConfiguration {
@Setting
public LocaleEntry remove = new BasicLocaleEntry("<prefix> Tag <tag> has been removed from <target>");

@Setting
public LocaleEntry set = new BasicLocaleEntry("<prefix> <target> had their tag set to <tag>");

}

@ConfigSerializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ public Component commandAdminList(final @NonNull Collection<Tag> tags) {
return component;
}

@Override
public Component commandAdminSet(@NonNull final Tag tag, @NonNull final TagsUser target) {
Template tagTemplate = Template.of("tag", tag.component());
Template targetTemplate = Template.of("target", this.nameFromUser(target));

return this.locale.commands.admin.list.asComponent(this.prefix(), tagTemplate, targetTemplate);
}

@Override
public Component commandErrorUserNotFound(final @NonNull String input) {
Template inputTemplate = Template.of("input", input);
Expand Down

0 comments on commit a273f7c

Please sign in to comment.