310 Commits

Author SHA1 Message Date
Omer Oreg 0b717ba9c0 Made ShowCommandHelp constructors public
This makes it so you can throw the exception from outside the package.
2020-04-12 13:21:44 -04:00
portlek 3a3734730c turkish language support 2020-04-12 13:19:35 -04:00
Hasan Demirtaş 5953e6a99e toLowerCase method with Locale.ENGLISH parameter.
Fixes #255
2020-04-12 13:19:35 -04:00
Tim Hagemann 2ba6895e0c Specifically ignore annotations in java package for meta-annotations
There's no world in which a java annotation contains one of the
command annotations and may only lead to infinite recursion.
2020-04-06 10:36:31 -04:00
Tim Hagemann 667dfec904 Support simple meta-annotations
This adds basic support for meta-annotations for commands and
parameters and allows users to create their own custom annotations
combining certain existing annotations and values. For example, a user
 can now define their own `CustomAnnotation` which combines a
condition and a flag:

```java
@Conditions("conditionname:confitionconfig")
@Flags("flagconfig=flagvalue")
public @interface CustomAnnotation {}
```
(Necessary `@Retention` and `@Target` ignore for brevity)
And use it just like they would normally.

This works by recursively going through the annotations, instead of
just looking at the root level. The reason most existing annotations
had to be touched is for them to be allowed on other annotations as
most of them were restricted to method or fields.

Currently there's no limit on nesting because if the user wants to
nest it to obscure levels - so be it. We could decide to limit this at
 some point to prevent users from shooting themselves in the foot if
that's necessary.

`@Dependency` and was specifically ignored as I don't think it makes
sense for that to be supported in this use case.

Relates to: #89
2020-04-06 10:36:31 -04:00
JOO200 eb7064f7c4 Exception handling: Handle CompletionException like ExecutionException 2020-04-06 10:34:49 -04:00
Joo200 34a60b920a Fix wrong output for default context resolver for numbers. 2019-11-17 11:27:43 -05:00
MalzSmith 82c431426d Added hungarian language (#236) 2019-08-19 07:16:17 -05:00
chickeneer ec4816fe1b Fix Index out of bound error in completions for no parameter commands 2019-08-06 21:28:47 -05:00
JOO200 d17055eb99 Use getter for command conditions (#225) 2019-07-08 17:16:18 -05:00
chickeneer 7292c50f4a Do not filter out valid completion arguments
Fixes a bug introduced by PR 200. The bug related to the Values annotation which uses this getCompletionValues method also.

This is definitely not the propersolution. The underlying issue is
related to the logic calling `args` which is the original argument
array. And it should not be using arguments which have been resolved in
a previous parameter.
I was not able to find a quick/simple way to accommodate that issue.
2019-06-05 11:20:10 -05:00
MrIvanPlays 280e2f0da3 Make InvalidCommandArgument a runtime exception 2019-04-03 08:08:49 +03:00
Aikar 4cc8d5a9e8 Fix help page count 2019-04-01 17:38:23 -04:00
Aikar 4aef08f587 also check for null 2019-03-31 18:57:44 -04:00
Aikar 1be6a0b3cb check for null 2019-03-31 18:56:29 -04:00
JOO200 7583dc8810 Add support for CompletableFuture exception. (#206)
This PR adds support for exceptions in CompletableFuture in Commands.

Usage: Just return a CompletableFuture. ACF will catch the exceptionally stuff.
```java
public CompletableFuture<Void> futuredExecution(Player player) {
    return CompletableFuture.failedFuture(new InvalidCommandArgument("Failed in future.", false));
}
```
2019-03-31 13:00:24 -04:00
MrIvanPlays 3416c2e7ad Add bulgarian language (#204) 2019-03-28 13:26:04 -04:00
Aikar 07d5fa671c Fix some bugs with RegisteredCommand 2019-03-26 17:58:02 -04:00
JOO200 72d45739c9 Add support for multi word tab completion (#200)
I added support for multi word tab completion.

Current problem:
the replacement "example" contains completions with whitespaces
```java
@CommandCompletion("@example")
public void test(Player player, String takesTheRest) {...}
```
"takesTheRest" takes all the whole rest howewer the tab completion only supports one word.

I don't use the ACFUtils much and maybe there are some ugly checks, feel free to refactor.
2019-03-24 09:43:43 -04:00
Aikar b3823ac2f0 Let's try oracle jdk since travis has issues with openjdk 2019-03-23 12:24:10 -04:00
Jeremy Wood 1c056cea45 Added basic JUnit5 testing framework. (#202) 2019-03-23 12:01:49 -04:00
Aikar 5a35fa25fc Handle future use of computePermissions to recalculate all children
Not used atm but while its fresh on mind....
2019-03-15 19:24:47 -04:00
Aikar 42867fe194 compute BaseCommand permissions before RegisteredCommands
Need to be computed for inheritance
2019-03-15 19:18:47 -04:00
Aikar 9c1521a456 Implement Bukkit Description for /help 2019-03-14 23:18:41 -04:00
Aikar e9857cb8b3 Adjust default parameter help output 2019-03-14 23:07:37 -04:00
Aikar 4e103adca4 Add Proper support for Default Completion Handlers 2019-03-14 22:34:56 -04:00
Aikar aa2e6ad1f8 Don't repeat last command completion unless its prefixed repeat 2019-03-12 21:52:50 -04:00
Aikar 23dd046b8e Improve parameter permissions and fix RC permission check 2019-03-09 11:27:58 -05:00
Kévin Jimenez d2754b99c9 Add support for CommandPermission annotation as parameter for permiss… (#197)
…ions by Optional annotation

In the past we could not handle a permission in relation to the presence of an optional argument, it forced us to manage it in the body of the command, and could be repetitive and boring, note that it also works with the annotation Default
2019-03-09 11:03:04 -05:00
Aikar ced74bc5d3 Support private methods too on local class.
we stil inherit public methods as previous
2019-03-03 11:11:58 -05:00
JOO200 7670224d81 Set default help page to one. (#196)
Fix for empty helps with CommandManager#generateCommandHelp()
2019-02-27 17:40:15 -05:00
Aikar 1b799355c5 fix command completions for aliases too 2019-02-25 23:00:31 -05:00
Aikar 6a7766e35d Fix command routing for forwarding commands
completions still funky, but least get execution working
2019-02-25 22:46:48 -05:00
Aikar 5d11925813 Fix NPE in help - Fixes #162 2019-02-25 22:27:03 -05:00
Aikar 67d631d47c Move to an improved CommandRouter, improve routing logic
now supports splitting commands over multiple BaseCommands better
should now only match probable @Default handlers, so @CatchUnknown
can still work in obviously wrong scenarios.

@HelpCommand no longer implies @Default as @CatchUnknown will pick it up
2019-02-25 21:45:12 -05:00
Aikar 9032570ca2 Fix getFirstElement to not care if there is more than 1 2019-02-24 13:19:25 -05:00
Aikar 4ef33613fc Do deep lookups on Private annotations
Added method to help do parent/enclosing based lookups
2019-02-23 22:32:05 -05:00
Aikar 115861be9a Fix Default handlers that consume input - #192 Fixed 2019-02-23 21:55:30 -05:00
Aikar a23ff21abf Improve code for scope lookup 2019-02-23 21:43:55 -05:00
JOO200 f235281112 Improve command handling from unknown commands (#195)
Currently there has to be the `@CatchUnknown` method in the same class as the `@Default` method.
Without finding any methods for handling unknown commands the default fallback method is the first registered or the class with `@Default` annotated method inside.

Maybe the solution to throw an exception for an unknown command is better.
The BaseCommand tries to execute the command context and if it's not possible it will throw an UnknownCommandException or smth like that.
2019-02-23 21:39:32 -05:00
JOO200 f893e37c97 Added Method-Getter in RegisteredCommand class (#193)
I want to use own annotations for help implementations (link, tooltips, short description etc.)
I can't access the method directly for the annotations, please add the getter ;)
2019-02-21 19:14:58 -05:00
Aikar 7282dade69 fix arg limit on completion context lookup and remove debug 2019-02-21 18:28:21 -05:00
Aikar 6303cce395 use better exception and reformat completions 2019-02-21 18:28:02 -05:00
Xavier 8db8d8b183 Fixed an issue where RegisteredCommand mutates the scopes required pe… (#190)
…rmissions and added caching to RegisteredCommand permissions
2019-02-14 16:33:34 -05:00
Xavier b96baaedac BaseCommand#hasPermission checks the required permissions (#188)
Currently the BaseCommand#hasPermission method doesn't actually check if the user has all the required permissions to execute a command, resulting in the following issue:

If user has permission permission.a they can execute:
/example
/example test
/example sub
/example sub testsub

Which is proper but if the user doesn't have permission.a they can only execute:
/example sub testsub

Example code:
```java
@CommandAlias("example")
@CommandPermission("permission.a")
public class ExampleCommand extends BaseCommand {

    @HelpCommand
    public void help(CommandHelp help) {
        help.showHelp();
    }

    @Subcommand("test")
    public void test(CommandSender sender) {
        sender.sendMessage("has permission to test?");
    }

    @Subcommand("sub")
    public class ExampleBCommand extends BaseCommand {

        @Subcommand("testsub")
        public void testSub(CommandSender sender) {
            sender.sendMessage("has permission to testSub?");
        }

    }

    @Subcommand("othersub")
    @CommandPermission("permission.b")
    public class ExampleCCommand extends BaseCommand {

        @Subcommand("othersub")
        public void otherSub(CommandSender sender) {
            sender.sendMessage("has permission to otherSub?");
        }

    }
}
```
2019-02-12 17:00:31 -05:00
Aikar 6481f22ea4 Fix last context for forwarding commands - Closes #179 2019-02-11 20:10:46 -05:00
Aikar 999c803091 Improve permission resolution of RootCommand's
ACF's permission tree can go more complex where a single root command
may have multiple dependent perm nodes.

So essentially ACF does not assign permission nodes to root in bukkit
and the such in a reasonable manner.

With this commit, we try to identify a single unique permission node,
and assign that permission node as the node to use where applicable.

In Bukkit/Sponge, we implement testPermission instead, which does a smarter
look up of all potential commands that root command might execute for the
given issuer, and if they have permission to any of them, then pass as true.

This is much more accurate, so if the issuer has access to no subcommand
then the root command should not be revealed anymore in Bukkit or Sponge.

In bungee, we are best guess at the unique perm node, and if there is
any ambiguity, it will be null and seen by everyone (but still enforces
permission checks)
2019-02-05 00:56:08 -05:00
Aikar 227052f6a2 Fix getContextValue resolving too many args 2019-02-05 00:52:55 -05:00
Aikar ebd60df1f4 Formatting changes 2019-02-05 00:52:44 -05:00
Aikar 2f8b21d865 Fix tabComplete isAsync 2019-02-04 21:23:49 -05:00