|
| 1 | +### Maven repository |
| 2 | + |
| 3 | +The Maven repository used to serve the CommandAPI has changed from JitPack.io to Maven Central. For Maven projects, you no longer require wan explicit `<repository>` entry for the CommandAPI. for Gradle projects, you need to ensure `mavenCentral()` in present in your `repositories` section. |
| 4 | + |
| 5 | +**The group ID has changed from `dev.jorel.CommandAPI` to `dev.jorel`** |
| 6 | + |
| 7 | +More information about setting up your development environment can be found in [Setting up your development environment](../dev-setup/setup). |
| 8 | + |
| 9 | +### CommandAPI command failures |
| 10 | + |
| 11 | +The `CommandAPI.fail()` no longer automatically throws the exception that it creates, and instead now requires you to manually throw the exception yourself. This improves upon invalid states in command executors and allows invalid states to be identified more easily at compile time. To update, simply add the `throw` keyword before you call `CommandAPI.fail()`: |
| 12 | + |
| 13 | +```java |
| 14 | +new CommandAPICommand("mycommand") |
| 15 | + .executes((sender, args) -> { |
| 16 | + if(!sender.hasPermission("some.permission")) { |
| 17 | + CommandAPI.fail("You don't have permission to run /mycommand!"); // [!code --] |
| 18 | + return; // [!code --] |
| 19 | + throw CommandAPI.fail("You don't have permission to run /mycommand!"); // [!code ++] |
| 20 | + } |
| 21 | + sender.sendMessage("Hello!"); |
| 22 | + }) |
| 23 | +``` |
| 24 | + |
| 25 | +### Suggestions |
| 26 | + |
| 27 | +Suggestions have been overhauled and no longer take in a `Function<SuggestionsInfo, String[]>` anymore. Instead, they now take in a `ArgumentSuggestions` object which represents argument suggestions (and whether they are executed asynchronously or have tooltips). |
| 28 | + |
| 29 | +#### Normal (string) suggestions |
| 30 | + |
| 31 | +These normal suggestions methods have been replaced with an `ArgumentSuggestions` parameter instead of a function: |
| 32 | + |
| 33 | +```java |
| 34 | +Argument replaceSuggestions(Function<SuggestionInfo, String[]> suggestions); // [!code --] |
| 35 | +Argument includeSuggestions(Function<SuggestionInfo, String[]> suggestions); // [!code --] |
| 36 | + |
| 37 | +Argument replaceSuggestions(ArgumentSuggestions suggestions); // [!code ++] |
| 38 | +Argument includeSuggestions(ArgumentSuggestions suggestions); // [!code ++] |
| 39 | +``` |
| 40 | + |
| 41 | +The same functionality can be reproduced by wrapping your existing functions in `ArgumentSuggestions.strings`: |
| 42 | + |
| 43 | +```java |
| 44 | +List<Argument> arguments = new ArrayList<>(); |
| 45 | +arguments.add(new StringArgument("world").replaceSuggestions(info -> // [!code --] |
| 46 | +arguments.add(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(info -> // [!code ++] |
| 47 | + new String[] {"northland", "eastland", "southland", "westland" } |
| 48 | +))); |
| 49 | +``` |
| 50 | + |
| 51 | +#### Normal (strings with tooltips) suggestions |
| 52 | + |
| 53 | +The `...T()` methods have been replaced with the normal methods above, and can use the `ArgumentSuggestions.stringsWithTooltips` method: |
| 54 | + |
| 55 | +```java |
| 56 | +Argument replaceSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions); // [!code --] |
| 57 | +Argument includeSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions); // [!code --] |
| 58 | + |
| 59 | +Argument replaceSuggestions(ArgumentSuggestions suggestions); // [!code ++] |
| 60 | +Argument includeSuggestions(ArgumentSuggestions suggestions); // [!code ++] |
| 61 | +``` |
| 62 | + |
| 63 | +For example: |
| 64 | + |
| 65 | +```java |
| 66 | +List<Argument> arguments = new ArrayList<>(); |
| 67 | +arguments.add(new StringArgument("emote") |
| 68 | + .replaceSuggestionsT( info -> new IStringTooltip[] { // [!code --] |
| 69 | + .replaceSuggestions(ArgumentSuggestions.stringsWithTooltips(info -> new IStringTooltip[] { // [!code ++] |
| 70 | + StringTooltip.of("wave", "Waves at a player"), |
| 71 | + StringTooltip.of("hug", "Gives a player a hug"), |
| 72 | + StringTooltip.of("glare", "Gives a player the death glare") |
| 73 | + } |
| 74 | + )) |
| 75 | +); |
| 76 | +``` |
| 77 | + |
| 78 | +#### Safe suggestions |
| 79 | + |
| 80 | +Similar to above with normal suggestions, safe suggestions have been replaced with `replaceSafeSuggestions` and `includeSafeSuggestions` respectively: |
| 81 | + |
| 82 | +```java |
| 83 | +Argument replaceWithSafeSuggestions(Function<SuggestionInfo, S[]> suggestions); // [!code --] |
| 84 | +Argument includeWithSafeSuggestions(Function<SuggestionInfo, S[]> suggestions); // [!code --] |
| 85 | + |
| 86 | +Argument replaceSafeSuggestions(SafeSuggestions<T> suggestions); // [!code ++] |
| 87 | +Argument includeSafeSuggestions(SafeSuggestions<T> suggestions); // [!code ++] |
| 88 | +``` |
| 89 | + |
| 90 | +These can be used with the `SafeSuggestions.suggest` and `SafeSuggestions.tooltips` methods to wrap existing functions. For example: |
| 91 | + |
| 92 | +```java |
| 93 | +List<Argument> arguments = new ArrayList<>(); |
| 94 | +arguments.add(new RecipeArgument("recipe").replaceWithSafeSuggestions(info -> // [!code --] |
| 95 | +arguments.add(new RecipeArgument("recipe").replaceSafeSuggestions(SafeSuggestions.suggest(info -> // [!code ++] |
| 96 | + new Recipe[] { emeraldSwordRecipe, /* Other recipes here */ } |
| 97 | +))); |
| 98 | +``` |
0 commit comments