getDefault(Parameter parameter) {
341 | Default defaultA = parameter.getAnnotation(Default.class);
342 |
343 | return defaultA == null ? Optional.empty() : Optional.of(defaultA.value());
344 | }
345 | }
346 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/ACommand.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.METHOD, ElementType.TYPE})
10 | public @interface ACommand {
11 |
12 | String[] names();
13 |
14 | String desc() default "";
15 |
16 | String permission() default "";
17 |
18 | String permissionMessage() default "No permission.";
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/ConsumedArgs.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface ConsumedArgs {
11 | int value();
12 | }
13 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Default.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import me.fixeddev.ebcm.part.CommandPart;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * The purpose of this annotation is to define the default value of a parameter
12 | * in an {@link ACommand}.
13 | *
14 | * When you set this annotation to any parameter in an {@link ACommand} you set
15 | * the default value of that parameter and also you set that parameter {@link CommandPart#isRequired()}
16 | * value to false
17 | */
18 | @Retention(RetentionPolicy.RUNTIME)
19 | @Target(ElementType.PARAMETER)
20 | public @interface Default {
21 | String[] value() default {};
22 | }
23 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Flag.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface Flag {
11 | char value();
12 | }
13 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Injected.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface Injected {
11 | /**
12 | * @return a boolean value that indicates if this injected value is required or not
13 | */
14 | boolean value() default false;
15 | }
16 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/ModifierAnnotation.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.ANNOTATION_TYPE)
10 | public @interface ModifierAnnotation {
11 | String value();
12 | }
13 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Named.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface Named {
11 | String value();
12 | }
13 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Optional.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import me.fixeddev.ebcm.part.CommandPart;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * The purpose of this annotation is to define the default value of a parameter
12 | * in an {@link ACommand}.
13 | *
14 | * When you set this annotation to any parameter in an {@link ACommand} you set
15 | * the default value of that parameter and also you set that parameter {@link CommandPart#isRequired()}
16 | * value to false
17 | */
18 | @Retention(RetentionPolicy.RUNTIME)
19 | @Target(ElementType.PARAMETER)
20 | public @interface Optional {
21 | String[] value() default {};
22 | }
23 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/ParentArg.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface ParentArg {
11 | /**
12 | * The index used to get this argument CommandPart value, 0 by default
13 | * but can be changed if more than 1 part with the same name is present
14 | * @return An integer representing the index of this argument's CommandPart
15 | */
16 | int value() default 0;
17 | }
18 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Required.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 |
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * Indicates that a command class that contains subcommands
11 | * Requires a subcommand to be executed
12 | */
13 | @Retention(RetentionPolicy.RUNTIME)
14 | @Target(ElementType.TYPE)
15 | public @interface Required {
16 | }
17 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/SubCommandClasses.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import me.fixeddev.ebcm.parametric.CommandClass;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * This annotation has the purpose to allow multiple layers of subcommands
12 | * on parametric commands. This annotation will register the specified command classes
13 | * as subcommands for the annotated command class
14 | */
15 | @Retention(RetentionPolicy.RUNTIME)
16 | @Target(ElementType.TYPE)
17 | public @interface SubCommandClasses {
18 | Class extends CommandClass>[] value();
19 | }
20 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/parametric/annotation/Usage.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.parametric.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.METHOD, ElementType.TYPE})
10 | public @interface Usage {
11 | String[] usage() default "_!!_NOT_OVERRIDE_!!_";
12 | }
13 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/part/ArgumentConsumingPart.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.part;
2 |
3 | import java.util.List;
4 |
5 | public interface ArgumentConsumingPart extends LineConsumingPart {
6 | Class> getArgumentType();
7 |
8 | /**
9 | * This default values are supposed to replace the command line arguments
10 | * in case that we need the default value
11 | *
12 | * @return A list of arguments that are used as default value
13 | */
14 | List getDefaultValues();
15 | }
16 |
--------------------------------------------------------------------------------
/Universal/src/main/java/me/fixeddev/ebcm/part/ArgumentPart.java:
--------------------------------------------------------------------------------
1 | package me.fixeddev.ebcm.part;
2 |
3 | import com.google.auto.value.AutoValue;
4 | import com.google.auto.value.extension.memoized.Memoized;
5 | import me.fixeddev.ebcm.SuggestionProvider;
6 | import me.fixeddev.ebcm.util.ListAppender;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.Optional;
11 |
12 | @AutoValue
13 | public abstract class ArgumentPart implements ArgumentConsumingPart {
14 |
15 | public static Builder builder(String name, Class> argumentType) {
16 | return new AutoValue_ArgumentPart.Builder()
17 | .named(name)
18 | .argumentType(argumentType)
19 | .setConsumedArguments(1)
20 | .setRequired(false)
21 | .setDescription("")
22 | .setDefaultValues(new ArrayList<>());
23 | }
24 |
25 | public abstract Optional getSuggestionProvider();
26 |
27 | public abstract int getConsumedArguments();
28 |
29 | @Override
30 | @Memoized
31 | public String getLineRepresentation() {
32 |
33 | return (isRequired() ? "<" : "[") +
34 | getName() +
35 | (isRequired() ? ">" : "]");
36 | }
37 |
38 | @AutoValue.Builder
39 | public abstract static class Builder {
40 | private ListAppender modifiersAppender = new ListAppender<>();
41 |
42 | protected final Builder named(String name) {
43 | return setName(name);
44 | }
45 |
46 | protected abstract Builder setName(String newName);
47 |
48 | protected final Builder argumentType(Class> argumentType) {
49 | return setArgumentType(argumentType);
50 | }
51 |
52 | protected abstract Builder setArgumentType(Class> newArgumentType);
53 |
54 | public abstract Builder setDefaultValues(List defaultValues);
55 |
56 | public abstract Builder setDescription(String newDescription);
57 |
58 | public abstract Builder setSuggestionProvider(SuggestionProvider suggestionProvider);
59 |
60 | public Builder setAllModifiers(List modifiers) {
61 | this.modifiersAppender.set(modifiers);
62 |
63 | return this;
64 | }
65 |
66 | public Builder addModifier(String modifier) {
67 | this.modifiersAppender.add(modifier);
68 |
69 | return this;
70 | }
71 |
72 | protected abstract Builder setModifiers(List