diff --git a/src/main/java/minevalley/core/api/CoreModule.java b/src/main/java/minevalley/core/api/CoreModule.java index d693ff03..399c682d 100644 --- a/src/main/java/minevalley/core/api/CoreModule.java +++ b/src/main/java/minevalley/core/api/CoreModule.java @@ -1,20 +1,36 @@ package minevalley.core.api; +import lombok.Getter; + +@Getter +@SuppressWarnings("unused") public abstract class CoreModule { + private final Module moduleDescription; + + public CoreModule() { + final Class clazz = getClass(); + if (!clazz.isAnnotationPresent(Module.class)) { + throw new IllegalArgumentException("Module annotation is missing in module '" + clazz.getSimpleName() + "'"); + } + this.moduleDescription = clazz.getAnnotation(Module.class); + } + /** * Is called when the module is enabled. */ - public abstract void onEnable(); + public void onEnable() { + // do nothing + } /** * Is called when the module is disabled. */ public void onDisable() { - + // do nothing } public void onCleanup() { - + // do nothing } } \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/Description.java b/src/main/java/minevalley/core/api/Module.java similarity index 90% rename from src/main/java/minevalley/core/api/Description.java rename to src/main/java/minevalley/core/api/Module.java index 228e8516..6320f428 100644 --- a/src/main/java/minevalley/core/api/Description.java +++ b/src/main/java/minevalley/core/api/Module.java @@ -6,7 +6,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target(java.lang.annotation.ElementType.TYPE) -public @interface Description { +public @interface Module { String name(); diff --git a/src/main/java/minevalley/core/api/command/Command.java b/src/main/java/minevalley/core/api/command/Command.java index f55dd322..49a3ab32 100644 --- a/src/main/java/minevalley/core/api/command/Command.java +++ b/src/main/java/minevalley/core/api/command/Command.java @@ -1,48 +1,70 @@ package minevalley.core.api.command; -import minevalley.core.api.users.OnlineUser; +import lombok.NonNull; -import java.util.List; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; -/** - * This interface corresponds to the often used CommandExecutor-interface. It's used very similarly, but has some advantages. - */ -public interface Command { +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE_USE) +public @interface Command { /** - * This is the equivalent to the onCommand-method of the CommandExecutor-interface + * This list is used to make all the strings usable command-variations. It should contain each alias and the original spelling of the command * - * @param user user who executed this command - * @param args array of arguments - * @return response-enum that decides what is sent to the user + * @return array of all command varies and its aliases */ - CommandResponse onCommand(OnlineUser user, String[] args); + @NonNull + String[] commands(); /** - * This method is used to define the completions displayed when the player presses TAB. + *

+ * This string defines the correct syntax. + *

+ * Begin with the mostly used alias of the command itself without "/" + * Then add all possible arguments with "< >" + * arguments that are not required are marked with "[< >]" + *
+ * Different argument suggestions are separated by vertical bars (example: see below). + *
+ * Literal argument suggestions are written in quotation marks (e. g. /restart <seconds | 'now'>) + */ + @NonNull + String syntax() default ""; + + /** + * This message defined here will be sent, when the onCommand-method returns SUCCESS. + *
+ * Don't use this method, if the player shouldn't get printed any message on success. + */ + String successMessage() default ""; + + /** + * If this is enabled, users that are allowed to use this command are also allowed to tab it. + * Disable this if you want to make custom permission-checks beyond the command-options! * - * @param user user who pressed TAB - * @param args array of the arguments - * @return list of the completions to display + * @return true, if everyone with permission can tab this command. */ - List onTabComplete(OnlineUser user, String[] args); + boolean allowTabbing() default true; /** - * This method is used to define whether a user is permissioned to execute/tab this command. - * This is checked, when a user tabs or executes the command. - *

- * Note: This method should not have any side effects! + * If abuseWarning() is true, the team will be notified if a player tries to execute this command without permission + * The return of ABUSE_WARNING in the onCommand method is not related to this setting and can also be carried out if nothing (or false) is specified here * - * @param user user who tries to execute/tab the command - * @return true, if the user is permissioned - false, if he isn't (error-message will be sent automatically) + * @return true, if the team should be notified about illegal use of this command. + */ + boolean abuseWarning() default false; + + /** + * If a value is specified here, the user must execute the command with the specified number of arguments. + * Otherwise, the command will not be invoked and the user will receive a syntax error. + */ + int correctSyntaxLength() default -1; + + /** + * If executableIfFrozen is true, this command can be executed even though the user is currently frozen by a team member. */ - boolean isPermissioned(OnlineUser user); - - enum CommandResponse { - SUCCESS, - ABUSE_WARNING, - WRONG_SYNTAX, - NO_PERMISSION, - NONE - } + boolean executableIfFrozen() default false; } \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/command/CommandOptions.java b/src/main/java/minevalley/core/api/command/CommandOptions.java deleted file mode 100644 index 7738eca2..00000000 --- a/src/main/java/minevalley/core/api/command/CommandOptions.java +++ /dev/null @@ -1,70 +0,0 @@ -package minevalley.core.api.command; - -import lombok.NonNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE_USE) -public @interface CommandOptions { - - /** - * This list is used to make all the strings usable command-variations. It should contain each alias and the original spelling of the command - * - * @return array of all command varies and its aliases - */ - @NonNull - String[] commands(); - - /** - *

- * This string defines the correct syntax. - *

- * Begin with the mostly used alias of the command itself without "/" - * Then add all possible arguments with "< >" - * arguments that are not required are marked with "[< >]" - *
- * Different argument suggestions are separated by vertical bars (example: see below). - *
- * Literal argument suggestions are written in quotation marks (e. g. /restart <seconds | 'now'>) - */ - @NonNull - String syntax() default ""; - - /** - * This message defined here will be sent, when the onCommand-method returns SUCCESS. - *
- * Don't use this method, if the player shouldn't get printed any message on success. - */ - String successMessage() default ""; - - /** - * If this is enabled, users that are allowed to use this command are also allowed to tab it. - * Disable this if you want to make custom permission-checks beyond the command-options! - * - * @return true, if everyone with permission can tab this command. - */ - boolean allowTabbing() default true; - - /** - * If abuseWarning() is true, the team will be notified if a player tries to execute this command without permission - * The return of ABUSE_WARNING in the onCommand method is not related to this setting and can also be carried out if nothing (or false) is specified here - * - * @return true, if the team should be notified about illegal use of this command. - */ - boolean abuseWarning() default false; - - /** - * If a value is specified here, the user must execute the command with the specified number of arguments. - * Otherwise, the command will not be invoked and the user will receive a syntax error. - */ - int correctSyntaxLength() default -1; - - /** - * If executableIfFrozen is true, this command can be executed even though the user is currently frozen by a team member. - */ - boolean executableIfFrozen() default false; -} \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/command/PlayerCommand.java b/src/main/java/minevalley/core/api/command/PlayerCommand.java index 2cb1a5aa..6c907128 100644 --- a/src/main/java/minevalley/core/api/command/PlayerCommand.java +++ b/src/main/java/minevalley/core/api/command/PlayerCommand.java @@ -1,30 +1,62 @@ package minevalley.core.api.command; import lombok.Getter; -import minevalley.core.api.Core; import minevalley.core.api.users.OnlineUser; import java.util.List; -import java.util.Objects; @Getter -public abstract class PlayerCommand implements Command { +@SuppressWarnings("unused") +public abstract class PlayerCommand { - private final CommandOptions description; + private final Command description; public PlayerCommand() { - this.description = Objects.requireNonNull( - getClass().getAnnotation(CommandOptions.class), "CommandOptions-Annotation is missing!"); - Core.registerCommand(this); + final Class clazz = getClass(); + if (!clazz.isAnnotationPresent(Command.class)) { + throw new IllegalArgumentException("CommandOptions annotation is missing in " + clazz.getSimpleName()); + } + this.description = clazz.getAnnotation(Command.class); } - @Override + /** + * This is the equivalent to the onCommand-method of the CommandExecutor-interface + * + * @param user user who executed this command + * @param args array of arguments + * @return response-enum that decides what is sent to the user + */ + public abstract CommandResponse onCommand(OnlineUser user, String[] args); + + /** + * This method is used to define the completions displayed when the player presses TAB. + * + * @param user user who pressed TAB + * @param args array of the arguments + * @return list of the completions to display + */ public List onTabComplete(OnlineUser user, String[] args) { return null; } - @Override + /** + * This method is used to define whether a user is permissioned to execute/tab this command. + * This is checked, when a user tabs or executes the command. + *

+ * Note: This method should not have any side effects! + * + * @param user user who tries to execute/tab the command + * @return true, if the user is permissioned - false, if he isn't (error-message will be sent automatically) + */ public boolean isPermissioned(OnlineUser user) { return true; } + + public enum CommandResponse { + SUCCESS, + ABUSE_WARNING, + WRONG_SYNTAX, + NO_PERMISSION, + NONE + } } \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/users/OnlineUser.java b/src/main/java/minevalley/core/api/users/OnlineUser.java index 6ccde657..484d386d 100644 --- a/src/main/java/minevalley/core/api/users/OnlineUser.java +++ b/src/main/java/minevalley/core/api/users/OnlineUser.java @@ -44,6 +44,7 @@ public interface OnlineUser extends User { /** * Gets whether this user is currently logged in via labymod. + *
* Note: When joining, this boolean isn't set immediately. Make sure to use a delay, when using this method in a PlayerJoinListener! * * @return true, if this user is using labymod @@ -271,7 +272,7 @@ public interface OnlineUser extends User { */ void sendError(); - // ChatInterface + // ChatInput /** * Asks the player for any type of input via a chat-interface. The player can leave this interface. If he writes something into this interface, the callback gets called. @@ -281,17 +282,6 @@ public interface OnlineUser extends User { */ void input(@NonNull String message, @NonNull Consumer callback); - /** - * Gets whether the user is currently in a chat input. - * - * @return true, if the user is in a chat input - * @deprecated use isInChatInput()! - */ - @Deprecated - default boolean isInChatInterface() { - return isInChatInput(); - } - /** * Gets whether the user is currently in a chat input. * @@ -299,16 +289,6 @@ default boolean isInChatInterface() { */ boolean isInChatInput(); - /** - * Lets the user leave his current chat input - * - * @deprecated use leaveChatInput instead! - */ - @Deprecated - default void leaveInterface() { - leaveChatInput(); - } - /** * Lets the user leave his current chat input */