From 2b1e9b73620568665dc3fcc2c1858186a47374b6 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Sun, 7 Mar 2021 21:58:53 -0600 Subject: [PATCH] JavaDocs! Simple Docs --- .../api/annotations/CommandInfo.java | 23 +++++++++++++++ .../simplexcore/SimplexCorePlugin.java | 11 ++++---- .../simplexcore/command/CommandLoader.java | 19 ++++++++++++- .../simplexcore/command/SimplexCommand.java | 28 +++++++++++++++++++ .../simplexcore/plugin/AddonRegistry.java | 2 +- 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/simplexdev/api/annotations/CommandInfo.java b/src/main/java/io/github/simplexdev/api/annotations/CommandInfo.java index fb51fc7..519180a 100644 --- a/src/main/java/io/github/simplexdev/api/annotations/CommandInfo.java +++ b/src/main/java/io/github/simplexdev/api/annotations/CommandInfo.java @@ -5,18 +5,41 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * This annotation must be used to annotate every command class. + * Please also ensure that your commands are in their own package (ie .commands) + * This helps the {@link io.github.simplexdev.simplexcore.command.CommandLoader} to correctly load your commands. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface CommandInfo { + /** + * @return The name of the command. + */ String name(); + /** + * @return The description of the command. + */ String description(); + /** + * @return How the command should be used. + */ String usage(); + /** + * @return A list of aliases of the command separated by commas in a single String. + */ String aliases() default ""; + /** + * @return The permission for the command + */ String permission() default "simplex.core"; + /** + * @return The message to send if someone does not have permission to use the command. + */ String permissionMessage() default "You do not have permission to use this command."; } diff --git a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java index 4dba056..8145aab 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java +++ b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java @@ -25,8 +25,10 @@ public final class SimplexCorePlugin extends SimplexAddon { private TimeValues time; private Yaml internals; - // should this just be 'new SimplexCorePlugin()' ? - protected static final SimplexCorePlugin instance = getPlugin(SimplexCorePlugin.class); + protected static SimplexCorePlugin instance; // = getPlugin(SimplexCorePlugin.class); + public static SimplexCorePlugin getInstance() { + return instance; + } @Override public SimplexCorePlugin getPlugin() { @@ -35,6 +37,7 @@ public final class SimplexCorePlugin extends SimplexAddon { @Override public void init() { + instance = this; this.dpm = new DependencyManagement(); this.config = new YamlFactory(this).setDefaultPathways(); this.time = new TimeValues(); @@ -77,10 +80,6 @@ public final class SimplexCorePlugin extends SimplexAddon { return suspended; } - public static SimplexCorePlugin getInstance() { - return instance; - } - public Logger getLogger() { return this.getServer().getLogger(); } diff --git a/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java b/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java index 0a37924..b543499 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java +++ b/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java @@ -22,7 +22,10 @@ public final class CommandLoader { private Reflections reflections; private static final CommandLoader instance = new CommandLoader(); - public static CommandLoader getInstance() { + /** + * @return A Singleton Pattern instance of this class. + */ + public static synchronized CommandLoader getInstance() { return instance; } @@ -80,6 +83,13 @@ public final class CommandLoader { }); } + /** + * Gets the command class as a child of {@link CommandExecutor} from the {@link CommandInfo#name()} annotation. + * This is for registering the CommandExecutor of the provided command with Bukkit. + * This should only be used by the CommandLoader. + * @param name The name of the command. + * @return An instance of the command class as a CommandExecutor. + */ public synchronized CommandExecutor getExecutorFromName(String name) { for (Class obj : reflections.getSubTypesOf(CommandExecutor.class)) { if (!obj.isAnnotationPresent(CommandInfo.class)) { @@ -101,6 +111,13 @@ public final class CommandLoader { throw new RuntimeException("Unable to get a command executor! Terminating!"); } + /** + * Gets the command class as a child of {@link TabCompleter} from the {@link CommandInfo#name()} annotation. + * This is for registering the TabCompleter of the provided command with Bukkit. + * This should only be used by the CommandLoader. + * @param name The name of the command + * @return The command as an instance of TabCompleter + */ @Nullable public synchronized TabCompleter getTabFromName(String name) { for (Class obj : reflections.getSubTypesOf(TabCompleter.class)) { diff --git a/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java b/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java index 1ad8b30..07f1c27 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java +++ b/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java @@ -20,27 +20,55 @@ public abstract class SimplexCommand implements CommandExecutor, TabCompleter { return sender instanceof Player; } + /** + * Gets an online player from their username + * @param name The player's username + * @return An instance of {@link Player} which represents the online player in question. + */ @Nullable public Player getPlayer(String name) { return SimplexCorePlugin.getInstance().getServer().getPlayer(name); } + /** + * Gets an online player from their {@link UUID}. + * @param uuid The player's UUID + * @return An instance of {@link Player} which represents the online player in question. + */ @Nullable public Player getPlayer(UUID uuid) { return SimplexCorePlugin.getInstance().getServer().getPlayer(uuid); } + /** + * Gets an instance of {@link Player} based off an instance of {@link CommandSender}. + * This will be null if the condition {CommandSender instanceof Player} is false. + * @param sender The CommandSender to cast + * @return An instance of Player relating to CommandSender. + */ @Nullable public Player getPlayer(CommandSender sender) { return isPlayer(sender) ? (Player) sender : null; } + /** + * Send a message or a group of messages to a {@link Player}. + * If you want the messages to send on new lines, put \n at the end of each message to send. + * @param player The Player to send a message to + * @param messages The messages to send. + */ public void playerMsg(Player player, String... messages) { StringBuilder builder = new StringBuilder(); Utilities.forEach(messages, builder::append); player.sendMessage(builder.toString()); } + /** + * Send a message or a group of messages to a {@link CommandSender} + * If you want the messages to send on new lines, put \n at the end of each message to send. + * @param sender The CommandSender to send a message to. + * @param messages The messages to send. + */ public void msg(CommandSender sender, String... messages) { StringBuilder builder = new StringBuilder(); Utilities.forEach(messages, builder::append); diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java index 3f37545..5f7a6fa 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java @@ -14,7 +14,7 @@ public final class AddonRegistry { protected AddonRegistry() { } - public static AddonRegistry getInstance() { + public static synchronized AddonRegistry getInstance() { return instance; }