Add a confirmation system.

This commit is contained in:
Alexander Söderberg 2020-09-22 23:03:11 +02:00
parent 77cbf15faa
commit 3f59a81836
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
8 changed files with 266 additions and 3 deletions

View file

@ -32,7 +32,9 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParser;
import com.intellectualsites.commands.arguments.parser.ParserParameters;
import com.intellectualsites.commands.arguments.parser.StandardParameters;
import com.intellectualsites.commands.execution.CommandExecutionHandler;
import com.intellectualsites.commands.extra.confirmation.CommandConfirmationManager;
import com.intellectualsites.commands.meta.CommandMeta;
import com.intellectualsites.commands.meta.SimpleCommandMeta;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -140,10 +142,15 @@ public final class AnnotationParser<C> {
/* Determine command name */
final String commandToken = commandMethod.value().split(" ")[0].split("\\|")[0];
@SuppressWarnings("ALL") final CommandManager manager = this.manager;
final SimpleCommandMeta.Builder metaBuilder = SimpleCommandMeta.builder()
.with(this.metaFactory.apply(method.getAnnotations()));
if (method.isAnnotationPresent(Confirmation.class)) {
metaBuilder.with(CommandConfirmationManager.CONFIRMATION_REQUIRED_META, "true");
}
@SuppressWarnings("ALL")
Command.Builder builder = manager.commandBuilder(commandToken,
tokens.get(commandToken).getMinor(),
this.metaFactory.apply(method.getAnnotations()));
metaBuilder.build());
final Collection<ArgumentParameterPair> arguments = this.argumentExtractor.apply(method);
final Map<String, CommandArgument<C, ?>> commandArguments = Maps.newHashMap();
final Map<CommandArgument<C, ?>, String> argumentDescriptions = Maps.newHashMap();

View file

@ -0,0 +1,37 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Require confirmation for the command
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Confirmation {
}