From 6842cb2792666b4f2bb1141953586d7a41553a5a Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Sun, 23 Jul 2023 02:15:12 -0500 Subject: [PATCH] Adjusted Command Processing Completion annotations have been moved to top level, from per method, for a much clearer understanding of how the annotation should be used. --- .../totalfreedom/datura/cmd/CageCommand.java | 6 +- .../datura/cmd/ClearDropsCommand.java | 2 +- .../datura/cmd/ClearEntitiesCommand.java | 2 +- .../totalfreedom/datura/cmd/HaltCommand.java | 6 +- .../datura/cmd/LockerCommand.java | 4 +- .../datura/cmd/ManageUserCommand.java | 6 +- .../totalfreedom/datura/cmd/SmiteCommand.java | 2 +- .../audience/MutableAudienceForwarder.java | 11 ++- .../totalfreedom/command/BukkitDelegate.java | 69 +++++++++++-------- .../command/annotation/Completion.java | 2 +- .../command/annotation/Completions.java | 6 +- .../data/ServiceTaskRegistry.java | 2 +- .../totalfreedom/display/DisplayableView.java | 1 + .../java/me/totalfreedom/particle/Trail.java | 2 +- .../java/me/totalfreedom/shop/Reaction.java | 10 +-- build.gradle | 6 ++ 16 files changed, 71 insertions(+), 66 deletions(-) diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java index 375b38a..c3d6fa6 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java @@ -37,6 +37,9 @@ import org.jetbrains.annotations.NotNull; @Info(name = "cage", description = "Cage a player.", usage = "/cage [material]") @Permissive(perm = "datura.cage") +@Completion(args = {"%player%"}, index = 0) +@Completion(args = {"on", "off"}, index = 1) +@Completion(args = {"[material]"}, index = 2) public class CageCommand extends Commander { protected CageCommand(final @NotNull JavaPlugin plugin) @@ -44,8 +47,6 @@ public class CageCommand extends Commander super(plugin); } - @Completion(args = {"%player%"}, index = 0) - @Completion(args = {"on", "off"}, index = 1) @Subcommand(permission = "datura.cage", args = {Player.class, String.class}) public void cagePlayer(final CommandSender sender, final Player player, final String string) { @@ -62,7 +63,6 @@ public class CageCommand extends Commander } } - @Completion(args = {"[material]"}, index = 2) @Subcommand(permission = "datura.cage.custom", args = {Player.class, String.class, Material.class}) public void cagePlayer(final CommandSender sender, final Player player, final String string, final Material material) diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java index d616def..5168a5a 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull; @Info(name = "cleardrops", description = "Clears all item drops in the world" + ".", usage = "/", aliases = {"cd", "clearitems", "ci", "wipeitems", "wi", "removedrops", "rd"}) @Permissive(perm = "datura.cleardrops") +@Completion(index = 0, args = {"%world%"}) public class ClearDropsCommand extends Commander { /** @@ -70,7 +71,6 @@ public class ClearDropsCommand extends Commander } @Subcommand(permission = "datura.cleardrops", args = {World.class}) - @Completion(index = 0, args = {"%world%"}) public void clearDrops(final CommandSender sender, final World world) { Patchwork.getInstance() diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java index 6460a33..f77cf16 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull; @Info(name = "clearentities", description = "Clears all entities in the world.", usage = "/ [world]", aliases = {"ew", "ce", "entitywipe", "entityclear", "ec"}) @Permissive(perm = "datura.clearentities") +@Completion(index = 0, args = {"%world%"}) public class ClearEntitiesCommand extends Commander { /** @@ -57,7 +58,6 @@ public class ClearEntitiesCommand extends Commander } @Subcommand(permission = "datura.clearentities", args = {World.class}) - @Completion(index = 0, args = {"%world%"}) public void clearEntities(final CommandSender sender, final World world) { int i = 0; diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/HaltCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/HaltCommand.java index a4bfd32..903da90 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/HaltCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/HaltCommand.java @@ -17,6 +17,8 @@ import org.jetbrains.annotations.NotNull; @Info(name = "halt", description = "Halt a single player, or every player.", usage = "/ ") @Permissive(perm = "datura.halt") +@Completion(index = 0, args = {"%player%", "all"}) +@Completion(index = 1, args = {"on", "off"}) public class HaltCommand extends Commander { private final Datura plugin = Shortcuts.provideModule(Datura.class); @@ -35,9 +37,6 @@ public class HaltCommand extends Commander super(plugin); } - - @Completion(index = 0, args = {"%player%", "all"}) - @Completion(index = 1, args = {"on", "off"}) @Subcommand(permission = "datura.halt", args = {Player.class, String.class}) public void haltPlayer(final CommandSender sender, final Player target, final String toggle) { @@ -58,7 +57,6 @@ public class HaltCommand extends Commander } } - // No completion needed here since it's already registered. @Subcommand(permission = "datura.halt.all", args = {String.class, String.class}) public void haltAll(final CommandSender sender, final String all, final String toggle) { diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java index 38f9f2c..0623c84 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java @@ -13,6 +13,8 @@ import org.jetbrains.annotations.NotNull; @Info(name = "locker", description = "Lock a player, preventing them from interacting with their game client.", usage = "/locker ", aliases = {"lock", "lockup"}) @Permissive(perm = "datura.locker") +@Completion(args = {"%player%"}, index = 0) +@Completion(args = {"on", "off"}, index = 1) public final class LockerCommand extends Commander { public LockerCommand(final @NotNull Datura plugin) @@ -20,8 +22,6 @@ public final class LockerCommand extends Commander super(plugin); } - @Completion(args = {"%player%"}, index = 0) - @Completion(args = {"on", "off"}, index = 1) @Subcommand(permission = "datura.locker", args = {Player.class, String.class}) public void lockPlayer(final CommandSender sender, final Player player, final String string) { diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/ManageUserCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/ManageUserCommand.java index 9c0b86b..026cb17 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/ManageUserCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/ManageUserCommand.java @@ -20,6 +20,9 @@ import org.jetbrains.annotations.NotNull; @Info(name = "manageuser", description = "Manage a user's permissions", usage = "/manageuser )>", aliases = {"mu", "userdata", "ud", "usermanager", "um"}) @Permissive(perm = "datura.manageuser") +@Completion(index = 0, args = {"%player%"}) +@Completion(index = 1, args = {"info", "add", "remove"}) +@Completion(index = 2, args = {""}) public class ManageUserCommand extends Commander { @@ -38,9 +41,6 @@ public class ManageUserCommand extends Commander } @Subcommand(permission = "datura.manageuser", args = {Player.class, String.class, String.class, Long.class}) - @Completion(index = 0, args = {"%player%"}) - @Completion(index = 1, args = {"info", "add", "remove"}) - @Completion(index = 2, args = {""}) public void manageUser(final CommandSender sender, final Player player, final String addOrRemove, final String permission, final long duration) { diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/SmiteCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/SmiteCommand.java index 531f59f..c434d7e 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/SmiteCommand.java +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/SmiteCommand.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull; @Info(name = "smite", description = "Smite a player.", usage = "/smite ", aliases = {"sm"}) @Permissive(perm = "datura.smite") +@Completion(index = 0, args = {"%player%"}) public class SmiteCommand extends Commander { /** @@ -30,7 +31,6 @@ public class SmiteCommand extends Commander } @Subcommand(permission = "datura.smite", args = {Player.class}) - @Completion(index = 0, args = {"%player%"}) public void smite(final CommandSender sender, final Player player) { final double size = 5D; diff --git a/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java b/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java index f725d73..38eaf1a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java +++ b/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java @@ -1,5 +1,9 @@ package me.totalfreedom.audience; +import java.util.HashSet; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Predicate; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.chat.ChatType; @@ -13,13 +17,8 @@ import net.kyori.adventure.title.Title; import net.kyori.adventure.title.TitlePart; import org.jetbrains.annotations.NotNull; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Predicate; - /** - * A replacement for {@link net.kyori.adventure.audience.ForwardingAudience} that allows for audiences to be removed & + * A replacement for {@link net.kyori.adventure.audience.ForwardingAudience} that allows for audiences to be removed and * added at will. Not thread safe. *

* This is intended for use in toggleable logging systems, for example, potion spy. diff --git a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java b/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java index e5ee289..6ac04ff 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java +++ b/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java @@ -1,5 +1,9 @@ package me.totalfreedom.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; import me.totalfreedom.command.annotation.Completion; import me.totalfreedom.command.annotation.Subcommand; import me.totalfreedom.provider.ContextProvider; @@ -10,24 +14,18 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - /** * This class is acts as a delegate between our custom command implementation and the Bukkit API. *
* This class is not meant to be used directly, and is only public to allow for the Bukkit API to access it. As a * result, this file will remain undocumented. - * + *
*
* This class is not thread-safe. *
@@ -36,7 +34,6 @@ import java.util.Set; * This class is not meant to be instantiated. *
* This class is not meant to be used outside Patchwork. - *
*/ public final class BukkitDelegate extends Command implements PluginIdentifiableCommand { @@ -101,14 +98,18 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC { try { - if (noConsole) { + if (noConsole) + { command.getBaseMethod() - .invoke(command, (Player)sender); - } else { + .invoke(command, (Player) sender); + } + else + { command.getBaseMethod() .invoke(command, sender); } - } catch (Exception ex) + } + catch (Exception ex) { FreedomLogger.getLogger("Patchwork") .error(ex); @@ -142,37 +143,45 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC final String[] reasonArgs = Arrays.copyOfRange(args, i, args.length - 1); final String reason = String.join(" ", reasonArgs); objects[i] = reason; - } else + } + else { continue; } } - if (argType.equals(Location.class)) { + if (argType.equals(Location.class)) + { final String[] locationArgs = Arrays.copyOfRange(args, i, i + 3); final String location = String.join(" ", locationArgs); objects[i] = location; } final Object obj = provider.fromString(arg, argType); - if (obj == null) { - FreedomLogger.getLogger("Datura").error("Failed to parse argument " + arg + " for type " + argType.getName()); + if (obj == null) + { + FreedomLogger.getLogger("Datura") + .error("Failed to parse argument " + arg + " for type " + argType.getName()); return; } objects[i] = obj; } try { - if (noConsole) { + if (noConsole) + { command.getSubcommands() .get(node) - .invoke(command, (Player)sender, objects); - } else { + .invoke(command, (Player) sender, objects); + } + else + { command.getSubcommands() .get(node) .invoke(command, sender, objects); } - } catch (Exception ex) + } + catch (Exception ex) { FreedomLogger.getLogger("Patchwork") .error(ex); @@ -204,16 +213,16 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC .map(World::getName) .toList()); case "%number%" -> results.addAll(List.of( - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9")); + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9")); case "%location%" -> results.add("world x y z"); default -> results.add(p); } diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java index d32efa4..1613184 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java +++ b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java @@ -12,7 +12,7 @@ import java.lang.annotation.Target; * This will register at class level, and does not retain method information. As a result, you only need to register the * arguments a single time, and it will always be used in tab completions. */ -@Target(ElementType.METHOD) +@Target(ElementType.TYPE) @Repeatable(Completions.class) @Retention(RetentionPolicy.RUNTIME) public @interface Completion diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java index 694804e..cdcfb15 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java +++ b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java @@ -8,10 +8,10 @@ import java.lang.annotation.Target; /** * A marker interface which represents a holder for multiple {@link Completion} annotations. *
- * This interface is NOT intended for implementation and should - * NOT be used. + * This interface is NOT intended for implementation and should + * NOT be used. */ -@Target(ElementType.METHOD) +@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Completions { diff --git a/Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java index 2cf3e8d..e734b8e 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java +++ b/Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java @@ -284,7 +284,7 @@ public class ServiceTaskRegistry *
* The service should have been registered previously as a ServiceSubscription. * - * @param service The service you are trying to unregister. + * @param clazz The service you are trying to unregister. * @see #registerService(ServiceSubscription) * @see ServiceSubscription */ diff --git a/Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java b/Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java index 26c5138..7c4e2ec 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java +++ b/Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java @@ -78,6 +78,7 @@ public class DisplayableView extends InventoryView } @Override + @Deprecated(forRemoval = true, since = "1.16") public @NotNull String getTitle() { return title; diff --git a/Patchwork/src/main/java/me/totalfreedom/particle/Trail.java b/Patchwork/src/main/java/me/totalfreedom/particle/Trail.java index b6ef17f..f9f934a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/particle/Trail.java +++ b/Patchwork/src/main/java/me/totalfreedom/particle/Trail.java @@ -56,7 +56,7 @@ public interface Trail * * @return The color of the trail, or null if the trail is a gradient or non-colorable. * @see Particle - * @see #getColors(); + * @see #getColors() */ @Nullable Color getColor(); diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java b/Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java index 0b96cc7..ad1c761 100644 --- a/Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java +++ b/Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java @@ -1,9 +1,7 @@ package me.totalfreedom.shop; -import me.totalfreedom.display.BossBarDisplay; -import net.kyori.adventure.text.Component; - import java.time.Duration; +import net.kyori.adventure.text.Component; /** * Represents a chat reaction that can be performed by a player. @@ -59,10 +57,4 @@ public abstract class Reaction implements Reactable { return reactionType; } - - @Override - public BossBarDisplay getBossBarDisplay() - { - - } } diff --git a/build.gradle b/build.gradle index f6090f2..5c91798 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,12 @@ subprojects { weight = 0 } } + + javadoc { + options { + encoding = 'UTF-8' + } + } } tasks.register('buildChain') {