Clean up descriptions
This commit is contained in:
parent
b0cd22886d
commit
3b2ccdca14
10 changed files with 281 additions and 37 deletions
40
README.md
40
README.md
|
|
@ -66,6 +66,7 @@ The code is based on a (W.I.P) paper that can be found [here](https://github.com
|
||||||
- **cloud-minecraft/cloud-paper**: Module that extends cloud-bukkit to add special support for Paper 1.8.8+
|
- **cloud-minecraft/cloud-paper**: Module that extends cloud-bukkit to add special support for Paper 1.8.8+
|
||||||
- **cloud-minecraft/cloud-bungee**: BungeeCord 1.8.8+ implementation of Cloud
|
- **cloud-minecraft/cloud-bungee**: BungeeCord 1.8.8+ implementation of Cloud
|
||||||
- **cloud-minecraft/cloud-velocity**: Velocity v1.1.0 implementation of cloud
|
- **cloud-minecraft/cloud-velocity**: Velocity v1.1.0 implementation of cloud
|
||||||
|
- **cloud-minecraft/cloud-cloudburst**: Cloudburst v1.0.0+ implementation of cloud
|
||||||
|
|
||||||
## links
|
## links
|
||||||
|
|
||||||
|
|
@ -110,6 +111,45 @@ To use `cloud` you will first need to add it as a dependency to your project. Cl
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you are shading in cloud, it is highly recommended that you relocate all of our classes to prevent issues
|
||||||
|
with conflicting dependencies:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.intellectualsites.commands</pattern>
|
||||||
|
<shadedPattern>YOUR.PACKAGE.HERE.cloud</shadedPattern> <!-- Replace this -->
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.intellectualsites.services</pattern>
|
||||||
|
<shadedPattern>YOUR.PACKAGE.HERE.cloud.pipeline</shadedPattern> <!-- Replace this -->
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
```
|
||||||
|
|
||||||
**gradle**:
|
**gradle**:
|
||||||
```groovy
|
```groovy
|
||||||
repositories {
|
repositories {
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,8 @@ public final class AnnotationParser<C> {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.metaFactory = new MetaFactory(this, metaMapper);
|
this.metaFactory = new MetaFactory(this, metaMapper);
|
||||||
this.annotationMappers = Maps.newHashMap();
|
this.annotationMappers = Maps.newHashMap();
|
||||||
this.registerAnnotationMapper(Description.class, d -> ParserParameters.single(StandardParameters.DESCRIPTION, d.value()));
|
this.registerAnnotationMapper(CommandDescription.class, d ->
|
||||||
|
ParserParameters.single(StandardParameters.DESCRIPTION, d.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -181,7 +182,7 @@ public final class AnnotationParser<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String description = argumentDescriptions.getOrDefault(argument, "");
|
final String description = argumentDescriptions.getOrDefault(argument, "");
|
||||||
builder = builder.argument(argument, description);
|
builder = builder.argument(argument, com.intellectualsites.commands.Description.of(description));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Try to find the command sender type */
|
/* Try to find the command sender type */
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import java.lang.annotation.Target;
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
public @interface Description {
|
public @interface CommandDescription {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command description
|
* Command description
|
||||||
|
|
@ -27,6 +27,7 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.StaticArgument;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionHandler;
|
import com.intellectualsites.commands.execution.CommandExecutionHandler;
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
@ -44,10 +45,9 @@ import java.util.function.Consumer;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class Command<C> {
|
public class Command<C> {
|
||||||
|
|
||||||
@Nonnull private final Map<CommandArgument<C, ?>, String> arguments;
|
@Nonnull private final Map<CommandArgument<C, ?>, Description> arguments;
|
||||||
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||||
@Nullable private final Class<? extends C> senderType;
|
@Nullable private final Class<? extends C> senderType;
|
||||||
@Nonnull private final String commandPermission;
|
@Nonnull private final String commandPermission;
|
||||||
|
|
@ -62,7 +62,7 @@ public class Command<C> {
|
||||||
* @param commandPermission Command permission
|
* @param commandPermission Command permission
|
||||||
* @param commandMeta Command meta instance
|
* @param commandMeta Command meta instance
|
||||||
*/
|
*/
|
||||||
public Command(@Nonnull final Map<CommandArgument<C, ?>, String> commandArguments,
|
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nullable final Class<? extends C> senderType,
|
@Nullable final Class<? extends C> senderType,
|
||||||
@Nonnull final String commandPermission,
|
@Nonnull final String commandPermission,
|
||||||
|
|
@ -99,7 +99,7 @@ public class Command<C> {
|
||||||
* @param senderType Required sender type. May be {@code null}
|
* @param senderType Required sender type. May be {@code null}
|
||||||
* @param commandMeta Command meta instance
|
* @param commandMeta Command meta instance
|
||||||
*/
|
*/
|
||||||
public Command(@Nonnull final Map<CommandArgument<C, ?>, String> commandArguments,
|
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nullable final Class<? extends C> senderType,
|
@Nullable final Class<? extends C> senderType,
|
||||||
@Nonnull final CommandMeta commandMeta) {
|
@Nonnull final CommandMeta commandMeta) {
|
||||||
|
|
@ -114,11 +114,33 @@ public class Command<C> {
|
||||||
* @param commandPermission Command permission
|
* @param commandPermission Command permission
|
||||||
* @param commandMeta Command meta instance
|
* @param commandMeta Command meta instance
|
||||||
*/
|
*/
|
||||||
public Command(@Nonnull final Map<CommandArgument<C, ?>, String> commandArguments,
|
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nonnull final String commandPermission,
|
@Nonnull final String commandPermission,
|
||||||
@Nonnull final CommandMeta commandMeta) {
|
@Nonnull final CommandMeta commandMeta) {
|
||||||
this(commandArguments, commandExecutionHandler, null, "", commandMeta);
|
this(commandArguments, commandExecutionHandler, null, commandPermission, commandMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command builder. Is recommended to use the builder methods
|
||||||
|
* in {@link CommandManager} rather than invoking this method directly.
|
||||||
|
*
|
||||||
|
* @param commandName Base command argument
|
||||||
|
* @param commandMeta Command meta instance
|
||||||
|
* @param description Command description
|
||||||
|
* @param aliases Command aliases
|
||||||
|
* @param <C> Command sender type
|
||||||
|
* @return Command builder
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static <C> Builder<C> newBuilder(@Nonnull final String commandName,
|
||||||
|
@Nonnull final CommandMeta commandMeta,
|
||||||
|
@Nonnull final Description description,
|
||||||
|
@Nonnull final String... aliases) {
|
||||||
|
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
|
||||||
|
map.put(StaticArgument.required(commandName, aliases), description);
|
||||||
|
return new Builder<>(null, commandMeta, null, map,
|
||||||
|
new CommandExecutionHandler.NullCommandExecutionHandler<>(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -135,8 +157,8 @@ public class Command<C> {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String commandName,
|
public static <C> Builder<C> newBuilder(@Nonnull final String commandName,
|
||||||
@Nonnull final CommandMeta commandMeta,
|
@Nonnull final CommandMeta commandMeta,
|
||||||
@Nonnull final String... aliases) {
|
@Nonnull final String... aliases) {
|
||||||
final Map<CommandArgument<C, ?>, String> map = new LinkedHashMap<>();
|
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
|
||||||
map.put(StaticArgument.required(commandName, aliases), "");
|
map.put(StaticArgument.required(commandName, aliases), Description.empty());
|
||||||
return new Builder<>(null, commandMeta, null, map,
|
return new Builder<>(null, commandMeta, null, map,
|
||||||
new CommandExecutionHandler.NullCommandExecutionHandler<>(), "");
|
new CommandExecutionHandler.NullCommandExecutionHandler<>(), "");
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +221,7 @@ public class Command<C> {
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getArgumentDescription(@Nonnull final CommandArgument<C, ?> argument) {
|
public String getArgumentDescription(@Nonnull final CommandArgument<C, ?> argument) {
|
||||||
return this.arguments.get(argument);
|
return this.arguments.get(argument).getDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -212,7 +234,7 @@ public class Command<C> {
|
||||||
public static final class Builder<C> {
|
public static final class Builder<C> {
|
||||||
|
|
||||||
@Nonnull private final CommandMeta commandMeta;
|
@Nonnull private final CommandMeta commandMeta;
|
||||||
@Nonnull private final Map<CommandArgument<C, ?>, String> commandArguments;
|
@Nonnull private final Map<CommandArgument<C, ?>, Description> commandArguments;
|
||||||
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||||
@Nullable private final Class<? extends C> senderType;
|
@Nullable private final Class<? extends C> senderType;
|
||||||
@Nonnull private final String commandPermission;
|
@Nonnull private final String commandPermission;
|
||||||
|
|
@ -221,7 +243,7 @@ public class Command<C> {
|
||||||
private Builder(@Nullable final CommandManager<C> commandManager,
|
private Builder(@Nullable final CommandManager<C> commandManager,
|
||||||
@Nonnull final CommandMeta commandMeta,
|
@Nonnull final CommandMeta commandMeta,
|
||||||
@Nullable final Class<? extends C> senderType,
|
@Nullable final Class<? extends C> senderType,
|
||||||
@Nonnull final Map<CommandArgument<C, ?>, String> commandArguments,
|
@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments,
|
||||||
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nonnull final String commandPermission) {
|
@Nonnull final String commandPermission) {
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
|
|
@ -232,6 +254,20 @@ public class Command<C> {
|
||||||
this.commandMeta = Objects.requireNonNull(commandMeta, "Meta may not be null");
|
this.commandMeta = Objects.requireNonNull(commandMeta, "Meta may not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add command meta to the internal command meta map
|
||||||
|
*
|
||||||
|
* @param key Meta key
|
||||||
|
* @param value Meta value
|
||||||
|
* @return New builder instance using the inserted meta key-value pair
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Builder<C> meta(@Nonnull final String key, @Nonnull final String value) {
|
||||||
|
final CommandMeta commandMeta = SimpleCommandMeta.builder().with(this.commandMeta).build();
|
||||||
|
return new Builder<>(this.commandManager, commandMeta, this.senderType, this.commandArguments,
|
||||||
|
this.commandExecutionHandler, this.commandPermission);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supply a command manager instance to the builder. This will be used when attempting to
|
* Supply a command manager instance to the builder. This will be used when attempting to
|
||||||
* retrieve command argument parsers, in the case that they're needed. This
|
* retrieve command argument parsers, in the case that they're needed. This
|
||||||
|
|
@ -258,6 +294,21 @@ public class Command<C> {
|
||||||
return this.argument(StaticArgument.required(main, aliases));
|
return this.argument(StaticArgument.required(main, aliases));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a required {@link StaticArgument} into the command chain
|
||||||
|
*
|
||||||
|
* @param main Main argument name
|
||||||
|
* @param description Literal description
|
||||||
|
* @param aliases Argument aliases
|
||||||
|
* @return New builder instance with the modified command chain
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Builder<C> literal(@Nonnull final String main,
|
||||||
|
@Nonnull final Description description,
|
||||||
|
@Nonnull final String... aliases) {
|
||||||
|
return this.argument(StaticArgument.required(main, aliases), description);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new command argument with an empty description to the command
|
* Add a new command argument with an empty description to the command
|
||||||
*
|
*
|
||||||
|
|
@ -267,7 +318,7 @@ public class Command<C> {
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument) {
|
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument) {
|
||||||
return this.argument(argument, "");
|
return this.argument(argument, Description.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -275,12 +326,13 @@ public class Command<C> {
|
||||||
*
|
*
|
||||||
* @param argument Argument to add
|
* @param argument Argument to add
|
||||||
* @param description Argument description
|
* @param description Argument description
|
||||||
* @param <T> Argument type
|
* @param <T> Argument type
|
||||||
* @return New builder instance with the command argument inserted into the argument list
|
* @return New builder instance with the command argument inserted into the argument list
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument, @Nonnull final String description) {
|
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument,
|
||||||
final Map<CommandArgument<C, ?>, String> commandArgumentMap = new LinkedHashMap<>(this.commandArguments);
|
@Nonnull final Description description) {
|
||||||
|
final Map<CommandArgument<C, ?>, Description> commandArgumentMap = new LinkedHashMap<>(this.commandArguments);
|
||||||
commandArgumentMap.put(argument, description);
|
commandArgumentMap.put(argument, description);
|
||||||
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArgumentMap,
|
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArgumentMap,
|
||||||
this.commandExecutionHandler, this.commandPermission);
|
this.commandExecutionHandler, this.commandPermission);
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,23 @@ public abstract class CommandManager<C> {
|
||||||
*/
|
*/
|
||||||
public abstract boolean hasPermission(@Nonnull C sender, @Nonnull String permission);
|
public abstract boolean hasPermission(@Nonnull C sender, @Nonnull String permission);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command builder
|
||||||
|
*
|
||||||
|
* @param name Command name
|
||||||
|
* @param aliases Command aliases
|
||||||
|
* @param description Command description
|
||||||
|
* @param meta Command meta
|
||||||
|
* @return Builder instance
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
||||||
|
@Nonnull final Collection<String> aliases,
|
||||||
|
@Nonnull final Description description,
|
||||||
|
@Nonnull final CommandMeta meta) {
|
||||||
|
return Command.newBuilder(name, meta, description, aliases.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command builder
|
* Create a new command builder
|
||||||
*
|
*
|
||||||
|
|
@ -232,7 +249,24 @@ public abstract class CommandManager<C> {
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
||||||
@Nonnull final Collection<String> aliases,
|
@Nonnull final Collection<String> aliases,
|
||||||
@Nonnull final CommandMeta meta) {
|
@Nonnull final CommandMeta meta) {
|
||||||
return Command.newBuilder(name, meta, aliases.toArray(new String[0]));
|
return Command.newBuilder(name, meta, Description.empty(), aliases.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command builder
|
||||||
|
*
|
||||||
|
* @param name Command name
|
||||||
|
* @param meta Command meta
|
||||||
|
* @param description Command description
|
||||||
|
* @param aliases Command aliases
|
||||||
|
* @return Builder instance
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
||||||
|
@Nonnull final CommandMeta meta,
|
||||||
|
@Nonnull final Description description,
|
||||||
|
@Nonnull final String... aliases) {
|
||||||
|
return Command.newBuilder(name, meta, description, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -247,21 +281,39 @@ public abstract class CommandManager<C> {
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
||||||
@Nonnull final CommandMeta meta,
|
@Nonnull final CommandMeta meta,
|
||||||
@Nonnull final String... aliases) {
|
@Nonnull final String... aliases) {
|
||||||
return Command.newBuilder(name, meta, aliases);
|
return Command.newBuilder(name, meta, Description.empty(), aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command builder using a default command meta instance.
|
* Create a new command builder using a default command meta instance.
|
||||||
*
|
*
|
||||||
* @param name Command name
|
* @param name Command name
|
||||||
* @param aliases Command aliases
|
* @param description Command description
|
||||||
|
* @param aliases Command aliases
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
||||||
* @see #createDefaultCommandMeta() Default command meta creation
|
* @see #createDefaultCommandMeta() Default command meta creation
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name, @Nonnull final String... aliases) {
|
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
||||||
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), aliases).manager(this);
|
@Nonnull final Description description,
|
||||||
|
@Nonnull final String... aliases) {
|
||||||
|
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), description, aliases).manager(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command builder using a default command meta instance.
|
||||||
|
*
|
||||||
|
* @param name Command name
|
||||||
|
* @param aliases Command aliases
|
||||||
|
* @return Builder instance
|
||||||
|
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
||||||
|
* @see #createDefaultCommandMeta() Default command meta creation
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
||||||
|
@Nonnull final String... aliases) {
|
||||||
|
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), Description.empty(), aliases).manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -344,8 +396,8 @@ public abstract class CommandManager<C> {
|
||||||
/**
|
/**
|
||||||
* Postprocess a command context instance
|
* Postprocess a command context instance
|
||||||
*
|
*
|
||||||
* @param context Command context
|
* @param context Command context
|
||||||
* @param command Command instance
|
* @param command Command instance
|
||||||
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
|
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
|
||||||
* @see #registerCommandPostProcessor(CommandPostprocessor) Register a command postprocessor
|
* @see #registerCommandPostProcessor(CommandPostprocessor) Register a command postprocessor
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link com.intellectualsites.commands.arguments.CommandArgument} description
|
||||||
|
*/
|
||||||
|
public final class Description {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty command description
|
||||||
|
*/
|
||||||
|
private static final Description EMPTY = Description.of("");
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
private Description(@Nonnull final String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an empty command description
|
||||||
|
*
|
||||||
|
* @return Command description
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static Description empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a command description instance
|
||||||
|
*
|
||||||
|
* @param string Command description
|
||||||
|
* @return Created command description
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static Description of(@Nonnull final String string) {
|
||||||
|
return new Description(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command description
|
||||||
|
*
|
||||||
|
* @return Command description
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command description
|
||||||
|
*
|
||||||
|
* @return Command description
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -85,15 +85,15 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
/**
|
/**
|
||||||
* Create a new required command argument with a default value
|
* Create a new required command argument with a default value
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultNum Default num
|
* @param defaultBoolean Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C> CommandArgument<C, Boolean> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Boolean> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final boolean defaultBoolean) {
|
||||||
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(Boolean.toString(defaultBoolean)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -125,4 +125,17 @@ public final class CommandContext<C> {
|
||||||
return (T) value;
|
return (T) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a value if it exists, else return the provided default value
|
||||||
|
*
|
||||||
|
* @param key Argument key
|
||||||
|
* @param defaultValue Default value
|
||||||
|
* @param <T> Argument type
|
||||||
|
* @return Argument, or supplied default value
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public <T> T getOrDefault(@Nonnull final String key, @Nonnull final T defaultValue) {
|
||||||
|
return this.<T>get(key).orElse(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class CommandHelpHandlerTest {
|
||||||
manager.command(manager.commandBuilder("test", meta1).literal("this").literal("thing").build());
|
manager.command(manager.commandBuilder("test", meta1).literal("this").literal("thing").build());
|
||||||
final SimpleCommandMeta meta2 = SimpleCommandMeta.builder().with("description", "Command with variables").build();
|
final SimpleCommandMeta meta2 = SimpleCommandMeta.builder().with("description", "Command with variables").build();
|
||||||
manager.command(manager.commandBuilder("test", meta2).literal("int").
|
manager.command(manager.commandBuilder("test", meta2).literal("int").
|
||||||
argument(IntegerArgument.required("int"), "A number").build());
|
argument(IntegerArgument.required("int"), Description.of("A number")).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import com.intellectualsites.commands.annotations.AnnotationParser;
|
||||||
import com.intellectualsites.commands.annotations.Argument;
|
import com.intellectualsites.commands.annotations.Argument;
|
||||||
import com.intellectualsites.commands.annotations.CommandMethod;
|
import com.intellectualsites.commands.annotations.CommandMethod;
|
||||||
import com.intellectualsites.commands.annotations.Confirmation;
|
import com.intellectualsites.commands.annotations.Confirmation;
|
||||||
import com.intellectualsites.commands.annotations.Description;
|
import com.intellectualsites.commands.annotations.CommandDescription;
|
||||||
import com.intellectualsites.commands.annotations.specifier.Completions;
|
import com.intellectualsites.commands.annotations.specifier.Completions;
|
||||||
import com.intellectualsites.commands.annotations.specifier.Range;
|
import com.intellectualsites.commands.annotations.specifier.Range;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
|
|
@ -203,7 +203,7 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
.literal("help")
|
.literal("help")
|
||||||
.argument(StringArgument.<CommandSender>newBuilder("query").greedy()
|
.argument(StringArgument.<CommandSender>newBuilder("query").greedy()
|
||||||
.asOptionalWithDefault("")
|
.asOptionalWithDefault("")
|
||||||
.build(), "Help query")
|
.build(), Description.of("Help Query"))
|
||||||
.handler(c -> minecraftHelp.queryCommands(c.<String>get("query").orElse(""),
|
.handler(c -> minecraftHelp.queryCommands(c.<String>get("query").orElse(""),
|
||||||
c.getSender())).build());
|
c.getSender())).build());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
@ -211,7 +211,7 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Description("Test cloud command using @CommandMethod")
|
@CommandDescription("Test cloud command using @CommandMethod")
|
||||||
@CommandMethod(value = "annotation|a <input> [number]", permission = "some.permission.node")
|
@CommandMethod(value = "annotation|a <input> [number]", permission = "some.permission.node")
|
||||||
private void annotatedCommand(@Nonnull final Player player,
|
private void annotatedCommand(@Nonnull final Player player,
|
||||||
@Argument(value = "input", description = "Some string") @Completions("one,two,duck")
|
@Argument(value = "input", description = "Some string") @Completions("one,two,duck")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue