From 5a02f027267e0f654b5cac3f6aef9730fb05892b Mon Sep 17 00:00:00 2001 From: efekos <56752400+efekos@users.noreply.github.com> Date: Mon, 20 May 2024 16:19:19 +0300 Subject: [PATCH] fix NumberLimitations somehow being nested under Item, update README & version --- README.md | 52 ++++++++++++------- pom.xml | 2 +- .../efekos/arn/annotation/modifier/Item.java | 24 --------- .../resolver/impl/command/CmdDoubleArg.java | 3 +- .../resolver/impl/command/CmdFloatArg.java | 3 +- .../arn/resolver/impl/command/CmdIntArg.java | 3 +- .../arn/resolver/impl/command/CmdLongArg.java | 4 +- 7 files changed, 43 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index ddb985e..358ee22 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ implementation 'dev.efekos:Arn:0.1.0' ## Usage Arn uses Java Reflection API to scan through your plugin, detect needed classes and use them. Because of this, you have -to add a [`Container`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/Container.html) annotation to -**every** class that must be scanned by [`Arn`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/Arn.html). +to add a [`Container`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/Container.html) annotation to +**every** class that must be scanned by [`Arn`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/Arn.html). ### Creating commands @@ -89,14 +89,14 @@ public int helloWorld(CommandSender sender, @CommandArgument String name /*strin ```` All we have to do is add a parameter with -[`CommandArgument`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/CommandArgument.html) annotation. This +[`CommandArgument`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/CommandArgument.html) annotation. This method is now the equivalent of `/helloworld `, `` being a `String` that can have whitespaces using quoted strings. You can use following combinations of annotations and types by default (all of them requires -[`CommandArgument`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/CommandArgument.html).): +[`CommandArgument`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/CommandArgument.html).): * [`Advancement`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/advancement/Advancement.html) * [`Attribute`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html) -* [`@Block`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/modifier/Block.html) [`Material`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html) +* [`@Block`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/modifier/Block.html) [`Material`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html) * [`BlockData`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/BlockData.html) * `Boolean` * `boolean` @@ -111,9 +111,9 @@ strings. You can use following combinations of annotations and types by default * [`GameMode`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/GameMode.html) * `Integer` * `int` -* [`@InventorySlot`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/modifier/NumberLimitations.html) `Integer` -* [`@InventorySlot`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/modifier/NumberLimitations.html) `int` -* [`@Item`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/modifier/Item.html) [`Material`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html) +* [`@InventorySlot`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/modifier/NumberLimitations.html) `Integer` +* [`@InventorySlot`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/modifier/NumberLimitations.html) `int` +* [`@Item`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/modifier/Item.html) [`Material`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html) * [`ItemStack`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html) * [`Location`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Location.html) * `Long` @@ -123,9 +123,9 @@ strings. You can use following combinations of annotations and types by default * [`Player`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Player.html) * `String` * [`BaseComponent`](https://javadoc.io/doc/net.md-5/bungeecord-chat/latest/net/md_5/bungee/api/chat/BaseComponent.html) -* [`@Vector`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/modifier/Vector.html) [`Location`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Location.html) +* [`@Vector`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/modifier/Vector.html) [`Location`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Location.html) -These don't require a [`CommandArgument`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/CommandArgument.html) +These don't require a [`CommandArgument`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/CommandArgument.html) annotation. * [`BlockCommandSender`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/command/BlockCommandSender.html) @@ -162,7 +162,7 @@ with a bit of research. ### Advanced literals I only showed you how to make base commands. There is more than base commands in Arn. If you want to use two or more -literals, you can simply separate them with `.` in your [`CommandArgument`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/CommandArgument.html) +literals, you can simply separate them with `.` in your [`CommandArgument`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/CommandArgument.html) annotation. But in this way, arguments will be placed after all the literals. If you want to place literals between arguments, you can follow this syntax: `[ab]:[0-9]+:[a-z]+`. First group of a letter determines will this literal be placed before or after the argument with the given index. Second group of a number is the index of an argument. Finally, last group of @@ -177,7 +177,7 @@ the literal would be placed after the 1st argument. ### Custom arguments If you want to make a custom argument, you can, using Enum classes! All you have to do is annotate an enum class with both -[`Container`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/Container.html) and [`CustomArgument`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/CustomArgument.html), +[`Container`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/Container.html) and [`CustomArgument`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/CustomArgument.html), and you'll be able to use that enum class as a command argument. ````java @@ -216,7 +216,7 @@ public class Commands { ### Blocking access You can block access by using a permission or annotations. All you have to do is add the permission node to the -[`Command`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/Command.html) like this: +[`Command`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/Command.html) like this: ````java import dev.efekos.arn.annotation.Command; @@ -231,20 +231,36 @@ import dev.efekos.arn.annotation.block.BlockPlayer; public int method(/*...*/); ```` +### Limits + +You can apply [`NumberLimitations`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/modifier/NumberLimitations.html) +to any command argument with a number type. + +````java +import dev.efekos.arn.annotation.Command; +import dev.efekos.arn.annotation.CommandArgument; +import dev.efekos.arn.annotation.block.BlockCommandBlock; +import dev.efekos.arn.annotation.modifier.NumberLimitations; + +@Command("settimeout") +@BlockCommandBlock +public int setTimeout(@CommandArgument @NumberLimitations(min = 0,max = 30) Integer argument); +```` + ### Configurations If you want to go even more crazy, you can implement your own command parameter types. You have to make an implementation -of [`CommandHandlerMethodArgumentResolver`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/resolver/CommandHandlerMethodArgumentResolver.html) +of [`CommandHandlerMethodArgumentResolver`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/resolver/CommandHandlerMethodArgumentResolver.html) first. If you want to add an argument to the command structure to resolver a parameter, you might also need to make an -implementation of a [`CommandArgumentResolver`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/resolver/CommandArgumentResolver.html). -After that, simply make a [`Container`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/annotation/Container.html) that -implements [`ArnConfigurer`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/config/ArnConfigurer.html), and add your +implementation of a [`CommandArgumentResolver`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/resolver/CommandArgumentResolver.html). +After that, simply make a [`Container`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/annotation/Container.html) that +implements [`ArnConfigurer`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/config/ArnConfigurer.html), and add your resolvers using that configurer. ### Running After all of your command and configurations are done, call -[`Arn`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/Arn.html)[`#run`](https://efekos.dev/javadoc/arn/0.1/dev/efekos/arn/Arn.html#run(java.lang.Class)) +[`Arn`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/Arn.html)[`#run`](https://efekos.dev/javadoc/arn/0.1.1/dev/efekos/arn/Arn.html#run(java.lang.Class)) from your plugin. ````java diff --git a/pom.xml b/pom.xml index 0105c62..bd3ff48 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.efekos Arn - 0.1.0 + 0.1.1 jar Arn diff --git a/src/main/java/dev/efekos/arn/annotation/modifier/Item.java b/src/main/java/dev/efekos/arn/annotation/modifier/Item.java index df96876..9f9ddf9 100644 --- a/src/main/java/dev/efekos/arn/annotation/modifier/Item.java +++ b/src/main/java/dev/efekos/arn/annotation/modifier/Item.java @@ -1,8 +1,6 @@ package dev.efekos.arn.annotation.modifier; -import dev.efekos.arn.annotation.CommandArgument; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -19,27 +17,5 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface Item { - /** - * Applies limitations to number arguments annotated with {@link CommandArgument}. When this annotation is present on any - * number argument ({@code long},{@code int},{@code float} and {@code double}), given minimum and maximum limits will be - * applied to the command argument node which will be on final command structure. - * @since 0.1 - * @author efekos - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.PARAMETER) - @interface NumberLimitations { - - /** - * Minimum value of the number argument. - * @return Minimum value. - */ - long min() default Integer.MIN_VALUE; - /** - * Maximum value of the number argument. - * @return Maximum value. - */ - long max() default Integer.MAX_VALUE; - } } diff --git a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdDoubleArg.java b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdDoubleArg.java index 8868041..a8d9af7 100644 --- a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdDoubleArg.java +++ b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdDoubleArg.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.ArgumentBuilder; import dev.efekos.arn.annotation.CommandArgument; import dev.efekos.arn.annotation.modifier.Item; +import dev.efekos.arn.annotation.modifier.NumberLimitations; import dev.efekos.arn.resolver.CommandArgumentResolver; import net.minecraft.commands.CommandDispatcher; @@ -30,7 +31,7 @@ public boolean isApplicable(Parameter parameter) { @Override public ArgumentBuilder apply(Parameter parameter) { String s = parameter.getAnnotation(CommandArgument.class).value(); - Item.NumberLimitations limitations = parameter.getAnnotation(Item.NumberLimitations.class); + NumberLimitations limitations = parameter.getAnnotation(NumberLimitations.class); boolean b = limitations != null; return CommandDispatcher.a(s.isEmpty() ?parameter.getName():s, b? DoubleArgumentType.doubleArg(limitations.min(),limitations.max()):DoubleArgumentType.doubleArg()); } diff --git a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdFloatArg.java b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdFloatArg.java index b2bbc1b..0bbbf77 100644 --- a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdFloatArg.java +++ b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdFloatArg.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.ArgumentBuilder; import dev.efekos.arn.annotation.CommandArgument; import dev.efekos.arn.annotation.modifier.Item; +import dev.efekos.arn.annotation.modifier.NumberLimitations; import dev.efekos.arn.resolver.CommandArgumentResolver; import net.minecraft.commands.CommandDispatcher; @@ -30,7 +31,7 @@ public boolean isApplicable(Parameter parameter) { @Override public ArgumentBuilder apply(Parameter parameter) { String s = parameter.getAnnotation(CommandArgument.class).value(); - Item.NumberLimitations limitations = parameter.getAnnotation(Item.NumberLimitations.class); + NumberLimitations limitations = parameter.getAnnotation(NumberLimitations.class); boolean b = limitations != null; return CommandDispatcher.a(s.isEmpty() ?parameter.getName():s, b?FloatArgumentType.floatArg(limitations.min(),limitations.max()):FloatArgumentType.floatArg()); } diff --git a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdIntArg.java b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdIntArg.java index 577026b..25f781f 100644 --- a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdIntArg.java +++ b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdIntArg.java @@ -5,6 +5,7 @@ import dev.efekos.arn.annotation.CommandArgument; import dev.efekos.arn.annotation.modifier.InventorySlot; import dev.efekos.arn.annotation.modifier.Item; +import dev.efekos.arn.annotation.modifier.NumberLimitations; import dev.efekos.arn.resolver.CommandArgumentResolver; import net.minecraft.commands.CommandDispatcher; @@ -31,7 +32,7 @@ public boolean isApplicable(Parameter parameter) { @Override public ArgumentBuilder apply(Parameter parameter) { String s = parameter.getAnnotation(CommandArgument.class).value(); - Item.NumberLimitations limitations = parameter.getAnnotation(Item.NumberLimitations.class); + NumberLimitations limitations = parameter.getAnnotation(NumberLimitations.class); boolean b = limitations != null; return CommandDispatcher.a(s.isEmpty() ?parameter.getName():s, b? IntegerArgumentType.integer((int)limitations.min(),(int)limitations.max()):IntegerArgumentType.integer()); } diff --git a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdLongArg.java b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdLongArg.java index f281762..e9cbbe7 100644 --- a/src/main/java/dev/efekos/arn/resolver/impl/command/CmdLongArg.java +++ b/src/main/java/dev/efekos/arn/resolver/impl/command/CmdLongArg.java @@ -3,7 +3,7 @@ import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.builder.ArgumentBuilder; import dev.efekos.arn.annotation.CommandArgument; -import dev.efekos.arn.annotation.modifier.Item; +import dev.efekos.arn.annotation.modifier.NumberLimitations; import dev.efekos.arn.resolver.CommandArgumentResolver; import net.minecraft.commands.CommandDispatcher; @@ -30,7 +30,7 @@ public boolean isApplicable(Parameter parameter) { @Override public ArgumentBuilder apply(Parameter parameter) { String s = parameter.getAnnotation(CommandArgument.class).value(); - Item.NumberLimitations limitations = parameter.getAnnotation(Item.NumberLimitations.class); + NumberLimitations limitations = parameter.getAnnotation(NumberLimitations.class); boolean b = limitations != null; return CommandDispatcher.a(s.isEmpty() ?parameter.getName():s, b? LongArgumentType.longArg(limitations.min(),limitations.max()):LongArgumentType.longArg()); }