diff --git a/.gitignore b/.gitignore index 7165e983f..b0a8d5cdc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,9 @@ reference-code.iml reference-code/reference-code.iml reference-code/target reference-code/build -reference-code/.kotlin -reference-code/.gradle +reference-code/**/build +**/.kotlin +**/.gradle package-lock.json .vscode \ No newline at end of file diff --git a/README.md b/README.md index fddb14bb6..f5d70f07c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ yarn install yarn docs:build ``` +### View website changes locally + +```bash +yarn docs:dev +``` + ### Verify reference code ```bash diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index d0ad3708a..147758e71 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -114,7 +114,7 @@ const vitepressOptions: UserConfig = { }).then(_ => { }) }, - config: (md) => { + config: ( md) => { tabsPlugin(md); injectUpgradingPartsPlugin(md); mermaidSpaceConverter(md); diff --git a/docs/.vitepress/theme/preference/PreferenceSwitch.vue b/docs/.vitepress/theme/preference/PreferenceSwitch.vue index 8bd96e533..976ac733b 100644 --- a/docs/.vitepress/theme/preference/PreferenceSwitch.vue +++ b/docs/.vitepress/theme/preference/PreferenceSwitch.vue @@ -4,7 +4,12 @@ import {VTIconChevronDown, VTSwitch} from '@vue/theme' import {useData, useRoute} from 'vitepress' import {onMounted, ref, Ref, watch} from 'vue' -import {openPreference, openPreferenceKey, preferGroovyInGradle, preferGroovyInGradleKey, preferMaven, preferMavenKey, preferReobf, preferReobfKey,} from "./preference"; +import { + openPreference, openPreferenceKey, + preferPaper, preferPaperKey, + preferGroovyInGradle, preferGroovyInGradleKey, + preferMaven, preferMavenKey +} from "./preference"; const {frontmatter} = useData(); let preferencesToDisplay: Ref = ref(); @@ -36,6 +41,12 @@ const restoreOutline = (e: Event) => { (e.target as HTMLElement).classList.remove('no-outline'); }; +const togglePaper = useToggleFn( + preferPaperKey, + preferPaper, + 'prefer-paper' +) + const toggleMaven = useToggleFn( preferMavenKey, preferMaven, @@ -48,12 +59,6 @@ const toggleGradleDsl = useToggleFn( 'prefer-groovy' ); -const toggleMapping = useToggleFn( - preferReobfKey, - preferReobf, - 'prefer-reobf' -) - function useToggleFn( storageKey: string, state: Ref, @@ -77,9 +82,9 @@ function useToggleFn( refresh() onMounted(() => { + togglePaper(preferPaper.value); toggleMaven(preferMaven.value); toggleGradleDsl(preferGroovyInGradle.value); - toggleMapping(preferReobf.value); }); @@ -102,6 +107,16 @@ onMounted(() => { :aria-hidden="!openPreference" >
+
+ + + +
{ />
-
- - - -

@@ -270,59 +275,63 @@ onMounted(() => { \ No newline at end of file diff --git a/docs/.vitepress/theme/preference/preference.ts b/docs/.vitepress/theme/preference/preference.ts index ac3e0c39a..2cb486d7d 100644 --- a/docs/.vitepress/theme/preference/preference.ts +++ b/docs/.vitepress/theme/preference/preference.ts @@ -12,11 +12,11 @@ function getBoolean(key: string, defaultValue: boolean) { export const openPreferenceKey = 'command-api-docs-prefer-open-preference' export const openPreference = ref(getBoolean(openPreferenceKey, true)) +export const preferPaperKey = 'command-api-docs-prefer-paper' +export const preferPaper = ref(getBoolean(preferPaperKey, true)) + export const preferMavenKey = 'command-api-docs-prefer-maven' export const preferMaven = ref(getBoolean(preferMavenKey, false)) export const preferGroovyInGradleKey = 'command-api-docs-prefer-groovy-dsl-in-gradle' -export const preferGroovyInGradle = ref(getBoolean(preferGroovyInGradleKey, false)) - -export const preferReobfKey = 'command-api-docs-prefer-mojmap' -export const preferReobf = ref(getBoolean(preferReobfKey, false)) \ No newline at end of file +export const preferGroovyInGradle = ref(getBoolean(preferGroovyInGradleKey, false)) \ No newline at end of file diff --git a/docs/.vitepress/theme/upgrading/upgrading.ts b/docs/.vitepress/theme/upgrading/upgrading.ts index 0c39b9329..95d0fe785 100644 --- a/docs/.vitepress/theme/upgrading/upgrading.ts +++ b/docs/.vitepress/theme/upgrading/upgrading.ts @@ -19,6 +19,7 @@ export const upgradingInfos: UpgradingInfo[] = [ {from: '9.0.3', to: '9.1.0'}, {from: '9.2.0', to: '9.3.0'}, {from: '9.7.0', to: '10.0.0'}, + {from: '10.1.2', to: '11.0.0'} ] export const keyVersions = Array.from(new Set(upgradingInfos.map(info => [info.from, info.to]).flat())); diff --git a/docs/en/annotations/annotations.md b/docs/en/annotations/annotations.md index 035f9a809..b35abcc8a 100644 --- a/docs/en/annotations/annotations.md +++ b/docs/en/annotations/annotations.md @@ -14,25 +14,25 @@ This page outlines in detail the list of all annotations that the CommandAPI's a The `@Command` annotation is used to declare a command. The parameter is the name of the command that will be registered. -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#declareCommand +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#declareCommand ### `@Alias({...})` The `@Alias` annotation is used to declare a list of aliases for a command. The parameter is a list of aliases which can be used for the command. -<<< @/../reference-code/src/main/java/annotations/aliasClassExample/TeleportCommand.java#aliasClassExample +<<< @/../reference-code/bukkit/src/main/java/annotations/aliasClassExample/TeleportCommand.java#aliasClassExample ### `@Permission("permissionNode")` The `@Permission` annotation is used to add a permission node to a command. Users that want to run this command must have this permission. The parameter is the permission node required to run the command. -<<< @/../reference-code/src/main/java/annotations/permissionClassExample/TeleportCommand.java#permissionClassExample +<<< @/../reference-code/bukkit/src/main/java/annotations/permissionClassExample/TeleportCommand.java#permissionClassExample ### `@NeedsOp` The `@NeedsOp` annotation is used to indicate that a command needs to have operator privileges to run it. This annotation has no parameters. -<<< @/../reference-code/src/main/java/annotations/needsOpClassExample/TeleportCommand.java#needsOpClassExample +<<< @/../reference-code/bukkit/src/main/java/annotations/needsOpClassExample/TeleportCommand.java#needsOpClassExample ### `@Help("Full description")` @@ -40,11 +40,11 @@ The `@Help` annotation is used to add a help topic to a command. This annotation A simple form which just uses a string which is used as the full description for a command: -<<< @/../reference-code/src/main/java/annotations/helpClassExample/TeleportCommand.java#helpClassExample +<<< @/../reference-code/bukkit/src/main/java/annotations/helpClassExample/TeleportCommand.java#helpClassExample A form with two parameters `value` and `shortDescription`, to provide the full description (`value`) and short description (`shortDescription`) content for a command: -<<< @/../reference-code/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java#shortHelpClassExample +<<< @/../reference-code/bukkit/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java#shortHelpClassExample ## Annotations that go on methods @@ -54,27 +54,27 @@ To use annotations on methods, **methods must be static**. The `@Default` annotation indicates that the method is _not_ a subcommand. This acts in a similar way to regular Bukkit commands. Commands with the `@Default` annotation can be used to run the main code when the command named with the `@Command` annotation is stated, such as the following: -<<< @/../reference-code/src/main/java/annotations/DefaultMethodExample.java#defaultMethodExample +<<< @/../reference-code/bukkit/src/main/java/annotations/DefaultMethodExample.java#defaultMethodExample The `@Default` annotation does not mean that the command can't have arguments! Arguments can still be used and declared as shown: -<<< @/../reference-code/src/main/java/annotations/DefaultMethodExample.java#defaultWithArgsMethodExample +<<< @/../reference-code/bukkit/src/main/java/annotations/DefaultMethodExample.java#defaultWithArgsMethodExample ### `@Subcommand` The `@Subcommand` simply tells the CommandAPI that the declared method is a subcommand. This acts in a similar way to the regular CommandAPI's `.withSubcommand()` method. The subcommand annotation can take in a single string which is the name of the subcommand: -<<< @/../reference-code/src/main/java/annotations/SubcommandMethodExample.java#subcommandMethodExample +<<< @/../reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java#subcommandMethodExample Or, it can take in a list of strings which represent the _aliases_ that can also be used for the declared subcommand: -<<< @/../reference-code/src/main/java/annotations/SubcommandMethodExample.java#subcommandAliasesMethodExample +<<< @/../reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java#subcommandAliasesMethodExample ### `@Permission` The `@Permission` annotation can also be used on methods to indicate that a permission is required to execute a command. -<<< @/../reference-code/src/main/java/annotations/PermissionMethodExample.java#permissionMethodExample +<<< @/../reference-code/bukkit/src/main/java/annotations/PermissionMethodExample.java#permissionMethodExample ### `@NeedsOp` @@ -88,14 +88,14 @@ The annotations for arguments are really simple, there are just two things you n $$\begin{align} \texttt{StringArgument}&\xrightarrow{A}\texttt{@AStringArgument}\\\\ -\texttt{PlayerArgument}&\xrightarrow{A}\texttt{@APlayerArgument}\\\\ +\texttt{IntegerArgument}&\xrightarrow{A}\texttt{@AIntegerArgument}\\\\ \texttt{AdvancementArgument}&\xrightarrow{A}\texttt{@AAdvancementArgument}\\\\ &\hspace{0.75em}\vdots \end{align}$$ For example, we use `@AStringArgument` to indicate that this command takes a `StringArgument` as its first parameter: -<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#simpleParameterExample +<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#simpleParameterExample - **The name of the argument (referred to as "nodeName" in the normal CommandAPI system) is the name of the variable assigned to the parameter.** In the above code, this means that the name of the argument is `warpName`. @@ -107,7 +107,7 @@ Certain argument annotations have extra parameters that can be supplied to provi The following numerical arguments can take both a `min` and `max` value. Both of these are completely optional. This indicates the range of values (inclusive) that is valid for this argument. For example: -<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#numericalParameterExample +<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#numericalParameterExample #### Literal arguments @@ -115,10 +115,10 @@ Both the `LiteralArgument` and `MultiLiteralArgument` can be used. When these ar For the `@ALiteralArgument` annotation, the parameter is the literal to be used for the command. For the `@AMultiLiteralArgument`, the parameter can be an array of multiple literals to use: -<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#literalParameterExample +<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#literalParameterExample #### Other arguments The `LocationArgument`, `Location2DArgument`, `EntitySelectorArgument` and `ScoreHolderArgument` can all take an extra parameter in their constructors. As a result, the annotation-equivalent of these arguments also allow you to provide the parameter in the annotation: -<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#otherParameterExample \ No newline at end of file +<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#otherParameterExample \ No newline at end of file diff --git a/docs/en/annotations/intro.md b/docs/en/annotations/intro.md index 0649e07c2..919b05c1f 100644 --- a/docs/en/annotations/intro.md +++ b/docs/en/annotations/intro.md @@ -43,7 +43,7 @@ Let's say we're writing a plugin with the capability to create warps to places o Using the regular CommandAPI, this is one way we can create this command. In the code below, we use StringArguments to represent the warp names. To teleport to a warp, we also populate it with suggestions (deferred so it updates), and also use a subcommand to represent `/warp create`: -<<< @/../reference-code/src/main/java/annotations/Intro.java#legacyExample +<<< @/../reference-code/bukkit/src/main/java/annotations/Intro.java#legacyExample Seems fairly straightforward, given everything else covered in this documentation. Now let's compare it to using annotations! @@ -51,22 +51,22 @@ Seems fairly straightforward, given everything else covered in this documentatio I think it's best to show the example and explain it afterwards: -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#annotationsExample +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#annotationsExample -<<< @/../reference-code/src/main/java/annotations/Intro.java#annotationsRegisterExample +<<< @/../reference-code/bukkit/src/main/java/annotations/Intro.java#annotationsRegisterExample As we can see, the code certainly _looks_ very different to the normal registration method. Let's take it apart piece by piece to see what exactly is going on here. #### Command declaration -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#declareCommand +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#declareCommand Firstly, we declare our command `warp`. To do this, we use the `@Command` annotation and simply state the name of the command in the annotation. This annotation is attached to the class `WarpCommand`, which indicates that the whole class `WarpCommand` will be housing our command. The annotation framework is designed in such a way that an entire command is represented by a single class. This provides a more modular approach to command declaration that allows you to easily contain the methods of a command in one location. #### Default command -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#defaultExample +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#defaultExample Here, declare the main command implementation using the `@Default` annotation. The `@Default` annotation informs the CommandAPI that the method it is attached to does not have any subcommands. This is effectively the same as registering a regular command without using `.withSubcommand()`. @@ -74,7 +74,7 @@ Here, we simply write what happens when no arguments are run (i.e. the user just #### Default command (again!) -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#anotherDefaultExample +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#anotherDefaultExample We also have a second `@Default` annotated method, which handles our `/warp ` command. Because this isn't a subcommand (the warp to teleport to is not a subcommand, it's an argument), we're still using the `@Default` annotation. In this method, we include an argument with this command by using the `@AStringArgument` annotation. This argument uses the `StringArgument` class, and the name of this argument is "warpName", which is extracted from the name of the variable. Simply put, **the Annotation for an argument is A** followed by the name of the argument. This is synonymous with using the following: @@ -88,7 +88,7 @@ The second argument is a `String` object, which represents the result of our arg #### Subcommand -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#subcommandExample +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#subcommandExample Lastly, we declare a subcommand to allow us to run `/warp create `. To do this, we simply use the `@Subcommand` annotation. In this example, we also apply a permission node that is required to run the command by using the `@Permission` annotation. The rest is fairly straight forward - we declare an argument, in this case it's another `StringArgument` , so we use `@AStringArgument` and then declare everything else in a similar fashion to the default command executor. @@ -96,6 +96,6 @@ Lastly, we declare a subcommand to allow us to run `/warp create `. To do Registering the command is fairly simple and is a one-liner: -<<< @/../reference-code/src/main/java/annotations/Intro.java#annotationsRegisterExample +<<< @/../reference-code/bukkit/src/main/java/annotations/Intro.java#annotationsRegisterExample This line can be placed in your `onEnable()` or `onLoad()` method like you were registering a normal command. \ No newline at end of file diff --git a/docs/en/annotations/registration.md b/docs/en/annotations/registration.md index 3793ebad5..01e063cd2 100644 --- a/docs/en/annotations/registration.md +++ b/docs/en/annotations/registration.md @@ -16,10 +16,10 @@ CommandAPI.registerCommand(className) Say we have a simple command `/warp` that is defined as follows: -<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#annotationsExample +<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#annotationsExample We can register this in our `onLoad()` method so we can use this command from within Minecraft functions: -<<< @/../reference-code/src/main/java/annotations/Registration.java#registerCommand +<<< @/../reference-code/bukkit/src/main/java/annotations/Registration.java#registerCommand :::: \ No newline at end of file diff --git a/docs/en/create-commands/aliases.md b/docs/en/create-commands/aliases.md index 80dd24820..bcd1d57be 100644 --- a/docs/en/create-commands/aliases.md +++ b/docs/en/create-commands/aliases.md @@ -16,11 +16,11 @@ In this example, we register the command `/getpos` that returns the command send :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Aliases.java#aliasesExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Aliases.java#aliasesExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Aliases.kt#aliasesExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Aliases.kt#aliasesExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Aliases.kt#aliasesExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Aliases.kt#aliasesExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/arguments.md b/docs/en/create-commands/arguments/arguments.md index ebdf46940..bfe308892 100644 --- a/docs/en/create-commands/arguments/arguments.md +++ b/docs/en/create-commands/arguments/arguments.md @@ -1,5 +1,6 @@ --- order: 1 +preferences: ["paper-spigot"] authors: - DerEchtePilz - willkroboth @@ -22,8 +23,8 @@ Adding arguments for registration is simple: // Create a List List arguments = new ArrayList<>(); -// Add an argument with the node "target", which is a PlayerArgument -arguments.add(new PlayerArgument("target")); +// Add an argument with the node "target", which is a EntitySelectorArgument.OnePlayer +arguments.add(new EntitySelectorArgument.OnePlayer("target")); ``` The String value is the node that is registered into Minecraft's internal command graph. This name is also used as a prompt that is shown to a player when they are entering the command. @@ -32,29 +33,29 @@ The CommandAPI is very flexible when it comes to registering arguments, and lets :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsExampleDSL ::: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsVarargExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsVarargExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsVarargExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsVarargExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsVarargExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsVarargExampleDSL ::: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsListExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsListExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsListExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsListExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsListExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsListExampleDSL ::: ## Argument Casting @@ -63,76 +64,140 @@ To access arguments, they have to be casted to the type that the argument repres :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#argumentCastExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/Arguments.java#argumentCastExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#argumentCastExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#argumentCastExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#argumentCastExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt#argumentCastExampleDSL ::: The type to cast each argument (declared in the `dev.jorel.commandapi.arguments` package) is listed below: -| Argument class | Data type | -|------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [`AngleArgument`](./types/misc/angle-arguments) | `float` | -| [`AdvancementArgument`](./types/misc/advancement-arguments) | `org.bukkit.advancement.Advancement` | -| [`AdventureChatArgument`](./types/chat/adventure-chat-arguments) | `net.kyori.adventure.text.Component` | -| [`AdventureChatColorArgument`](./types/chat/adventure-chat-arguments#adventure-chat-color-argument) | `net.kyori.adventure.text.format.NamedTextColor` | -| [`AdventureChatComponentArgument`](./types/chat/adventure-chat-arguments#adventure-chat-component-argument) | `net.kyori.adventure.text.Component` | -| [`AxisArgument`](./types/position/axis-arguments) | `java.util.EnumSet` | -| [`BiomeArgument`](./types/misc/biome-arguments) | `org.bukkit.block.Biome` | -| [`BiomeArgument.NamespacedKey`](./types/misc/biome-arguments) | `org.bukkit.NamespacedKey` | -| [`BlockPredicateArgument`](./types/predicate/block-predicate-arguments) | `java.util.function.Predicate`
 `` | -| [`BlockStateArgument`](./types/misc/blockstate-arguments) | `org.bukkit.block.data.BlockData` | -| [`BooleanArgument`](./types/primitive-arguments#boolean-arguments) | `boolean` | -| [`ChatArgument`](./types/chat/spigot-chat-arguments#chat-argument) | `net.md_5.bungee.api.chat.BaseComponent[]` | -| [`ChatColorArgument`](./types/chat/spigot-chat-arguments#chat-color-argument) | `org.bukkit.ChatColor` | -| [`ChatComponentArgument`](./types/chat/spigot-chat-arguments#chat-component-argument) | `net.md_5.bungee.api.chat.BaseComponent[]` | -| [`CommandArgument`](./types/command-arguments) | `dev.jorel.commandapi.wrappers.CommandResult` | -| [`CustomArgument`](./types/custom-arguments) | `T` | -| [`DoubleArgument`](./types/primitive-arguments#numerical-arguments) | `double` | -| [`EnchantmentArgument`](./types/misc/enchantment-arguments) | `org.bukkit.enchantments.Enchantment` | -| [`EntitySelectorArgument.ManyEntities`](./types/entities-arguments#entity-selector-argument) | `Collection` | -| [`EntitySelectorArgument.ManyPlayers`](./types/entities-arguments#entity-selector-argument) | `Collection` | -| [`EntitySelectorArgument.OneEntity`](./types/entities-arguments#entity-selector-argument) | `org.bukkit.entity.Entity` | -| [`EntitySelectorArgument.OnePlayer`](./types/entities-arguments#entity-selector-argument) | `org.bukkit.entity.Player` | -| [`EntityTypeArgument`](./types/entities-arguments#entity-type-argument) | `org.bukkit.entity.EntityType` | -| [`FloatArgument`](./types/primitive-arguments#numerical-arguments) | `float` | -| [`FloatRangeArgument`](./types/ranged-arguments#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.FloatRange` | -| [`FunctionArgument`](../functions-and-tags/function-arguments) | `dev.jorel.commandapi.wrappers.FunctionWrapper[]` | -| [`GreedyStringArgument`](./types/string-arguments#greedy-string-argument) | `String` | -| [`IntegerArgument`](./types/primitive-arguments#numerical-arguments) | `int` | -| [`IntegerRangeArgument`](./types/ranged-arguments#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | -| [`ItemStackArgument`](./types/misc/itemstack-arguments) | `org.bukkit.inventory.ItemStack` | -| [`ItemStackPredicateArgument`](./types/predicate/itemstack-predicate-arguments) | `java.util.function.Predicate`
 `` | -| [`ListArgument`](./types/list-arguments) | `java.util.Collection` | -| [`LiteralArgument`](./types/literal/literal-arguments) | N/A | -| [`Location2DArgument`](./types/position/location-arguments#2d-location) | `dev.jorel.commandapi.wrappers.Location2D` | -| [`LocationArgument`](./types/position/location-arguments#3d-location) | `org.bukkit.Location` | -| [`LongArgument`](./types/primitive-arguments#numerical-arguments) | `long` | -| [`LootTableArgument`](./types/misc/loottable-arguments) | `org.bukkit.loot.LootTable` | -| [`MapArgument`](./types/map-arguments) | `java.util.LinkedHashMap` | -| [`MathOperationArgument`](./types/misc/mathoperation-arguments) | `dev.jorel.commandapi.wrappers.MathOperation` | -| [`MultiLiteralArgument`](./types/literal/multiliteral-arguments) | `String` | -| [`NamespacedKeyArgument`](./types/misc/namespacedkey-arguments) | `org.bukkit.NamespacedKey` | -| [`NBTCompoundArgument`](./types/nbt-arguments) | The cast type changes depending on whether you're shading the CommandAPI or using the CommandAPI as a plugin:
  • Shading:
    `T` (implemented yourself)

  • Plugin:
    `dev.jorel.commandapi.nbtapi.NBTContainer`
| -| [`ObjectiveArgument`](./types/scoreboard/objective-arguments#objective-argument) | `org.bukkit.scoreboard.Objective` | -| [`ObjectiveCriteriaArgument`](./types/scoreboard/objective-arguments#objective-criteria-argument) | `String` | -| [`OfflinePlayerArgument`](./types/entities-arguments#offlineplayer-argument) | `org.bukkit.OfflinePlayer` | -| [`ParticleArgument`](./types/misc/particle-arguments) | `dev.jorel.commandapi.wrappers.ParticleData` | -| [`PlayerArgument`](./types/entities-arguments#player-argument) | `org.bukkit.entity.Player` | -| [`PotionEffectArgument`](./types/misc/potion-arguments) | `org.bukkit.potion.PotionEffectType` | -| [`PotionEffectArgument.NamespacedKey`](./types/misc/potion-arguments) | `org.bukkit.NamespacedKey` | -| [`RecipeArgument`](./types/misc/recipe-arguments) | The cast type changes depending on your Minecraft version:
  • Version 1.14.4 and below:
    `org.bukkit.inventory.Recipe`

  • 1.15 and above:
    `org.bukkit.inventory.ComplexRecipe`
| -| [`RotationArgument`](./types/position/rotation-arguments) | `dev.jorel.commandapi.wrappers.Rotation` | -| [`ScoreboardSlotArgument`](./types/scoreboard/scoreboard-arguments#scoreboard-slot-argument) | `dev.jorel.commandapi.wrappers.ScoreboardSlot` | -| [`ScoreHolderArgument.Single`](./types/scoreboard/scoreboard-arguments#score-holder-argument) | `String` | -| [`ScoreHolderArgument.Multiple`](./types/scoreboard/scoreboard-arguments#score-holder-argument) | `Collection` | -| [`SoundArgument`](./types/misc/sound-arguments) | `org.bukkit.Sound` | -| [`SoundArgument.NamespacedKey`](./types/misc/sound-arguments) | `org.bukkit.NamespacedKey` | -| [`StringArgument`](./types/string-arguments#string-argument) | `String` | -| [`TeamArgument`](./types/scoreboard/team-arguments) | `org.bukkit.scoreboard.Team` | -| [`TextArgument`](./types/string-arguments#text-argument) | `String` | -| [`TimeArgument`](./types/misc/time-arguments) | `int` | -| [`UUIDArgument`](./types/misc/uuid-arguments) | `java.util.UUID` | -| [`WorldArgument`](./types/misc/world-arguments) | `org.bukkit.World` | \ No newline at end of file +
+ +| Argument class | Data type | +|---------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`AngleArgument`](./types/misc/angle-arguments) | `float` | +| [`AdvancementArgument`](./types/misc/advancement-arguments) | `org.bukkit.advancement.Advancement` | +| [`AxisArgument`](./types/position/axis-arguments) | `java.util.EnumSet` | +| [`BiomeArgument`](./types/misc/biome-arguments) | `org.bukkit.block.Biome` | +| [`BiomeArgument.NamespacedKey`](./types/misc/biome-arguments) | `org.bukkit.NamespacedKey` | +| [`BlockPredicateArgument`](./types/predicate/block-predicate-arguments) | `java.util.function.Predicate`
 `` | +| [`BlockStateArgument`](./types/misc/blockstate-arguments) | `org.bukkit.block.BlockState` | +| [`BooleanArgument`](./types/primitive-arguments#boolean-arguments) | `boolean` | +| [`ChatArgument`](./types/chat/adventure-chat-arguments#adventure-chat-argument) | `net.kyori.adventure.chat.SignedMessage` | +| [`ChatColorArgument`](./types/chat/adventure-chat-arguments#adventure-chat-color-argument) | `net.kyori.adventure.text.format.NamedTextColor` | +| [`ChatComponentArgument`](./types/chat/adventure-chat-arguments#adventure-chat-component-argument) | `net.kyori.adventure.text.Component` | +| [`CommandArgument`](./types/command-arguments) | `dev.jorel.commandapi.wrappers.CommandResult` | +| [`CustomArgument`](./types/custom-arguments) | `T` | +| [`DoubleArgument`](./types/primitive-arguments#numerical-arguments) | `double` | +| [`DoubleRangeArgument`](./types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.DoubleRange` | +| [`EnchantmentArgument`](./types/misc/enchantment-arguments) | `org.bukkit.enchantments.Enchantment` | +| [`EntitySelectorArgument.ManyEntities`](./types/entities-arguments#entity-selector-argument) | `Collection` | +| [`EntitySelectorArgument.ManyPlayers`](./types/entities-arguments#entity-selector-argument) | `Collection` | +| [`EntitySelectorArgument.OneEntity`](./types/entities-arguments#entity-selector-argument) | `org.bukkit.entity.Entity` | +| [`EntitySelectorArgument.OnePlayer`](./types/entities-arguments#entity-selector-argument) | `org.bukkit.entity.Player` | +| [`EntityTypeArgument`](./types/entities-arguments#entity-type-argument) | `org.bukkit.entity.EntityType` | +| [`FloatArgument`](./types/primitive-arguments#numerical-arguments) | `float` | +| [`FunctionArgument`](../functions-and-tags/function-arguments) | `dev.jorel.commandapi.wrappers.FunctionWrapper[]` | +| [`GreedyStringArgument`](./types/string-arguments#greedy-string-argument) | `String` | +| [`IntegerArgument`](./types/primitive-arguments#numerical-arguments) | `int` | +| [`IntegerRangeArgument`](./types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | +| [`ItemStackArgument`](./types/misc/itemstack-arguments) | `org.bukkit.inventory.ItemStack` | +| [`ItemStackPredicateArgument`](./types/predicate/itemstack-predicate-arguments) | `java.util.function.Predicate`
 `` | +| [`ListArgument`](./types/list-arguments) | `java.util.Collection` | +| [`LiteralArgument`](./types/literal/literal-arguments) | N/A | +| [`Location2DArgument`](./types/position/location-arguments#2d-location) | `dev.jorel.commandapi.wrappers.Location2D` | +| [`LocationArgument`](./types/position/location-arguments#3d-location) | `org.bukkit.Location` | +| [`LongArgument`](./types/primitive-arguments#numerical-arguments) | `long` | +| [`LootTableArgument`](./types/misc/loottable-arguments) | `org.bukkit.loot.LootTable` | +| [`MapArgument`](./types/map-arguments) | `java.util.LinkedHashMap` | +| [`MathOperationArgument`](./types/misc/mathoperation-arguments) | `dev.jorel.commandapi.wrappers.MathOperation` | +| [`MultiLiteralArgument`](./types/literal/multiliteral-arguments) | `String` | +| [`NamespacedKeyArgument`](./types/misc/namespacedkey-arguments) | `org.bukkit.NamespacedKey` | +| [`NBTCompoundArgument`](./types/nbt-arguments) | The cast type changes depending on whether you're shading the CommandAPI or using the CommandAPI as a plugin:
  • Shading:
    `T` (implemented yourself)

  • Plugin:
    `dev.jorel.commandapi.nbtapi.NBTContainer`
| +| [`ObjectiveArgument`](./types/scoreboard/objective-arguments#objective-argument) | `org.bukkit.scoreboard.Objective` | +| [`ObjectiveCriteriaArgument`](./types/scoreboard/objective-arguments#objective-criteria-argument) | `String` | +| [`ParticleArgument`](./types/misc/particle-arguments) | `dev.jorel.commandapi.wrappers.ParticleData` | +| [`PlayerProfileArgument`](./types/entities-arguments#playerprofile-argument) | `java.util.List` | +| [`PotionEffectArgument`](./types/misc/potion-arguments) | `org.bukkit.potion.PotionEffectType` | +| [`PotionEffectArgument.NamespacedKey`](./types/misc/potion-arguments) | `org.bukkit.NamespacedKey` | +| [`RecipeArgument`](./types/misc/recipe-arguments) | The cast type changes depending on your Minecraft version:
  • Version 1.14.4 and below:
    `org.bukkit.inventory.Recipe`

  • 1.15 and above:
    `org.bukkit.inventory.ComplexRecipe`
| +| [`RotationArgument`](./types/position/rotation-arguments) | `dev.jorel.commandapi.wrappers.Rotation` | +| [`ScoreboardSlotArgument`](./types/scoreboard/scoreboard-arguments#scoreboard-slot-argument) | `dev.jorel.commandapi.wrappers.ScoreboardSlot` | +| [`ScoreHolderArgument.Single`](./types/scoreboard/scoreboard-arguments#score-holder-argument) | `String` | +| [`ScoreHolderArgument.Multiple`](./types/scoreboard/scoreboard-arguments#score-holder-argument) | `Collection` | +| [`SoundArgument`](./types/misc/sound-arguments) | `org.bukkit.Sound` | +| [`SoundArgument.NamespacedKey`](./types/misc/sound-arguments) | `org.bukkit.NamespacedKey` | +| [`StringArgument`](./types/string-arguments#string-argument) | `String` | +| [`TeamArgument`](./types/scoreboard/team-arguments) | `org.bukkit.scoreboard.Team` | +| [`TextArgument`](./types/string-arguments#text-argument) | `String` | +| [`TimeArgument`](./types/misc/time-arguments) | `int` | +| [`UUIDArgument`](./types/misc/uuid-arguments) | `java.util.UUID` | +| [`WorldArgument`](./types/misc/world-arguments) | `org.bukkit.World` | + +
+
+ +| Argument class | Data type | +|--------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`AngleArgument`](./types/misc/angle-arguments) | `float` | +| [`AdvancementArgument`](./types/misc/advancement-arguments) | `org.bukkit.advancement.Advancement` | +| [`AxisArgument`](./types/position/axis-arguments) | `java.util.EnumSet` | +| [`BiomeArgument`](./types/misc/biome-arguments) | `org.bukkit.block.Biome` | +| [`BiomeArgument.NamespacedKey`](./types/misc/biome-arguments) | `org.bukkit.NamespacedKey` | +| [`BlockPredicateArgument`](./types/predicate/block-predicate-arguments) | `java.util.function.Predicate`
 `` | +| [`BlockStateArgument`](./types/misc/blockstate-arguments) | `org.bukkit.block.BlockState` | +| [`BooleanArgument`](./types/primitive-arguments#boolean-arguments) | `boolean` | +| [`ChatArgument`](./types/chat/spigot-chat-arguments#chat-argument) | `net.md_5.bungee.api.chat.BaseComponent[]` | +| [`ChatColorArgument`](./types/chat/spigot-chat-arguments#chat-color-argument) | `org.bukkit.ChatColor` | +| [`ChatComponentArgument`](./types/chat/spigot-chat-arguments#chat-component-argument) | `net.md_5.bungee.api.chat.BaseComponent[]` | +| [`CommandArgument`](./types/command-arguments) | `dev.jorel.commandapi.wrappers.CommandResult` | +| [`CustomArgument`](./types/custom-arguments) | `T` | +| [`DoubleArgument`](./types/primitive-arguments#numerical-arguments) | `double` | +| [`DoubleRangeArgument`](./types/ranged-arguments#the-integer-range-and-float-range-class) | `dev.jorel.commandapi.wrappers.DoubleRange` | +| [`EnchantmentArgument`](./types/misc/enchantment-arguments) | `org.bukkit.enchantments.Enchantment` | +| [`EntitySelectorArgument.ManyEntities`](./types/entities-arguments#entity-selector-argument) | `Collection` | +| [`EntitySelectorArgument.ManyPlayers`](./types/entities-arguments#entity-selector-argument) | `Collection` | +| [`EntitySelectorArgument.OneEntity`](./types/entities-arguments#entity-selector-argument) | `org.bukkit.entity.Entity` | +| [`EntitySelectorArgument.OnePlayer`](./types/entities-arguments#entity-selector-argument) | `org.bukkit.entity.Player` | +| [`EntityTypeArgument`](./types/entities-arguments#entity-type-argument) | `org.bukkit.entity.EntityType` | +| [`FloatArgument`](./types/primitive-arguments#numerical-arguments) | `float` | +| [`FunctionArgument`](../functions-and-tags/function-arguments) | `dev.jorel.commandapi.wrappers.FunctionWrapper[]` | +| [`GreedyStringArgument`](./types/string-arguments#greedy-string-argument) | `String` | +| [`IntegerArgument`](./types/primitive-arguments#numerical-arguments) | `int` | +| [`IntegerRangeArgument`](./types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | +| [`ItemStackArgument`](./types/misc/itemstack-arguments) | `org.bukkit.inventory.ItemStack` | +| [`ItemStackPredicateArgument`](./types/predicate/itemstack-predicate-arguments) | `java.util.function.Predicate`
 `` | +| [`ListArgument`](./types/list-arguments) | `java.util.Collection` | +| [`LiteralArgument`](./types/literal/literal-arguments) | N/A | +| [`Location2DArgument`](./types/position/location-arguments#2d-location) | `dev.jorel.commandapi.wrappers.Location2D` | +| [`LocationArgument`](./types/position/location-arguments#3d-location) | `org.bukkit.Location` | +| [`LongArgument`](./types/primitive-arguments#numerical-arguments) | `long` | +| [`LootTableArgument`](./types/misc/loottable-arguments) | `org.bukkit.loot.LootTable` | +| [`MapArgument`](./types/map-arguments) | `java.util.LinkedHashMap` | +| [`MathOperationArgument`](./types/misc/mathoperation-arguments) | `dev.jorel.commandapi.wrappers.MathOperation` | +| [`MultiLiteralArgument`](./types/literal/multiliteral-arguments) | `String` | +| [`NamespacedKeyArgument`](./types/misc/namespacedkey-arguments) | `org.bukkit.NamespacedKey` | +| [`NBTCompoundArgument`](./types/nbt-arguments) | The cast type changes depending on whether you're shading the CommandAPI or using the CommandAPI as a plugin:
  • Shading:
    `T` (implemented yourself)

  • Plugin:
    `dev.jorel.commandapi.nbtapi.NBTContainer`
| +| [`ObjectiveArgument`](./types/scoreboard/objective-arguments#objective-argument) | `org.bukkit.scoreboard.Objective` | +| [`ObjectiveCriteriaArgument`](./types/scoreboard/objective-arguments#objective-criteria-argument) | `String` | +| [`ParticleArgument`](./types/misc/particle-arguments) | `dev.jorel.commandapi.wrappers.ParticleData` | +| [`PlayerProfileArgument`](./types/entities-arguments#playerprofile-argument) | `java.util.List` | +| [`PotionEffectArgument`](./types/misc/potion-arguments) | `org.bukkit.potion.PotionEffectType` | +| [`PotionEffectArgument.NamespacedKey`](./types/misc/potion-arguments) | `org.bukkit.NamespacedKey` | +| [`RecipeArgument`](./types/misc/recipe-arguments) | The cast type changes depending on your Minecraft version:
  • Version 1.14.4 and below:
    `org.bukkit.inventory.Recipe`

  • 1.15 and above:
    `org.bukkit.inventory.ComplexRecipe`
| +| [`RotationArgument`](./types/position/rotation-arguments) | `dev.jorel.commandapi.wrappers.Rotation` | +| [`ScoreboardSlotArgument`](./types/scoreboard/scoreboard-arguments#scoreboard-slot-argument) | `dev.jorel.commandapi.wrappers.ScoreboardSlot` | +| [`ScoreHolderArgument.Single`](./types/scoreboard/scoreboard-arguments#score-holder-argument) | `String` | +| [`ScoreHolderArgument.Multiple`](./types/scoreboard/scoreboard-arguments#score-holder-argument) | `Collection` | +| [`SoundArgument`](./types/misc/sound-arguments) | `org.bukkit.Sound` | +| [`SoundArgument.NamespacedKey`](./types/misc/sound-arguments) | `org.bukkit.NamespacedKey` | +| [`StringArgument`](./types/string-arguments#string-argument) | `String` | +| [`TeamArgument`](./types/scoreboard/team-arguments) | `org.bukkit.scoreboard.Team` | +| [`TextArgument`](./types/string-arguments#text-argument) | `String` | +| [`TimeArgument`](./types/misc/time-arguments) | `int` | +| [`UUIDArgument`](./types/misc/uuid-arguments) | `java.util.UUID` | +| [`WorldArgument`](./types/misc/world-arguments) | `org.bukkit.World` | + +
\ No newline at end of file diff --git a/docs/en/create-commands/arguments/command-arguments.md b/docs/en/create-commands/arguments/command-arguments.md index 88226c76a..9c99e2695 100644 --- a/docs/en/create-commands/arguments/command-arguments.md +++ b/docs/en/create-commands/arguments/command-arguments.md @@ -109,9 +109,9 @@ This is how these commands are implemented: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getArgExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java#getArgExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getArgExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getArgExample ::: :::: @@ -168,9 +168,9 @@ We want to find out which entity selector is being used when the command is exec :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getRawExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java#getRawExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getRawExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getRawExample ::: :::: @@ -229,9 +229,9 @@ Here, we don't actually want to cast the argument, so we use unsafe arguments to :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getUncheckedExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java#getUncheckedExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getUncheckedExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getUncheckedExample ::: :::: @@ -290,9 +290,9 @@ To visualize this, we want to implement the command from [Access arguments by no :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getByArgumentExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java#getByArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getByArgumentExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getByArgumentExample ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/listed-arguments.md b/docs/en/create-commands/arguments/listed-arguments.md index 3562f3549..5a2dd23b7 100644 --- a/docs/en/create-commands/arguments/listed-arguments.md +++ b/docs/en/create-commands/arguments/listed-arguments.md @@ -31,11 +31,11 @@ Let's also say that in our implementation of this command, we don't actually per :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/ListedArguments.java#listedArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/ListedArguments.java#listedArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/ListedArguments.kt#listedArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/ListedArguments.kt#listedArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/ListedArguments.kt#listedArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/ListedArguments.kt#listedArgumentsExampleDSL ::: In this scenario, the argument `` is not present in the [`CommandArguments args`](./command-arguments) for the executor. diff --git a/docs/en/create-commands/arguments/optional-arguments.md b/docs/en/create-commands/arguments/optional-arguments.md index 911f3d77e..819616981 100644 --- a/docs/en/create-commands/arguments/optional-arguments.md +++ b/docs/en/create-commands/arguments/optional-arguments.md @@ -34,11 +34,11 @@ For that, we’re going to register a command `/sayhi`. To add optional argument :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/OptionalArguments.java#simpleOptionalArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/OptionalArguments.java#simpleOptionalArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#simpleOptionalArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#simpleOptionalArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#simpleOptionalArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#simpleOptionalArgumentsExampleDSL ::: @@ -65,12 +65,12 @@ When using the `withOptionalArguments` method it might be interesting to know th ```java new CommandAPICommand("optional") - .withOptionalArguments(new PlayerArgument("target")) + .withOptionalArguments(new EntitySelectorArgument.OnePlayer("target")) ``` ```java new CommandAPICommand("optional") - .withArguments(new PlayerArgument("target").setOptional(true)) + .withArguments(new EntitySelectorArgument.OnePlayer("target").setOptional(true)) ``` However, calling `withOptionalArguments` is safer because it makes sure that the argument is optional because of that internal call. @@ -103,11 +103,11 @@ This is how the `getOptional` method is being implemented: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/OptionalArguments.java#getOptionalExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/OptionalArguments.java#getOptionalExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#getOptionalExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#getOptionalExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#getOptionalExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#getOptionalExampleDSL ::: :::: @@ -131,7 +131,7 @@ At this point, your command is basically done. Any attempt to add a required argument will result in an `OptionalArgumentException`. However, this is where the `combineWith` method comes in. This method allows you to combine arguments. -Let's say you have an optional `StringArgument` (here simplified to `A`) and you want a required `PlayerArgument` (here simplified to `B`). +Let's say you have an optional `StringArgument` (here simplified to `A`) and you want a required `EntitySelectorArgument.OnePlayer` (here simplified to `B`). Argument `B` should only be required if argument `A` is given. To implement that logic, we’re going to use the `combineWith` method so that we have this syntax: @@ -144,7 +144,7 @@ This does two things: 1. When checking optional argument constraints the argument `B` will be ignored so the `OptionalArgumentException` will not be thrown 2. It allows you to define additional optional arguments afterwards which can only be entered if argument `B` has been entered -This is how you would add another optional `PlayerArgument` (here simplified to `C`): +This is how you would add another optional `EntitySelectorArgument.OnePlayer` (here simplified to `C`): ```java new CommandAPICommand("mycommand") @@ -176,11 +176,11 @@ To implement that structure, we make use of the `combineWith` method to make the :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/OptionalArguments.java#argumentsAfterOptionalArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/OptionalArguments.java#argumentsAfterOptionalArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#argumentsAfterOptionalArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#argumentsAfterOptionalArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#argumentsAfterOptionalArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt#argumentsAfterOptionalArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/suggestions/async-suggestions.md b/docs/en/create-commands/arguments/suggestions/async-suggestions.md index 24373caa2..f51abbb49 100644 --- a/docs/en/create-commands/arguments/suggestions/async-suggestions.md +++ b/docs/en/create-commands/arguments/suggestions/async-suggestions.md @@ -68,11 +68,11 @@ We make use of the `ArgumentSuggestions.stringsAsync` method to provide asynchro :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java#asyncSuggestionsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java#asyncSuggestionsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt#asyncSuggestionsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt#asyncSuggestionsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt#asyncSuggestionsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt#asyncSuggestionsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/suggestions/safe-suggestions.md b/docs/en/create-commands/arguments/suggestions/safe-suggestions.md index bac0bd17b..314b05107 100644 --- a/docs/en/create-commands/arguments/suggestions/safe-suggestions.md +++ b/docs/en/create-commands/arguments/suggestions/safe-suggestions.md @@ -1,5 +1,6 @@ --- order: 4 +preferences: ["paper-spigot"] authors: - Strokkur424 - DerEchtePilz @@ -42,6 +43,46 @@ Not all arguments support safe suggestions. This is mostly due to implementation The list of supported arguments are displayed in the following table. The parameter `T` (shown in the method signatures above) are also provided for each argument. This parameter is the same as the cast argument described in [Argument Casting](../command-arguments#argument-casting), except for a few exceptions which are outlined in **bold**. +
+ +| Argument | Class (T) | +|----------------------------------------------------------------------------------------------:|:----------------------------------------------------| +| [`AdvancementArgument`](../types/misc/advancement-arguments) | `org.bukkit.advancement.Advancement` | +| [`AxisArgument`](../types/position/axis-arguments) | `java.util.EnumSet` | +| [`BiomeArgument`](../types/misc/biome-arguments) | `org.bukkit.block.Biome` | +| [`BooleanArgument`](../types/primitive-arguments) | **`Boolean`** | +| [`ChatColorArgument`](../types/chat/spigot-chat-arguments#chat-color-argument) | `net.kyori.adventure.text.format.NamedTextColor` | +| [`DoubleArgument`](../types/primitive-arguments#numerical-arguments) | **`Double`** | +| [`DoubleRangeArgument`](../types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.DoubleRange` | +| [`EnchantmentArgument`](../types/misc/enchantment-arguments) | `org.bukkit.enchantments.Enchantment` | +| [`EntityTypeArgument`](../types/entities-arguments#entity-type-argument) | `org.bukkit.entity.EntityType` | +| [`FloatArgument`](../types/primitive-arguments#numerical-arguments) | **`Float`** | +| [`FunctionArgument`](../../functions-and-tags/function-arguments) | **`org.bukkit.NamespacedKey`** | +| [`GreedyStringArgument`](../types/string-arguments#greedy-string-argument) | `String` | +| [`IntegerArgument`](../types/primitive-arguments#numerical-arguments) | **`Integer`** | +| [`IntegerRangeArgument`](../types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | +| [`ItemStackArgument`](../types/misc/itemstack-arguments) | `org.bukkit.inventory.ItemStack` | +| [`Location2DArgument`](../types/position/location-arguments#2d-location) | `dev.jorel.commandapi.wrappers.Location2D` | +| [`LocationArgument`](../types/position/location-arguments#3d-location) | `org.bukkit.Location` | +| [`LongArgument`](../types/primitive-arguments#numerical-arguments) | **`Long`** | +| [`LootTableArgument`](../types/misc/loottable-arguments) | `org.bukkit.loot.LootTable` | +| [`MathOperationArgument`](../types/misc/mathoperation-arguments) | `dev.jorel.commandapi.wrappers.MathOperation` | +| [`NBTCompoundArgument`](../types/nbt-arguments) | `de.tr7zw.nbtapi.NBTContainer` | +| [`ObjectiveArgument`](../types/scoreboard/objective-arguments#objective-argument) | **`org.bukkit.scoreboard.Objective`** | +| [`ParticleArgument`](../types/misc/particle-arguments) | `org.bukkit.Particle` | +| [`PlayerProfileArgument`](../types/entities-arguments#playerprofile-argument) | **`com.destroystokyo.paper.profile.PlayerProfile`** | +| [`PotionEffectArgument`](../types/misc/potion-arguments) | `org.bukkit.potion.PotionEffectType` | +| [`RecipeArgument`](../types/misc/recipe-arguments) | `org.bukkit.inventory.Recipe` | +| [`RotationArgument`](../types/position/rotation-arguments) | `dev.jorel.commandapi.wrappers.Rotation` | +| [`ScoreboardSlotArgument`](../types/scoreboard/scoreboard-arguments#scoreboard-slot-argument) | `dev.jorel.commandapi.wrappers.ScoreboardSlot` | +| [`SoundArgument`](../types/misc/sound-arguments) | `org.bukkit.Sound` | +| [`TeamArgument`](../types/scoreboard/team-arguments) | **`org.bukkit.scoreboard.Team`** | +| [`TimeArgument`](../types/misc/time-arguments) | **`dev.jorel.commandapi.wrappers.Time`** | +| [`WorldArgument`](../types/misc/world-arguments) | `org.bukkit.World` | + +
+
+ | Argument | Class (T) | |----------------------------------------------------------------------------------------------:|:-----------------------------------------------| | [`AdvancementArgument`](../types/misc/advancement-arguments) | `org.bukkit.advancement.Advancement` | @@ -50,14 +91,14 @@ The list of supported arguments are displayed in the following table. The parame | [`BooleanArgument`](../types/primitive-arguments) | **`Boolean`** | | [`ChatColorArgument`](../types/chat/spigot-chat-arguments#chat-color-argument) | `org.bukkit.ChatColor` | | [`DoubleArgument`](../types/primitive-arguments#numerical-arguments) | **`Double`** | +| [`DoubleRangeArgument`](../types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.DoubleRange` | | [`EnchantmentArgument`](../types/misc/enchantment-arguments) | `org.bukkit.enchantments.Enchantment` | | [`EntityTypeArgument`](../types/entities-arguments#entity-type-argument) | `org.bukkit.entity.EntityType` | | [`FloatArgument`](../types/primitive-arguments#numerical-arguments) | **`Float`** | -| [`FloatRangeArgument`](../types/ranged-arguments#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.FloatRange` | | [`FunctionArgument`](../../functions-and-tags/function-arguments) | **`org.bukkit.NamespacedKey`** | | [`GreedyStringArgument`](../types/string-arguments#greedy-string-argument) | `String` | | [`IntegerArgument`](../types/primitive-arguments#numerical-arguments) | **`Integer`** | -| [`IntegerRangeArgument`](../types/ranged-arguments#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | +| [`IntegerRangeArgument`](../types/ranged-arguments#the-integer-range-and-double-range-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | | [`ItemStackArgument`](../types/misc/itemstack-arguments) | `org.bukkit.inventory.ItemStack` | | [`Location2DArgument`](../types/position/location-arguments#2d-location) | `dev.jorel.commandapi.wrappers.Location2D` | | [`LocationArgument`](../types/position/location-arguments#3d-location) | `org.bukkit.Location` | @@ -66,9 +107,8 @@ The list of supported arguments are displayed in the following table. The parame | [`MathOperationArgument`](../types/misc/mathoperation-arguments) | `dev.jorel.commandapi.wrappers.MathOperation` | | [`NBTCompoundArgument`](../types/nbt-arguments) | `de.tr7zw.nbtapi.NBTContainer` | | [`ObjectiveArgument`](../types/scoreboard/objective-arguments#objective-argument) | **`org.bukkit.scoreboard.Objective`** | -| [`OfflinePlayerArgument`](../types/entities-arguments#player-argument) | `org.bukkit.OfflinePlayer` | | [`ParticleArgument`](../types/misc/particle-arguments) | `org.bukkit.Particle` | -| [`PlayerArgument`](../types/entities-arguments#player-argument) | `org.bukkit.entity.Player` | +| [`PlayerProfileArgument`](../types/entities-arguments#playerprofile-argument) | **`org.bukkit.profile.PlayerProfile`** | | [`PotionEffectArgument`](../types/misc/potion-arguments) | `org.bukkit.potion.PotionEffectType` | | [`RecipeArgument`](../types/misc/recipe-arguments) | `org.bukkit.inventory.Recipe` | | [`RotationArgument`](../types/position/rotation-arguments) | `dev.jorel.commandapi.wrappers.Rotation` | @@ -78,6 +118,8 @@ The list of supported arguments are displayed in the following table. The parame | [`TimeArgument`](../types/misc/time-arguments) | **`dev.jorel.commandapi.wrappers.Time`** | | [`WorldArgument`](../types/misc/world-arguments) | `org.bukkit.World` | +
+ ## Safe time arguments While most of the arguments are fairly straight forward, I'd like to bring your attention to the `TimeArgument`'s safe suggestions function. This uses `dev.jorel.commandapi.wrappers.Time` as the class for `T` to ensure type-safety. The `Time` class has three static methods: @@ -121,18 +163,18 @@ To do this, we first register our custom items: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerCustomItem +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerCustomItem ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerCustomItem +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerCustomItem ::: Once we've done that, we can now include them in our command registration. To do this, we use `replaceSafeSuggestions(recipes)` and then register our command as normal: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerCommandWithSafeSuggestions +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerCommandWithSafeSuggestions ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerCommandWithSafeSuggestions +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerCommandWithSafeSuggestions ::: :::: @@ -149,27 +191,27 @@ Now say that we don't want non-op players to spawn bosses. To do this, we'll cre :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createForbiddenMobsList +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createForbiddenMobsList ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createForbiddenMobsList +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createForbiddenMobsList ::: We then use our safe arguments to return an `EntityType[]` as the list of values that are suggested to the player. In this example, we use the `sender()` method to determine if the sender has permissions to view the suggestions: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createSafeArguments +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createSafeArguments ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createSafeArguments +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createSafeArguments ::: Now we register our command as normal: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerSpawnMobCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerSpawnMobCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerSpawnMobCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerSpawnMobCommand ::: :::: @@ -186,18 +228,18 @@ Now, we don't want to remove a potion effect that doesn't exist on a player, so :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createSafePotionEffectArguments +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createSafePotionEffectArguments ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createSafePotionEffectArguments +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createSafePotionEffectArguments ::: And then we can register our command as normal: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerRemoveEffectCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerRemoveEffectCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerRemoveEffectCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerRemoveEffectCommand ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/suggestions/string-suggestions.md b/docs/en/create-commands/arguments/suggestions/string-suggestions.md index bf76c0259..7d7743504 100644 --- a/docs/en/create-commands/arguments/suggestions/string-suggestions.md +++ b/docs/en/create-commands/arguments/suggestions/string-suggestions.md @@ -24,9 +24,9 @@ We then implement our warp teleporting command using `replaceSuggestions()` on t :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createWarpCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createWarpCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createWarpCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createWarpCommand ::: :::: @@ -39,7 +39,7 @@ The `strings(Function suggestions)` method in `Argumen ::::tip Example - Friend list by replacing suggestions -Say you have a plugin which has a "friend list" for players. If you want to teleport to a friend in that list, you could use a `PlayerArgument`, which has the list of suggestions replaced with the list of friends that that player has. Since the list of friends _depends on the sender_, we can use the function to determine what our suggestions should be. Let's use the following command to teleport to a friend from our friend list: +Say you have a plugin which has a "friend list" for players. If you want to teleport to a friend in that list, you could use a `EntitySelectorArgument.OnePlayer`, which has the list of suggestions replaced with the list of friends that that player has. Since the list of friends _depends on the sender_, we can use the function to determine what our suggestions should be. Let's use the following command to teleport to a friend from our friend list: ```mccmd /friendtp @@ -49,18 +49,18 @@ Let's say we have a simple class to get the friends of a command sender: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createFriendsClass +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createFriendsClass ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createFriendsClass +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createFriendsClass ::: We can then use this to generate our suggested list of friends: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createFriendCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createFriendCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createFriendCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createFriendCommand ::: :::: @@ -105,9 +105,9 @@ When run, this command will send a message to a target player within the provide :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createLocalMessageCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createLocalMessageCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createLocalMessageCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createLocalMessageCommand ::: As shown in this code, we use the `previousArgs()` method access the previously declared arguments. In this example, `info.previousArgs()` will be `{ int }`, where this `int` refers to the radius. Note how this object array only has the previously declared arguments (and not for example `{ int, Player, String }`). diff --git a/docs/en/create-commands/arguments/suggestions/tooltips.md b/docs/en/create-commands/arguments/suggestions/tooltips.md index 0d4d94afc..132a7987b 100644 --- a/docs/en/create-commands/arguments/suggestions/tooltips.md +++ b/docs/en/create-commands/arguments/suggestions/tooltips.md @@ -51,18 +51,18 @@ First, we'll declare our arguments. Here, we'll use the `stringsWithTooltips` me :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createArgumentsWithTooltips +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createArgumentsWithTooltips ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createArgumentsWithTooltips +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createArgumentsWithTooltips ::: Finally, we declare our command as normal: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerEmoteCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerEmoteCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerEmoteCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerEmoteCommand ::: :::: @@ -90,9 +90,9 @@ Let's say we've created a simple plugin which has custom items. For a custom ite :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createCustomItemClass +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createCustomItemClass ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createCustomItemClass +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createCustomItemClass ::: We make use of the `Tooltip.messageFromString()` method to generate a Brigadier `Message` object from our string tooltip. @@ -101,9 +101,9 @@ Let's also say that our plugin has registered lots of `CustomItem`s and has this :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerCustomItemCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerCustomItemCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerCustomItemCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerCustomItemCommand ::: :::: @@ -147,18 +147,18 @@ First, we'll declare our arguments. Here, we use a `LocationArgument` and use th :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createArgumentsWithTooltipsAndSafeSuggestions +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createArgumentsWithTooltipsAndSafeSuggestions ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createArgumentsWithTooltipsAndSafeSuggestions +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createArgumentsWithTooltipsAndSafeSuggestions ::: In the arguments declaration, we've casted the command sender to a player. To ensure that the command sender is definitely a player, we'll use the `executesPlayer` command execution method in our command declaration: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerWarpCommand +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerWarpCommand ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerWarpCommand +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerWarpCommand ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/chat/adventure-chat-arguments.md b/docs/en/create-commands/arguments/types/chat/adventure-chat-arguments.md index 6b38e1977..e5b7391c8 100644 --- a/docs/en/create-commands/arguments/types/chat/adventure-chat-arguments.md +++ b/docs/en/create-commands/arguments/types/chat/adventure-chat-arguments.md @@ -8,21 +8,23 @@ authors: # Adventure chat arguments -:::info +From Paper 1.16.5 build #473 onwards, Paper now includes [Kyori's Adventure API](https://github.com/KyoriPowered/adventure-platform). This library is a replacement of the BungeeCord chat API and has all the same functionality as the BungeeCord chat API (and more!). The documentation for this API can be found [here](https://docs.adventure.kyori.net/index.html). -The two following classes, `AdventureChatComponentArgument` and `AdventureChatArgument` depend on a Paper-based server which has the Adventure library. If you use this class on a server without the Adventure library, it will throw a `PaperAdventureNotFoundException` +Since this functions very similar to the Spigot chat arguments, this page won't reiterate everything about how it works, we'll just outline some examples of how to use these arguments instead. +Additionally, the names used here may be confusing as they are the same names as on the [Spigot chat arguments](spigot-chat-arguments.md) page but have different return types. This is because the classes on this page are only accessible using `commandapi-paper-core` or `commandapi-paper-shade` +while the arguments on the Spigot chat arguments page are only available when using `commandapi-spigot-core` or `commandapi-spigot-shade`. -::: +:::info -From Paper 1.16.5 build #473 onwards, Paper now includes [Kyori's Adventure API](https://github.com/KyoriPowered/adventure-platform). This library is a replacement of the BungeeCord chat API and has all the same functionality as the BungeeCord chat API (and more!). The documentation for this API can be found [here](https://docs.adventure.kyori.net/index.html). +The three following classes, `ChatColorArgument`, `ChatComponentArgument` and `ChatArgument` depend on a Paper based server which has the Adventure library. If you use any of these classes on a server without the Adventure library, they will throw a `PaperAdventureNotFoundException`. -Since this functions very similar to the Spigot chat arguments, this page won't reiterate everything about how it works, we'll just outline some examples of how to use these arguments instead. +::: ## Adventure chat color argument ![Chatcolor argument in-game, displaying a list of Minecraft chat colors](/images/arguments/chatcolor.png) -The `AdventureChatColorArgument` class is used to represent a given chat color (e.g., red or green). This argument returns the `NamedTextColor` object. If `reset` is passed to this argument, this will return `NamedTextColor.WHITE`. +The `ChatColorArgument` class is used to represent a given chat color (e.g., red or green). This argument returns the `NamedTextColor` object. If `reset` is passed to this argument, this will return `NamedTextColor.WHITE`. ::::tip Example – Username color changing plugin @@ -36,18 +38,18 @@ We then use the `ChatColorArgument` to change the player's name color: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java#namedTextColorExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java#namedTextColorExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#namedTextColorExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#namedTextColorExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#namedTextColorExampleDSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#namedTextColorExampleDSL ::: :::: ## Adventure chat component argument -The `AdventureChatComponentArgument` class accepts raw chat-based JSON as valid input, as declared [here](https://minecraft.wiki/w/Raw_JSON_text_format). This is converted into Adventure's `Component` class. +The `ChatComponentArgument` class accepts raw chat-based JSON as valid input, as declared [here](https://minecraft.wiki/w/Raw_JSON_text_format). This is converted into Adventure's `Component` class. ::::tip Example – Opening a book with raw JSON content @@ -61,36 +63,36 @@ We can construct a book using the Adventure API's `Book.book(Component, Componen :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java#componentExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java#componentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#componentExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#componentExample ===KotlinDSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#componentExampleDSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#componentExampleDSL ::: :::: ## Adventure chat argument -The `AdventureChatArgument` class is the equivalent Adventure API class for the `ChatArgument` - it represents infinitely long strings similar to the `GreedyStringArgument` and allows entity selectors such as `@e`, `@p` and so on. The `AdventureChatArgument` returns a `Component`, similar to the `AdventureChatComponentArgument`. +The `ChatArgument` represents infinitely long strings similar to the `GreedyStringArgument` and allows entity selectors such as `@e`, `@p` and so on. The `ChatArgument` returns a `SignedMessage`. ::::tip Example – Sending personalized messages to players -We'll take the same example from the `ChatArgument` class, but using the `AdventureChatArgument` instead - We want to create a personalized message broadcasted to all users using a chat component that allows entity selectors. For this command, we want the following syntax: +We want to create a personalized message broadcasted to all users using a chat component that allows entity selectors. For this command, we want the following syntax: ```mccmd /pbroadcast ``` -To broadcast an Adventure `Component` to all players on the server, we have to use Paper's `broadcast(Component, String)` method. This method requires a permission node which all players must have to receive the broadcasted message. By default, Bukkit-based servers (Spigot and Paper) use the `bukkit.broadcast.user` permission, which is described [here](https://bukkit.fandom.com/wiki/CraftBukkit_Commands#Additional_Permissions): +To broadcast an Adventure `Component` to all players on the server, we have to use Paper's `sendMessage(SignedMessage, Bound)` method. :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java#chatArgumentExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java#chatArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#chatArgumentExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#chatArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#chatArgumentExampleDSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt#chatArgumentExampleDSL ::: diff --git a/docs/en/create-commands/arguments/types/chat/chat-arguments.md b/docs/en/create-commands/arguments/types/chat/chat-arguments.md index 99ddc0cba..e724b7035 100644 --- a/docs/en/create-commands/arguments/types/chat/chat-arguments.md +++ b/docs/en/create-commands/arguments/types/chat/chat-arguments.md @@ -14,6 +14,4 @@ The CommandAPI provides a number of ways to interact with chat formatting in Min - **Chat**: Text which is said in chat. This also includes entity selectors such as `@a` and `@r` - **ChatComponent**: Minecraft's [Raw JSON text format](https://minecraft.wiki/w/Raw_JSON_text_format) -The CommandAPI implements **ChatColor**, **Chat** and **ChatComponent** in two separate ways: [Spigot-compatible](./spigot-chat-arguments) and [Adventure-compatible](./adventure-chat-arguments). The differences between these and how to use them are described in their own relevant pages. - -The CommandAPI also supports Minecraft 1.19's chat preview feature. To use Minecraft 1.19's chat preview feature, information on that can be found in [Chat preview](./chat-preview). \ No newline at end of file +The CommandAPI implements **ChatColor**, **Chat** and **ChatComponent** in two separate ways: [Spigot-compatible](./spigot-chat-arguments) and [Adventure-compatible](./adventure-chat-arguments). The differences between these and how to use them are described in their own relevant pages. \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/chat/chat-preview.md b/docs/en/create-commands/arguments/types/chat/chat-preview.md deleted file mode 100644 index 177356a72..000000000 --- a/docs/en/create-commands/arguments/types/chat/chat-preview.md +++ /dev/null @@ -1,156 +0,0 @@ ---- -order: 4 -authors: - - DerEchtePilz - - willkroboth - - JorelAli ---- - -# Chat preview - -![Chat preview](/images/chatpreview.gif) - -Chat preview is a feature introduced in Minecraft 1.19 that allows the server to display a preview of a chat message to the client before the client sends their message to the server. This chat preview feature is also compatible with `/say` and `/msg`, as well as the `ChatArgument` and `AdventureChatArgument` classes. - -:::danger Minecraft version support - -The chat preview feature is only present in Minecraft versions 1.19, 1.19.1 and 1.19.2. [Chat preview was removed in 1.19.3](https://minecraft.wiki/w/Java_Edition_1.19.3#General_2), so this feature is unfortunately no longer usable in Minecraft 1.19.3 and beyond. - -::: - -## Enabling chat preview - -To use chat preview, your server must have `previews-chat` set to `true` in the `server.properties` file: - -```properties -... -previews-chat=true // [!code focus] -... -``` - -For players that want to use chat preview, they must have `Chat Preview` enabled in `Options > Chat Settings...` - -## Specifying a chat preview function - -The `ChatArgument` and `AdventureChatArgument` classes include a method, `withPreview`: - -```java -public T withPreview(PreviewableFunction preview); -``` - -The method `withPreview(PreviewableFunction preview)` lets you generate a preview to send to the client. This method takes in the `PreviewableFunction` functional interface, which is a function that takes in a `PreviewInfo` and returns either a `BaseComponent[]` (for `ChatArgument`) or a `Component` (for `AdventureChatArgument`): - -```java -public T generatePreview(PreviewInfo info) throws WrapperCommandSyntaxException; -``` - -The `PreviewInfo` class is a record containing the following: - -```java -public record PreviewInfo { - Player player(); - String input(); - String fullInput(); - T parsedInput(); -} -``` - -The following methods are as follows: - -```java -Player player(); -``` - -`player()` is the player currently typing a chat preview. - -```java -String input(); -``` - -`input()` is the current input for the current `ChatArgument` or `AdventureChatArgument`. If a user is typing `/mycommand hellowor¦` and the command syntax is `/mycommand `, the result of `input()` would be `"hellowor"`. - -```java -String fullInput(); -``` - -`fullInput()` is the full input that the player has typed, including the leading `/` symbol which is required to start a command. If a user is typing `/mycommand hellowor¦`, the result of `fullInput()` would be `"/mycommand hellowor"`. - -```java -T parsedInput(); -``` - -`parsedInput()` is similar to `input()`, except it has been parsed by the CommandAPI's argument parser. This is a representation of what the argument in the executor would look like. For a `ChatArgument` the return type is `BaseComponent[]`, and for `AdventureChatArgument` the return type is `Component`. - -## Using the chat preview function as the argument's value - -The `ChatArgument` and `AdventureChatArgument` classes also include a method, `usePreview`: - -```java -public T usePreview(boolean usePreview); -``` - -The `usePreview(boolean usePreview)` method lets you specify whether you would like the previewing function to be used as the argument's value during execution. If set to `true`, when the command's `.executes()` method is called, the argument value (e.g. `arg[0]`) will be the same as the content generated by the function provided to `withPreview()`. - -## Chat preview examples - -::::tip Example – Using chat preview - -Say we wanted to make our own `/broadcast` command that allowed the user to use `&` chat colors. We can use chat preview to show users what the result of their `/broadcast` command would look like before running the command. We'll use the following command syntax: - -```mccmd -/broadcast -``` - -Because the `ChatArgument` and `AdventureChatArgument` can support entity selectors (such as `@p`), it's best to use the `info.parsedInput()` method to handle parsed entity selectors. In our code, we use the `.withPreview()` method and take the parsed input and convert it to plain text. We then convert the plain text with `&` characters into component text to be displayed to the user. - -For execution, we do the same procedure, because the text that the user enters still has `&` characters that need to be converted into a component. - -#### Use Adventure Chat API - -:::tabs -===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java#chatPreviewAdventureExample -===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt#chatPreviewAdventureExample -::: - -#### Use Legacy Chat API - -:::tabs -===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java#chatPreviewLegacyExample -===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt#chatPreviewLegacyExample -::: - -:::: - -::::tip Example – Using chat preview with `usePreview()` - -Extending on the example above where we created a `/broadcast` command with chat preview support, we can simplify the code by using `.usePreview(true)` to use the preview function as the value of our argument in our executor function. We'll use the same command syntax as the previous example: - -```mccmd -/broadcast -``` - -By using `.usePreview(true)`, we don't have to re-translate `&` formatting codes into their corresponding components because that has already been done by the preview function specified in `.withPreview()` method. - -**Using Adventure Chat API** - -:::tabs -===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java#usePreviewAdventureExample -===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt#usePreviewAdventureExample -::: - -**Using Legacy Chat API** - -:::tabs -===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java#usePreviewLegacyExample -===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt#usePreviewLegacyExample -::: - -:::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/chat/spigot-chat-arguments.md b/docs/en/create-commands/arguments/types/chat/spigot-chat-arguments.md index 94b9677cd..3f69033a0 100644 --- a/docs/en/create-commands/arguments/types/chat/spigot-chat-arguments.md +++ b/docs/en/create-commands/arguments/types/chat/spigot-chat-arguments.md @@ -26,11 +26,11 @@ We then use the `ChatColorArgument` to change the player's name color: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java#chatColorArgumentExample +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java#chatColorArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatColorArgumentExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatColorArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatColorArgumentExampleDSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatColorArgumentExampleDSL ::: :::: @@ -116,11 +116,11 @@ Now we can create our book command. We use the player as the main target by usin :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java#setPagesExample +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java#setPagesExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#setPagesExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#setPagesExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#setPagesExampleDSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#setPagesExampleDSL ::: :::: @@ -153,11 +153,11 @@ _Bob_ would receive the message "Hello Bob", whereas _Michael_ would receive the :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java#chatArgumentExample +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java#chatArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatArgumentExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatArgumentExampleDSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt#chatArgumentExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/command-arguments.md b/docs/en/create-commands/arguments/types/command-arguments.md index 282acf3f8..b61ab9304 100644 --- a/docs/en/create-commands/arguments/types/command-arguments.md +++ b/docs/en/create-commands/arguments/types/command-arguments.md @@ -78,11 +78,11 @@ In this example, we want to be able to run any arbitrary command, so we will sim :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java#sudoCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java#sudoCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#sudoCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#sudoCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#sudoCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#sudoCommandExampleDSL ::: :::: @@ -122,27 +122,27 @@ We can implement our `/tp` branch using the `SuggestionsBranch.suggest()` method :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java#suggestionBranchesStep1 +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java#suggestionBranchesStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#suggestionBranchesStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#suggestionBranchesStep1 ::: For the `/give` branch, we can use a similar thing, but we need to tell the CommandArgument that the `/give` command branches into "diamond" and "dirt" suggestions. We can do this by using the `.branch()` method to add a new nested list of suggestions: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java#suggestionBranchesStep2 +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java#suggestionBranchesStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#suggestionBranchesStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#suggestionBranchesStep2 ::: Adding everything together, we get this fully completed CommandArgument: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java#suggestionBranchesStep3 +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java#suggestionBranchesStep3 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#suggestionBranchesStep3 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt#suggestionBranchesStep3 ::: :::: diff --git a/docs/en/create-commands/arguments/types/custom-arguments.md b/docs/en/create-commands/arguments/types/custom-arguments.md index 20fe8474f..26f9b68a9 100644 --- a/docs/en/create-commands/arguments/types/custom-arguments.md +++ b/docs/en/create-commands/arguments/types/custom-arguments.md @@ -1,5 +1,6 @@ --- order: 16 +preferences: ["paper-spigot"] authors: - DerEchtePilz - JorelAli @@ -84,22 +85,48 @@ These fields are as follows: Say we want to create an argument to represent the list of available worlds on the server. We want to have an argument which always returns a Bukkit `World` object as the result. Here, we create a method `worldArgument()` that returns our custom argument that returns a `World`. First, we retrieve our `String[]` of world names to be used for our suggestions. We then write our custom argument that creates a `World` object from the input (in this case, we simply convert the input to a `World` using `Bukkit.getWorld(String)`). We perform error handling before returning our result: +
+ +:::tabs +===Java +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/CustomArguments.java#declareCustomArgumentsExample +===Kotlin +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#declareCustomArgumentsExample +::: + +
+
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/CustomArguments.java#declareCustomArgumentsExample +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/CustomArguments.java#declareCustomArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#declareCustomArgumentsExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#declareCustomArgumentsExample ::: +
+ In our error handling step, we check if the world is equal to null (since the `Bukkit.getWorld(String)` is `@Nullable`). To handle this case, we throw a `CustomArgumentException` with an error from a `MessageBuilder`. The `CustomArgumentException` has various static factory methods tailored to your desired printing method, so a message builder isn't required each time: +
+ ```java -CustomArgumentException fromBaseComponents(BaseComponent[] errorMessage); CustomArgumentException fromString(String errorMessage); -CustomArgumentException fromAdventureComponent(Component errorMessage); +CustomArgumentException fromAdventureComponent(ComponentLike errorMessage); CustomArgumentException fromMessageBuilder(MessageBuilder errorMessage); ``` +
+
+ +```java +CustomArgumentException fromString(String errorMessage); +CustomArgumentException fromBaseComponents(BaseComponent[] errorMessage); +CustomArgumentException fromMessageBuilder(MessageBuilder errorMessage); +``` + +
+ We can use our custom argument like any other argument. Say we wanted to write a command to teleport to a specific world. We will create a command of the following syntax: ```mccmd @@ -108,15 +135,31 @@ We can use our custom argument like any other argument. Say we wanted to write a Since we have defined the method `worldArgument()` which automatically generates our argument, we can use it as follows: +
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/CustomArguments.java#useCustomArgumentsExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/CustomArguments.java#useCustomArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#useCustomArgumentsExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#useCustomArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#useCustomArgumentsExampleDSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#useCustomArgumentsExampleDSL ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/CustomArguments.java#useCustomArgumentsExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#useCustomArgumentsExample +===Kotlin DSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt#useCustomArgumentsExampleDSL +::: + +
+ By using a `CustomArgument` (as opposed to a simple `StringArgument` and replacing its suggestions), we are able to provide a much more powerful form of error handling (automatically handled inside the argument), and we can reuse this argument for other commands. :::: diff --git a/docs/en/create-commands/arguments/types/entities-arguments.md b/docs/en/create-commands/arguments/types/entities-arguments.md index cfb1d8438..a31d708a5 100644 --- a/docs/en/create-commands/arguments/types/entities-arguments.md +++ b/docs/en/create-commands/arguments/types/entities-arguments.md @@ -1,5 +1,6 @@ --- order: 7 +preferences: ["paper-spigot"] authors: - JorelAli - DerEchtePilz @@ -37,15 +38,31 @@ Say we want a command to remove certain types of entities. Typically, this would Instead, we can combine all of these into one by using the `EntitySelectorArgument`. We want to be able to target multiple entities at a time, so we want to use the `EntitySelectorArgument.ManyEntities` constructor. We can simply retrieve the `Collection` from this argument and iteratively remove each entity: +
+ +:::tabs +===Java +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java#entitySelectorArgumentExample +===Kotlin +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entitySelectorArgumentExample +===Kotlin DSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entitySelectorArgumentExampleDSL +::: + +
+
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java#entitySelectorArgumentExample +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java#entitySelectorArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entitySelectorArgumentExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entitySelectorArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entitySelectorArgumentExampleDSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entitySelectorArgumentExampleDSL ::: +
+ We could then use this to target specific entities, for example: - To remove all cows: @@ -62,78 +79,136 @@ We could then use this to target specific entities, for example: :::: -## Player argument +## PlayerProfile argument -The `PlayerArgument` class is very similar _(almost identical)_ to `EntitySelectorArgument.OnePlayer`. It returns a `Player` object and requires the player to be online. +The `PlayerProfileArgument` can serve a similar purpose as the `EntitySelectorArgument.OnePlayer` or `EntitySelectorArgument.ManyPlayers` if you only reference online players, but it can also be used to reference players that are offline or have never logged into your server. -:::info -The `PlayerArgument` internally uses the `GameProfile` class from Mojang's authlib, which means that this argument has a slight performance overhead compared to using `EntitySelectorArgument.OnePlayer` -::: +Because of this, it has a performance overhead even when the input is an online player or an entity selector. + +
+ +The `PlayerProfileArgument` returns a `List`. + +
+
-::::tip Example – PlayerArgument without entity selectors +The `PlayerProfileArgument` returns a `List`. -When registering a `PlayerArgument` you might notice that it includes `Entity Selectors` (`@a`, `@e`, `@r`, etc.). If you want to avoid those, you can use argument suggestions to only suggest the player names. For this example, let us create a /warp command: +
+ +::::tip Example – PlayerProfileArgument without entity selectors + +When registering a `PlayerProfileArgument` you might notice that it includes `Entity Selectors` (`@a`, `@e`, `@r`, etc.). If you want to avoid those, you can use argument suggestions to only suggest the player names. For this example, let us create a /warp command: ```mccmd /warp ``` -To get a `PlayerArgument` which only suggests the actual names, we can define it like this: +To get a `PlayerProfileArgument` which only suggests the actual names, we can define it like this: + +
:::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java#buildNoSelectorSuggestions +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java#buildNoSelectorSuggestions ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#buildNoSelectorSuggestions +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#buildNoSelectorSuggestions ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java#buildNoSelectorSuggestions +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#buildNoSelectorSuggestions +::: + +
+ Now we can define the rest of the command and include our suggestion inside it like this: +
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java#noSelectorSuggestionsExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java#noSelectorSuggestionsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#noSelectorSuggestionsExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#noSelectorSuggestionsExample ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java#noSelectorSuggestionsExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#noSelectorSuggestionsExample +::: + +
+ And there we have it! One thing to note is that entity selectors are still a valid input; they’re just not included in the suggestions. ![WarpCommand](/images/entityselectorplayerexample.gif) :::: -## OfflinePlayer argument +## AsyncPlayerProfile argument -The `OfflinePlayerArgument` class is identical to the `PlayerArgument` class, but instead of returning a `Player` object, it returns an `OfflinePlayer` object. Internally, this argument makes calls to Mojang servers (via Mojang's authlib), meaning it can be slightly slower than alternative methods such as using a `AsyncOfflinePlayerArgument`, which runs the API call asynchronously, or using a `StringArgument` and suggesting a list of existing offline players. +The `AsyncPlayerProfileArgument` class is identical to the `PlayerProfileArgument` class, but instead of making the API call synchronously, it makes the API call asynchronously. This means that the command will not block the main thread while waiting for the API call to complete. -The `OfflinePlayerArgument` _should_ be able to retrieve players that have never joined the server before. +
-## AsyncOfflinePlayer argument +:::info +The `AsyncPlayerProfileArgument` returns a `CompletableFuture>` object, which can be used to retrieve the `List` object when the API call is complete. +::: -The `AsyncOfflinePlayerArgument` class is identical to the `OfflinePlayerArgument` class, but instead of making the API call synchronously, it makes the API call asynchronously. This means that the command will not block the main thread while waiting for the API call to complete. +
+
:::info -The `AsyncOfflinePlayerArgument` returns a `CompletableFuture` object, which can be used to retrieve the `OfflinePlayer` object when the API call is complete. +The `AsyncPlayerProfileArgument` returns a `CompletableFuture>` object, which can be used to retrieve the `List` object when the API call is complete. ::: +
+ ::::tip Example - Checking if a player has joined before -Say we want to create a command that tells us if a player has joined the server before. We can use the `AsyncOfflinePlayerArgument` to fetch the `OfflinePlayer` object asynchronously. That way we simply wait for the request to complete, and once it does, we can check if the player has joined the server before. We want to create a command of the following form: +Say we want to create a command that tells us if a player has joined the server before. We can use the `AsyncPlayerProfileArgument` to fetch the `List` object asynchronously. That way we simply wait for the request to complete, and once it does, we can check if the player has joined the server before. We want to create a command of the following form: ```mccmd /playedbefore ``` -We now want to get the `CompletableFuture` object from the `AsyncOfflinePlayerArgument` and then use it to get the `OfflinePlayer` object. We can define it like this: +We now want to get the `CompletableFuture>` object from the `AsyncPlayerProfileArgument` and then use it to get the `List` object. We can define it like this: + +
+ +:::tabs +===Java +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java#playedBeforeArgumentExample +===Kotlin +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#playedBeforeArgumentExample +===Kotlin DSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#playedBeforeArgumentExampleDSL +::: + +
+
:::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java#playedBeforeArgumentExample +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java#playedBeforeArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#playedBeforeArgumentExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#playedBeforeArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#playedBeforeArgumentExampleDSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#playedBeforeArgumentExampleDSL ::: +
+ We now successfully ran a command that asynchronously checks if a player has joined the server before without blocking the main thread despite making an API call. :::: @@ -154,15 +229,31 @@ Say we want a command to spawn a specific type of entity, similar to the `/summo Since we're trying to specify an entity type, we will use the `EntityTypeArgument` as our argument type for ``. We combine this with the `IntegerArgument` class with a specified range of $1 \le \textit{amount} \le 100$: +
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java#entityTypeArgumentExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java#entityTypeArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entityTypeArgumentExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entityTypeArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entityTypeArgumentExampleDSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entityTypeArgumentExampleDSL ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java#entityTypeArgumentExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entityTypeArgumentExample +===Kotlin DSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt#entityTypeArgumentExampleDSL +::: + +
+ Note how in this example above, we have to explicitly state `Player player, CommandArguments args`. This is due to a limitation of Java's type inference system which is discussed [here](../../registration#setting-the-commands-executor). :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/list-arguments.md b/docs/en/create-commands/arguments/types/list-arguments.md index 49c36399b..04b53ccfe 100644 --- a/docs/en/create-commands/arguments/types/list-arguments.md +++ b/docs/en/create-commands/arguments/types/list-arguments.md @@ -137,11 +137,11 @@ To do this, we create a command with an `IntegerArgument` to specify the amount :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/ListArguments.java#listArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/ListArguments.java#listArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/ListArguments.kt#listArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/ListArguments.kt#listArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/ListArguments.kt#listArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/ListArguments.kt#listArgumentsExampleDSL ::: ![A /multigive argument gif where a user types "/multigive 64 stone dirt cobblestone grass_block" and suggestions appear automatically. Running the command gives the player 64 stone, dirt, cobblestone and grass_block items in their hotbar](/images/arguments/listargument_multigive.gif) diff --git a/docs/en/create-commands/arguments/types/literal/literal-arguments.md b/docs/en/create-commands/arguments/types/literal/literal-arguments.md index a93e1a241..aec614236 100644 --- a/docs/en/create-commands/arguments/types/literal/literal-arguments.md +++ b/docs/en/create-commands/arguments/types/literal/literal-arguments.md @@ -48,22 +48,22 @@ As an example, let's declare the literal "hello" as a valid literal for this com :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java#showLiteralArgumentsIsNotListed +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java#showLiteralArgumentsIsNotListed ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#showLiteralArgumentsIsNotListed +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#showLiteralArgumentsIsNotListed ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#showLiteralArgumentsIsNotListedDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#showLiteralArgumentsIsNotListedDSL ::: The `LiteralArgument` class also provides the `LiteralArgument.of()` and `LiteralArgument.literal()` helper methods which can be used as an alternative way to declare literal arguments: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java#helperMethodsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java#helperMethodsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#helperMethodsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#helperMethodsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#helperMethodsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#helperMethodsExampleDSL ::: If I were to run the following command: @@ -82,11 +82,11 @@ This is a demonstration of how you could create a command similar to Minecraft's :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java#literalArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java#literalArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#literalArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#literalArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#literalArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt#literalArgumentsExampleDSL ::: Note how, since we don't have access to the literal from `args`, we must access the provided gamemode from elsewhere. diff --git a/docs/en/create-commands/arguments/types/literal/multiliteral-arguments.md b/docs/en/create-commands/arguments/types/literal/multiliteral-arguments.md index 66f06fd0d..6e25dfba7 100644 --- a/docs/en/create-commands/arguments/types/literal/multiliteral-arguments.md +++ b/docs/en/create-commands/arguments/types/literal/multiliteral-arguments.md @@ -32,11 +32,11 @@ In this example, we'll show how to use multi literals to declare Minecraft's `/g :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/literal/MultiLiteralArguments.java#multiliteralArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/MultiLiteralArguments.java#multiliteralArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt#multiliteralArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt#multiliteralArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt#multiliteralArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt#multiliteralArgumentsExampleDSL ::: An important thing to note is that we don't have to implement a `default` case for the above `switch` statements, because the CommandAPI will only permit valid options of a `MultiLiteralArgument` to reach the executor. If the user enters an invalid option, the command doesn't run. diff --git a/docs/en/create-commands/arguments/types/map-arguments.md b/docs/en/create-commands/arguments/types/map-arguments.md index 6e9f76d90..e63b79036 100644 --- a/docs/en/create-commands/arguments/types/map-arguments.md +++ b/docs/en/create-commands/arguments/types/map-arguments.md @@ -147,11 +147,11 @@ To implement that, we create a command that uses a `MapArgument` and use `Player :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/MapArguments.java#mapArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/MapArguments.java#mapArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/MapArguments.kt#mapArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/MapArguments.kt#mapArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/MapArguments.kt#mapArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/MapArguments.kt#mapArgumentsExampleDSL ::: :::danger Developer's Note: diff --git a/docs/en/create-commands/arguments/types/misc/advancement-arguments.md b/docs/en/create-commands/arguments/types/misc/advancement-arguments.md index bf510c0f5..150206cf7 100644 --- a/docs/en/create-commands/arguments/types/misc/advancement-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/advancement-arguments.md @@ -20,15 +20,15 @@ Say we want to award a player an advancement. First, we need the syntax that our /award ``` -Since we require a player, we will use the `PlayerArgument` for this example. Given a player, we can simply get the `AdvancementProgress` for that player, and then award the criteria required to fully complete the provided advancement. +Since we require a player, we will use the `EntitySelectorArgument.OnePlayer` for this example. Given a player, we can simply get the `AdvancementProgress` for that player, and then award the criteria required to fully complete the provided advancement. :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java#advancementArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java#advancementArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt#advancementArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt#advancementArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt#advancementArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt#advancementArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/biome-arguments.md b/docs/en/create-commands/arguments/types/misc/biome-arguments.md index fa1b05eb5..50a65b50b 100644 --- a/docs/en/create-commands/arguments/types/misc/biome-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/biome-arguments.md @@ -30,11 +30,11 @@ And we can set the biome of the current chunk as expected: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java#biomeArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java#biomeArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt#biomeArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt#biomeArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt#biomeArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt#biomeArgumentsExampleDSL ::: :::: diff --git a/docs/en/create-commands/arguments/types/misc/blockstate-arguments.md b/docs/en/create-commands/arguments/types/misc/blockstate-arguments.md index 83906a55e..a5cbbf379 100644 --- a/docs/en/create-commands/arguments/types/misc/blockstate-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/blockstate-arguments.md @@ -10,13 +10,7 @@ authors: ![A block state argument with suggestions for Minecraft items](/images/arguments/blockstate.png) -The `BlockStateArgument` is used to represent data about blocks in the world. These refer to any blocks that have data or states, such as dispensers, signs, doors and pistons. The `BlockStateArgument` creates a Bukkit `BlockData` object when used. - -:::info - -Make sure to not confuse the cast type with `BlockState`. The naming of this argument refers to the internal Minecraft vanilla argument naming convention - **this argument casts to `BlockData` and NOT `BlockState`**. - -::: +The `BlockStateArgument` is used to represent data about blocks in the world. These refer to any blocks that have data or states, such as dispensers, signs, doors and pistons. The `BlockStateArgument` creates a Bukkit `BlockState` object when used. ::::tip Example – Setting a block @@ -30,11 +24,11 @@ And then we can simply set our block using `setBlockData()`: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java#blockStateArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java#blockStateArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt#blockStateArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt#blockStateArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt#blockStateArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt#blockStateArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/enchantment-arguments.md b/docs/en/create-commands/arguments/types/misc/enchantment-arguments.md index 7905fff1b..c28b9e936 100644 --- a/docs/en/create-commands/arguments/types/misc/enchantment-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/enchantment-arguments.md @@ -24,11 +24,11 @@ Since most enchantment levels range between 1 and 5, we will also make use of th :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java#enchantmentArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java#enchantmentArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt#enchantmentArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt#enchantmentArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt#enchantmentArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt#enchantmentArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/itemstack-arguments.md b/docs/en/create-commands/arguments/types/misc/itemstack-arguments.md index 56c6d5ccb..c26231918 100644 --- a/docs/en/create-commands/arguments/types/misc/itemstack-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/itemstack-arguments.md @@ -24,11 +24,11 @@ With this syntax, we can easily create our command: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java#itemStackArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java#itemStackArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt#itemStackArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt#itemStackArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt#itemStackArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt#itemStackArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/loottable-arguments.md b/docs/en/create-commands/arguments/types/misc/loottable-arguments.md index 2c67dd077..f9037de8f 100644 --- a/docs/en/create-commands/arguments/types/misc/loottable-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/loottable-arguments.md @@ -24,11 +24,11 @@ We ensure that the location provided is a container (such as a chest or shulkerb :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java#lootTableArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java#lootTableArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt#lootTableArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt#lootTableArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt#lootTableArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt#lootTableArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/mathoperation-arguments.md b/docs/en/create-commands/arguments/types/misc/mathoperation-arguments.md index bac443d8f..5015b543c 100644 --- a/docs/en/create-commands/arguments/types/misc/mathoperation-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/mathoperation-arguments.md @@ -64,11 +64,11 @@ As with any command, we declare our arguments, cast them properly, and then we w :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java#mathOperationArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java#mathOperationArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt#mathOperationArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt#mathOperationArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt#mathOperationArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt#mathOperationArgumentsExampleDSL ::: There are various applications for the `changelevel` command based on what the user inputs. For example: diff --git a/docs/en/create-commands/arguments/types/misc/particle-arguments.md b/docs/en/create-commands/arguments/types/misc/particle-arguments.md index 27a833d22..53548c79f 100644 --- a/docs/en/create-commands/arguments/types/misc/particle-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/particle-arguments.md @@ -219,11 +219,11 @@ With this, we can simply spawn the particle using the `World.spawnParticle(Parti :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java#withoutParticleDataExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java#withoutParticleDataExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withoutParticleDataExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withoutParticleDataExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withoutParticleDataExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withoutParticleDataExampleDSL ::: Running this can result in errors due to missing requirements. If you provide a particle that has additional requirements, Bukkit will throw an error and the particle will not be displayed. Instead, the example below should be used. @@ -242,11 +242,11 @@ In this case, we'll use the `World.spawnParticle(Particle particle, Location loc :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java#withParticleDataExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java#withParticleDataExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withParticleDataExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withParticleDataExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withParticleDataExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt#withParticleDataExampleDSL ::: This can be used with commands such as: diff --git a/docs/en/create-commands/arguments/types/misc/potion-arguments.md b/docs/en/create-commands/arguments/types/misc/potion-arguments.md index d655051c4..a39b58528 100644 --- a/docs/en/create-commands/arguments/types/misc/potion-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/potion-arguments.md @@ -20,28 +20,28 @@ Say we wanted to have a command that gives a player a potion effect. For this co /potion ``` -In this example, we utilize some of the other arguments that we've described earlier, such as the `PlayerArgument` and `TimeArgument`. Since duration for the `PotionEffect` constructor is in ticks, this is perfectly fit for the `TimeArgument`, which is represented in ticks. +In this example, we utilize some of the other arguments that we've described earlier, such as the `EntitySelectorArgument.OnePlayer` and `TimeArgument`. Since duration for the `PotionEffect` constructor is in ticks, this is perfectly fit for the `TimeArgument`, which is represented in ticks. #### Use `PotionEffectArgument` :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java#potionEffectArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/PotionArguments.java#potionEffectArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsExampleDSL ::: #### Use `PotionEffectArgument.NamespacedKey` :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java#potionEffectArgumentsNamespacedKeyExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/PotionArguments.java#potionEffectArgumentsNamespacedKeyExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsNamespacedKeyExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsNamespacedKeyExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsNamespacedKeyExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsNamespacedKeyExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/recipe-arguments.md b/docs/en/create-commands/arguments/types/misc/recipe-arguments.md index 384e560df..3f44be56c 100644 --- a/docs/en/create-commands/arguments/types/misc/recipe-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/recipe-arguments.md @@ -24,11 +24,11 @@ As such, we easily implement it by specifying the `RecipeArgument`, casting it a :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java#getResultExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java#getResultExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getResultExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getResultExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getResultExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getResultExampleDSL ::: :::: @@ -45,11 +45,11 @@ This is then implemented trivially as follows: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java#getKeyExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java#getKeyExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getKeyExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getKeyExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getKeyExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getKeyExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/sound-arguments.md b/docs/en/create-commands/arguments/types/misc/sound-arguments.md index c16519f8c..f2b728261 100644 --- a/docs/en/create-commands/arguments/types/misc/sound-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/sound-arguments.md @@ -42,22 +42,22 @@ This command simply plays the provided sound to the current player: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/SoundArguments.java#soundArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/SoundArguments.java#soundArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsExampleDSL ::: #### Use `SoundArgument.NamespacedKey` :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/SoundArguments.java#soundArgumentsNamespacedKeyExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/SoundArguments.java#soundArgumentsNamespacedKeyExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsNamespacedKeyExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsNamespacedKeyExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsNamespacedKeyExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsNamespacedKeyExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/time-arguments.md b/docs/en/create-commands/arguments/types/misc/time-arguments.md index a98c2f601..c4b1164f3 100644 --- a/docs/en/create-commands/arguments/types/misc/time-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/time-arguments.md @@ -30,11 +30,11 @@ Say we have a command `bigmsg` that displays a title message to all players for :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/TimeArguments.java#timeArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/TimeArguments.java#timeArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt#timeArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt#timeArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt#timeArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt#timeArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/misc/world-arguments.md b/docs/en/create-commands/arguments/types/misc/world-arguments.md index f248f96df..d4a86ab49 100644 --- a/docs/en/create-commands/arguments/types/misc/world-arguments.md +++ b/docs/en/create-commands/arguments/types/misc/world-arguments.md @@ -24,11 +24,11 @@ Using the world from the `WorldArgument`, we can then unload the world safely us :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/WorldArguments.java#worldArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/WorldArguments.java#worldArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt#worldArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt#worldArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt#worldArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt#worldArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/nbt-arguments.md b/docs/en/create-commands/arguments/types/nbt-arguments.md index 42276d962..f7e3d52b7 100644 --- a/docs/en/create-commands/arguments/types/nbt-arguments.md +++ b/docs/en/create-commands/arguments/types/nbt-arguments.md @@ -1,5 +1,6 @@ --- order: 11 +preferences: ["paper-spigot"] authors: - JorelAli - willkroboth @@ -36,13 +37,27 @@ Say we want to use the [NBT API](https://www.spigotmc.org/resources/nbt-api.7939 Now, we can configure the CommandAPI using the `CommandAPI.onLoad()` method to use the `NBTContainer` class, and the [`NBTContainer` constructor that takes in an `Object`](https://tr7zw.github.io/Item-NBT-API/v2-api/de/tr7zw/changeme/nbtapi/NBTContainer.html#NBTContainer-java.lang.Object-): +
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExample ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExample +::: + +
+ > _Confused with the `::new` syntax? Read more about method references to a constructor [here](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html)._ We're now able to use the `NBTContainer` as our implemented type for the `NBTCompoundArgument`! @@ -53,19 +68,35 @@ We're now able to use the `NBTContainer` as our implemented type for the `NBTCom Since the underlying implementation of the `NBTCompoundArgument` can change (e.g. `NBTContainer` if you're using the NBT API), the type of your NBT compound implementation has to be declared in angle brackets. +
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExample +<<< @/../reference-code/paper/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleDSL +<<< @/../reference-code/paper/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleDSL ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExample +===Kotlin DSL +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleDSL +::: + +
+ :::: :::info -If you believe you can supply a suitable example for this page, feel free to send an example [on the CommandAPI issues page!](https://github.com/CommandAPI/CommandAPI/issues/new/choose) +If you believe you can supply a suitable example for this page, feel free to send an example [on the CommandAPI issues page!](https://github.com/CommandAPI/docs/issues/new/) ::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/position/location-arguments.md b/docs/en/create-commands/arguments/types/position/location-arguments.md index cb4bf3b55..58de1f747 100644 --- a/docs/en/create-commands/arguments/types/position/location-arguments.md +++ b/docs/en/create-commands/arguments/types/position/location-arguments.md @@ -41,9 +41,9 @@ Say you use the following constructor, which sets `centerPosition` to `true`: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/position/LocationArguments.java#centerPositionExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/position/LocationArguments.java#centerPositionExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#centerPositionExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#centerPositionExample ::: **Integer positions are centered** @@ -80,9 +80,9 @@ Say you use the following constructor, which sets `centerPosition` to `false`: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/position/LocationArguments.java#doNotCenterPositionExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/position/LocationArguments.java#doNotCenterPositionExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#doNotCenterPositionExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#doNotCenterPositionExample ::: **Integer positions are not centered** @@ -113,11 +113,11 @@ Simply put, given the coordinates provided to the command, "break" the block by :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/position/LocationArguments.java#breakCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/position/LocationArguments.java#breakCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#breakCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#breakCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#breakCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt#breakCommandExampleDSL ::: :::: diff --git a/docs/en/create-commands/arguments/types/position/rotation-arguments.md b/docs/en/create-commands/arguments/types/position/rotation-arguments.md index 8f056f38f..1d7c1f149 100644 --- a/docs/en/create-commands/arguments/types/position/rotation-arguments.md +++ b/docs/en/create-commands/arguments/types/position/rotation-arguments.md @@ -32,11 +32,11 @@ To do this, we'll use the rotation from the `RotationArgument` and select an ent :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/position/RotationArguments.java#rotationArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/position/RotationArguments.java#rotationArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt#rotationArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt#rotationArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt#rotationArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt#rotationArgumentsExampleDSL ::: Note how the head pose requires an `EulerAngle` as opposed to a pitch and yaw. To account for this, we convert our rotation (which is in degrees) into an `EulerAngle` in radians. diff --git a/docs/en/create-commands/arguments/types/predicate/block-predicate-arguments.md b/docs/en/create-commands/arguments/types/predicate/block-predicate-arguments.md index c28c96986..0367de7c1 100644 --- a/docs/en/create-commands/arguments/types/predicate/block-predicate-arguments.md +++ b/docs/en/create-commands/arguments/types/predicate/block-predicate-arguments.md @@ -29,9 +29,9 @@ First, we declare our arguments. We want to use the `BlockPredicateArgument` sin :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java#useBlockStateArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java#useBlockStateArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt#useBlockStateArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt#useBlockStateArgumentsExample ::: We then register our `/replace` command. First, we parse the arguments making sure to cast to `Predicate` and `BlockData` (and not `BlockState`). After that, we use a few simple for loops to find the blocks within a radius sphere from the player. @@ -42,11 +42,11 @@ Lastly, we register our command as normal using the `register()` method. :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java#blockPredicateArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java#blockPredicateArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt#blockPredicateArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt#blockPredicateArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt#blockPredicateArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt#blockPredicateArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/predicate/itemstack-predicate-arguments.md b/docs/en/create-commands/arguments/types/predicate/itemstack-predicate-arguments.md index e553e0091..9dd0e005d 100644 --- a/docs/en/create-commands/arguments/types/predicate/itemstack-predicate-arguments.md +++ b/docs/en/create-commands/arguments/types/predicate/itemstack-predicate-arguments.md @@ -23,11 +23,11 @@ We implement this with a simple for loop over the player's inventory and remove :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/predicate/ItemStackPredicateArguments.java#itemStackPredicateArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/ItemStackPredicateArguments.java#itemStackPredicateArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt#itemStackPredicateArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt#itemStackPredicateArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt#itemStackPredicateArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt#itemStackPredicateArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/primitive-arguments.md b/docs/en/create-commands/arguments/types/primitive-arguments.md index 6a0968897..fe6316f82 100644 --- a/docs/en/create-commands/arguments/types/primitive-arguments.md +++ b/docs/en/create-commands/arguments/types/primitive-arguments.md @@ -37,11 +37,11 @@ We first retrieve the keys from the configuration file using the typical Bukkit :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/PrimitiveArguments.java#primitiveArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/PrimitiveArguments.java#primitiveArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt#primitiveArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt#primitiveArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt#primitiveArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt#primitiveArgumentsExampleDSL ::: :::: diff --git a/docs/en/create-commands/arguments/types/ranged-arguments.md b/docs/en/create-commands/arguments/types/ranged-arguments.md index db57dda63..537afbd5a 100644 --- a/docs/en/create-commands/arguments/types/ranged-arguments.md +++ b/docs/en/create-commands/arguments/types/ranged-arguments.md @@ -8,9 +8,9 @@ authors: # Ranged arguments -![A float range argument command with the argument "0.5.3.5" entered](/images/arguments/floatrange.png) +![A float range argument command with the argument "0.5.3.5" entered](/images/arguments/doublerange.png) -Ranged arguments allow players to provide a range between two numbers, all within a single argument. The CommandAPI provides two ranged arguments, `IntegerRangeArgument` for ranges with only integer values, and `FloatRangeArgument` for ranged with potential floating point values. +Ranged arguments allow players to provide a range between two numbers, all within a single argument. The CommandAPI provides two ranged arguments, `IntegerRangeArgument` for ranges with only integer values, and `DoubleRangeArgument` for ranged with potential floating point values. These consist of values such as: @@ -23,9 +23,9 @@ These consist of values such as: This allows you to let users define a range of values, which can be used to limit a value, such as the number of players in a region or for a random number generator. -## The IntegerRange & FloatRange class +## The IntegerRange & DoubleRange class -The CommandAPI returns an `IntegerRange` from the `IntegerRangeArgument`, and a `FloatRange` from the `FloatRangeArgument`, which represents the upper and lower bounds of the numbers provided by the command sender, as well as a method to check if a number is within that range. +The CommandAPI returns an `IntegerRange` from the `IntegerRangeArgument`, and a `DoubleRange` from the `DoubleRangeArgument`, which represents the upper and lower bounds of the numbers provided by the command sender, as well as a method to check if a number is within that range. The `IntegerRange` class has the following methods: @@ -37,13 +37,13 @@ class IntegerRange { } ``` -The `FloatRange` class has the following methods: +The `DoubleRange` class has the following methods: ```java -class FloatRange { - public float getLowerBound(); - public float getUpperBound(); - public boolean isInRange(float); +class DoubleRange { + public double getLowerBound(); + public double getUpperBound(); + public boolean isInRange(double); } ``` @@ -59,11 +59,11 @@ Now, we simply create our arguments using `IntegerRangeArgument` for our range a :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/RangedArguments.java#rangedArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/RangedArguments.java#rangedArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt#rangedArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt#rangedArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt#rangedArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt#rangedArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/scoreboard/objective-arguments.md b/docs/en/create-commands/arguments/types/scoreboard/objective-arguments.md index 8ec1a6c5d..39421bc24 100644 --- a/docs/en/create-commands/arguments/types/scoreboard/objective-arguments.md +++ b/docs/en/create-commands/arguments/types/scoreboard/objective-arguments.md @@ -27,11 +27,11 @@ As an example, let's create a command to move an objective to a player's sidebar :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java#objectiveArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java#objectiveArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveArgumentsExampleDSL ::: :::: @@ -52,11 +52,11 @@ To do this, we're going to take advantage of Bukkit's `Scoreboard.getObjectivesB :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java#objectiveCriteriaArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java#objectiveCriteriaArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveCriteriaArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveCriteriaArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveCriteriaArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt#objectiveCriteriaArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/scoreboard/scoreboard-arguments.md b/docs/en/create-commands/arguments/types/scoreboard/scoreboard-arguments.md index 0704e9896..7be113e4f 100644 --- a/docs/en/create-commands/arguments/types/scoreboard/scoreboard-arguments.md +++ b/docs/en/create-commands/arguments/types/scoreboard/scoreboard-arguments.md @@ -45,11 +45,11 @@ Note how we use `..9` to represent nine or fewer deaths (since ranges are inclus :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java#scoreHolderArgumentExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java#scoreHolderArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreHolderArgumentExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreHolderArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreHolderArgumentExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreHolderArgumentExampleDSL ::: :::: @@ -128,11 +128,11 @@ We implement this simply by using the `ScoreboardSlotArgument` as our argument, :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java#scoreboardSlotArgumentExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java#scoreboardSlotArgumentExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreboardSlotArgumentExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreboardSlotArgumentExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreboardSlotArgumentExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt#scoreboardSlotArgumentExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/scoreboard/team-arguments.md b/docs/en/create-commands/arguments/types/scoreboard/team-arguments.md index 3c62a7f2c..164393a93 100644 --- a/docs/en/create-commands/arguments/types/scoreboard/team-arguments.md +++ b/docs/en/create-commands/arguments/types/scoreboard/team-arguments.md @@ -22,11 +22,11 @@ To do this, given a team we want to use the `setAllowFriendlyFire(boolean)` func :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/scoreboard/TeamArguments.java#teamArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/TeamArguments.java#teamArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt#teamArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt#teamArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt#teamArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt#teamArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/string-arguments.md b/docs/en/create-commands/arguments/types/string-arguments.md index 48bf14674..bab40d46c 100644 --- a/docs/en/create-commands/arguments/types/string-arguments.md +++ b/docs/en/create-commands/arguments/types/string-arguments.md @@ -92,11 +92,11 @@ This would be ideal for a greedy string, since it can consume all text after the :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/StringsArguments.java#greedyStringArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/arguments/types/StringsArguments.java#greedyStringArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt#greedyStringArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt#greedyStringArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt#greedyStringArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt#greedyStringArgumentsExampleDSL ::: Any text entered after the `` argument would be sent to the player. For example, the command could be used as follows: diff --git a/docs/en/create-commands/command-trees.md b/docs/en/create-commands/command-trees.md index 9cc111ad3..5cdf5af7a 100644 --- a/docs/en/create-commands/command-trees.md +++ b/docs/en/create-commands/command-trees.md @@ -67,16 +67,16 @@ Say we want to take our `/sayhi` command from above and also have an argument wh /sayhi - Says "Hi!" to a target player ``` -We can do this by adding a `PlayerArgument` to our command. As described above, to add this argument, we must use the `then()` method: +We can do this by adding an `EntitySelectorArgument.OnePlayer` to our command. As described above, to add this argument, we must use the `then()` method: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#commandTreesExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/CommandTrees.java#commandTreesExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#commandTreesExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt#commandTreesExample ::: -In this example, we have our normal `/sayhi` command using the `executes()` method. We then add a new argument (a new "branch" in our "tree"), the `PlayerArgument`, using the `then()` method. **We want to make this branch executable, so we also use the `executes()` method _on the argument itself_**. To register the full command tree (which includes both `/sayhi` and `/sayhi `), we call `register()` on the `CommandTree` object. +In this example, we have our normal `/sayhi` command using the `executes()` method. We then add a new argument (a new "branch" in our "tree"), the `EntitySelectorArgument.OnePlayer`, using the `then()` method. **We want to make this branch executable, so we also use the `executes()` method _on the argument itself_**. To register the full command tree (which includes both `/sayhi` and `/sayhi `), we call `register()` on the `CommandTree` object. :::: @@ -86,22 +86,22 @@ Sometimes we will need such a `CommandTree`: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#legacyLargeArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/CommandTrees.java#legacyLargeArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#legacyLargeArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt#legacyLargeArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#legacyLargeArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt#legacyLargeArgumentsExampleDSL ::: Well, there's too much indentation. We can use nested arguments to reduce the indentation levels: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#nestedLargeArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/CommandTrees.java#nestedLargeArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#nestedLargeArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt#nestedLargeArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#nestedLargeArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt#nestedLargeArgumentsExampleDSL ::: That's effectively all of the basics of command trees! We start by writing a normal command, use `executes()` to make it executable and use `then()` to add additional paths to our command. Finally, we finish up with `register()` to register our command. Below, I've included a few more examples showcasing how to design commands using command trees. @@ -121,9 +121,9 @@ Say we wanted to create a plugin to let a user edit signs. We have a single comm :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#signeditCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/CommandTrees.java#signeditCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#signeditCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt#signeditCommandExample ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/executors/handle-failures.md b/docs/en/create-commands/executors/handle-failures.md index 079d75d51..25423436f 100644 --- a/docs/en/create-commands/executors/handle-failures.md +++ b/docs/en/create-commands/executors/handle-failures.md @@ -29,9 +29,9 @@ Therefore, to gracefully handle this with a proper error message, we use one of :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/HandleFailures.java#handleFailuresExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/HandleFailures.java#handleFailuresExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/HandleFailures.kt#handleFailuresExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/HandleFailures.kt#handleFailuresExample ::: :::: diff --git a/docs/en/create-commands/executors/native-sender.md b/docs/en/create-commands/executors/native-sender.md index e3e2b1e37..2a1b799e3 100644 --- a/docs/en/create-commands/executors/native-sender.md +++ b/docs/en/create-commands/executors/native-sender.md @@ -52,11 +52,11 @@ As you can see, this command takes no arguments. This is fine, since our "argume :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/NativeSender.java#breakCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/NativeSender.java#breakCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt#breakCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NativeSender.kt#breakCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt#breakCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NativeSender.kt#breakCommandExampleDSL ::: This can now be used via the following command examples: @@ -81,9 +81,9 @@ This `CommandSender` will work the same as any other `NativeProxyCommandSender` :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/NativeSender.java#constructorExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/NativeSender.java#constructorExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt#constructorExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NativeSender.kt#constructorExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt#constructorExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NativeSender.kt#constructorExampleDSL ::: diff --git a/docs/en/create-commands/executors/normal-executors.md b/docs/en/create-commands/executors/normal-executors.md index c4e4062cb..b05ac23e5 100644 --- a/docs/en/create-commands/executors/normal-executors.md +++ b/docs/en/create-commands/executors/normal-executors.md @@ -41,9 +41,9 @@ We use an argument "message" to hold the message to broadcast, we provide some a :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/NormalExecutors.java#broadcastExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/NormalExecutors.java#broadcastExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NormalExecutors.kt#broadcastExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NormalExecutors.kt#broadcastExample ::: Note how when we finish up our implementation of `.executes()`, we don't return anything. This is unlike commands in the standard Bukkit API where the `onCommand` method returns a Boolean value: @@ -76,9 +76,9 @@ Say we wanted to create a command `/suicide`, which kills the player that execut :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/NormalExecutors.java#suicideExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/NormalExecutors.java#suicideExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NormalExecutors.kt#suicideExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NormalExecutors.kt#suicideExample ::: :::: @@ -93,9 +93,9 @@ Extending on the suicide example above, we could write another implementation fo :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/NormalExecutors.java#differentImplExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/NormalExecutors.java#differentImplExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NormalExecutors.kt#differentImplExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NormalExecutors.kt#differentImplExample ::: This saves having to use `instanceof` multiple times to check the type of the `CommandSender`. @@ -136,9 +136,9 @@ Expanding on the suicide example above, we can restrict the command to only play :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/NormalExecutors.java#sameImplExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/NormalExecutors.java#sameImplExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/NormalExecutors.kt#sameImplExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/NormalExecutors.kt#sameImplExample ::: :::: diff --git a/docs/en/create-commands/executors/proxy-sender.md b/docs/en/create-commands/executors/proxy-sender.md index 4b0b4319b..2e64058fe 100644 --- a/docs/en/create-commands/executors/proxy-sender.md +++ b/docs/en/create-commands/executors/proxy-sender.md @@ -16,11 +16,11 @@ Say we have a command which kills the sender of a command. This is easily implem :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/ProxySender.java#simpleKillCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/ProxySender.java#simpleKillCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ProxySender.kt#simpleKillCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ProxySender.kt#simpleKillCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ProxySender.kt#simpleKillCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ProxySender.kt#simpleKillCommandExampleDSL ::: But what if the sender of the command is _not_ a player? By using Minecraft's `/execute` command, we could execute the command as _any_ arbitrary entity, as shown with the command below: @@ -33,11 +33,11 @@ To handle this case, we can use the `.executesProxy()` method to ensure that the :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/ProxySender.java#proxyKillCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/ProxySender.java#proxyKillCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ProxySender.kt#proxyKillCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ProxySender.kt#proxyKillCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ProxySender.kt#proxyKillCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ProxySender.kt#proxyKillCommandExampleDSL ::: This allows the command above to run successfully, killing all chickens it can find. diff --git a/docs/en/create-commands/executors/resulting-executors.md b/docs/en/create-commands/executors/resulting-executors.md index 895d4cab9..07257d6ec 100644 --- a/docs/en/create-commands/executors/resulting-executors.md +++ b/docs/en/create-commands/executors/resulting-executors.md @@ -32,11 +32,11 @@ Say we want a command that returns a random number as a result. This can then be :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/ResultingExecutors.java#randomResultCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/ResultingExecutors.java#randomResultCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomResultCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomResultCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomResultCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomResultCommandExampleDSL ::: This returns a **success value of 1** _(Because no errors or `CommandAPI.failWithString(String)` was thrown)_ and a **result value of a random number**. @@ -58,22 +58,22 @@ Since we're declaring commands that are to be used in `/execute`, we must ensure :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/ResultingExecutors.java#randomNumberCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/ResultingExecutors.java#randomNumberCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomNumberCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomNumberCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomNumberCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#randomNumberCommandExampleDSL ::: Now we write our implementation for `/givereward`. In this example, we use the `EntitySelectorArgument` to select a single player. We cast it to `Player` and then add the items to their inventory. :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/executors/ResultingExecutors.java#giverewardCommandExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/executors/ResultingExecutors.java#giverewardCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#giverewardCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#giverewardCommandExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#giverewardCommandExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt#giverewardCommandExampleDSL ::: Now that we've declared these commands, we can now use them in practice. We can use a command block to store a random number under the scoreboard score `randVal` for a player called `SomePlayer`, by executing the command `/randomnumber`. Since `/randomnumber` **returns** an integer, this value is stored in the scoreboard score: diff --git a/docs/en/create-commands/functions-and-tags/function-arguments.md b/docs/en/create-commands/functions-and-tags/function-arguments.md index a1e11bc32..96e8b454a 100644 --- a/docs/en/create-commands/functions-and-tags/function-arguments.md +++ b/docs/en/create-commands/functions-and-tags/function-arguments.md @@ -26,11 +26,11 @@ When provided with a function, it will execute that function. If instead a tag i :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/functionsandtags/FunctionArguments.java#functionArgumentsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/functionsandtags/FunctionArguments.java#functionArgumentsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt#functionArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt#functionArgumentsExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt#functionArgumentsExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt#functionArgumentsExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/functions-and-tags/function-wrapper.md b/docs/en/create-commands/functions-and-tags/function-wrapper.md index 152870b33..08610b1c9 100644 --- a/docs/en/create-commands/functions-and-tags/function-wrapper.md +++ b/docs/en/create-commands/functions-and-tags/function-wrapper.md @@ -48,9 +48,9 @@ The `run()` method runs the function. The command executor that runs this functi :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java#runExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java#runExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt#runExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt#runExample ::: ### `runAs(Entity)` diff --git a/docs/en/create-commands/functions-and-tags/functions.md b/docs/en/create-commands/functions-and-tags/functions.md index a5832c812..b560f177d 100644 --- a/docs/en/create-commands/functions-and-tags/functions.md +++ b/docs/en/create-commands/functions-and-tags/functions.md @@ -1,5 +1,6 @@ --- order: 1 +preferences: ["paper-spigot"] authors: - DerEchtePilz - willkroboth @@ -17,29 +18,58 @@ The CommandAPI has support to use Minecraft's [functions](https://minecraft.wiki Minecraft 1.16+ changes the way that datapacks are loaded on the server, so that they load before plugins are enabled. This means that non-vanilla commands that are declared in functions and tags will be detected as invalid, causing the server to throw a lot of errors at the very start. +
+ +To make commands available in datapacks, they have to be registered at the right place. More on that later. + +
+
+ The CommandAPI reloads datapacks once the server has finished loading using all declared commands, therefore **the error messages at the start of the server can be ignored**. +
+ ::: ## Using custom commands in functions -In order to use a command from your plugin in a `.mcfunction` file, you must register your command in your plugin's `onLoad()` method, instead of the `onEnable()` method. Failure to do so will not allow the command to be registered for Minecraft functions, causing the function file to fail to load during the server startup phase. +
+ +In order to use a command from your plugin in a `.mcfunction` file, you must register your command in your plugin's `bootstrap(BootstrapContext)` method, instead of the `onLoad()`/`onEnable()` method. Failure to do so will not allow the command to be registered for Minecraft functions, causing the function file to fail to load during the server startup phase. :::info -In short, if you want to register a command which can be used in Minecraft functions, register it in your plugin's `onLoad()` method. +In short, if you want to register a command which can be used in Minecraft functions, register it in your plugin's `bootstrap(BootstrapContext)` method. ::: +
+ ::::tip Example – Registering command for use in a function -Say we have a command `/killall` that simply kills all entities in all worlds on the server. If we were to register this in our `onLoad()` method, this would allow us to use the `/killall` command in Minecraft functions and tags. +
+ +Say we have a command `/killall` that simply kills all entities in all worlds on the server. To make it available in a function, we want to register the command in the `bootstrap(BootstrapContext)` method. :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/functionsandtags/Functions.java#functionsExample +<<< @/../reference-code/paper/src/main/java/createcommands/functionsandtags/Functions.java#functionsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/functionsandtags/Functions.kt#functionsExample +<<< @/../reference-code/paper/src/main/kotlin/createcommands/functionsandtags/Functions.kt#functionsExample ::: +
+
+ +Say we have a command `/killall` that simply kills all entities in all worlds on the server. It doesn't matter where we register to make the command available in a function, but we'll just use the `onLoad()` method here. + +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/createcommands/functionsandtags/Functions.java#functionsExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/functionsandtags/Functions.kt#functionsExample +::: + +
+ :::: \ No newline at end of file diff --git a/docs/en/create-commands/help.md b/docs/en/create-commands/help.md index 0a8817081..1c118f887 100644 --- a/docs/en/create-commands/help.md +++ b/docs/en/create-commands/help.md @@ -53,22 +53,22 @@ In this simple example, we implement the above screenshot's help topic. We regis :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Help.java#helpExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Help.java#helpExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Help.kt#helpExampleStep1 ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep1DSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Help.kt#helpExampleStep1DSL ::: We could also register this command using the `withHelp` method instead: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Help.java#helpExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Help.java#helpExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Help.kt#helpExampleStep2 ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep2DSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Help.kt#helpExampleStep2DSL ::: :::: @@ -87,18 +87,18 @@ In this example, we implement locale-specific help so players can see help in th :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Help.java#helpTopicExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Help.java#helpTopicExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpTopicExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Help.kt#helpTopicExampleStep1 ::: We then add our new `HelpTopic` to the command using the `withHelp` method: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Help.java#helpTopicExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Help.java#helpTopicExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpTopicExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Help.kt#helpTopicExampleStep2 ::: :::: diff --git a/docs/en/create-commands/permissions.md b/docs/en/create-commands/permissions.md index 144cb8919..e34235c46 100644 --- a/docs/en/create-commands/permissions.md +++ b/docs/en/create-commands/permissions.md @@ -33,18 +33,18 @@ Say we created a command `/god` that sets a player as being invulnerable. Since :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Permissions.java#withPermissionExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Permissions.java#withPermissionExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Permissions.kt#withPermissionExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt#withPermissionExample ::: As stated above, it is possible to assign a permission using a String instead of using `CommandPermission.fromString()`: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Permissions.java#withStringPermissionExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Permissions.java#withStringPermissionExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Permissions.kt#withStringPermissionExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt#withStringPermissionExample ::: :::: @@ -74,18 +74,18 @@ We first declare the command as normal. Nothing fancy is going on here: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Permissions.java#argumentPermissionExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Permissions.java#argumentPermissionExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Permissions.kt#argumentPermissionExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt#argumentPermissionExampleStep1 ::: -Now we declare our command with arguments. We use a `PlayerArgument` and apply the permission _to the argument_. After that, we register our command as normal: +Now we declare our command with arguments. We use a `EntitySelectorArgument.OnePlayer` and apply the permission _to the argument_. After that, we register our command as normal: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Permissions.java#argumentPermissionExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Permissions.java#argumentPermissionExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Permissions.kt#argumentPermissionExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt#argumentPermissionExampleStep2 ::: :::: @@ -121,9 +121,9 @@ We first declare the command as normal. Nothing fancy is going on here: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Permissions.java#childBasedPermissionExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Permissions.java#childBasedPermissionExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Permissions.kt#childBasedPermissionExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt#childBasedPermissionExample ::: In our **plugin.yml** we can also set up our permissions, for example... diff --git a/docs/en/create-commands/registration.md b/docs/en/create-commands/registration.md index 8316542ed..30a45dfe3 100644 --- a/docs/en/create-commands/registration.md +++ b/docs/en/create-commands/registration.md @@ -1,5 +1,6 @@ --- order: 1 +preferences: ["paper-spigot"] authors: - DerEchtePilz - willkroboth @@ -15,9 +16,9 @@ I think the easiest way to explain it is with an example: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Registration.java#registrationExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Registration.java#registrationExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Registration.kt#registrationExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Registration.kt#registrationExample ::: - First, we create a new `CommandAPICommand`, with the name of the command that the sender must enter to run it. @@ -202,11 +203,24 @@ Register the command with the provided plugin's name. ## Command loading order -It is recommended to register commands in either the `onLoad()` or `onEnable()` method. With the CommandAPI, depending on whether you use `onLoad()` or `onEnable()` to load your commands depends on whether your plugin is used with Minecraft's functions: +Places where you can register commands are listed below: -| When to load | What to do | -|---------------------|--------------------------------------------------------------------------------------------------------------------------------| -| `onLoad()` method | Register commands to be used in Minecraft functions ([see the Function section for more info](./functions-and-tags/functions)) | -| `onEnable()` method | Register regular commands | +
-The CommandAPI does support registering commands outside of these methods while the server is running. Commands registered after the server is done loading _should_ work the same as commands registered in `onEnable`. +| When to load | What to do | +|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------| +| `bootstrap(BootstrapContext)` method | Register commands to be used in Minecraft functions ([see the Function section for more info](./functions-and-tags/functions)) | +| `onLoad()`/`onEnable()` method | Register regular commands not available in datapacks | + +
+
+ +| When to load | What to do | +|--------------------------------|-----------------------------------------------------------------| +| `onLoad()`/`onEnable()` method | Register regular commands not available in datapacks by default | + +If you want your command to be accessible in Minecraft functions, make sure the [datapack reload](../user-setup/config#skip-initial-datapack-reload) process is set to `false`. + +
+ +The CommandAPI does support registering commands anytime after the server is done loading. Commands registered while the server is running _should_ work the same as commands registered in `onLoad()`/`onEnable()`. diff --git a/docs/en/create-commands/requirements.md b/docs/en/create-commands/requirements.md index b31415f02..72650128a 100644 --- a/docs/en/create-commands/requirements.md +++ b/docs/en/create-commands/requirements.md @@ -41,9 +41,9 @@ We want to put a requirement on this command that the player needs to have at le :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#baseOnPlayerLevelExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#baseOnPlayerLevelExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#baseOnPlayerLevelExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#baseOnPlayerLevelExample ::: It's important to note that in this example, we case the `sender` to a `player` for the requirement method. We know that the sender is definitely a player because we use `executesPlayer()`, which ensures that this is the case. Now that we've got this, **we need to make sure we update the player's requirements _when their exp changes_**. This is covered in more detail in the section about updating requirements below. @@ -69,18 +69,18 @@ To represent our party in code, we'll use a simple `Map` called `partyMembers` w :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#partySystemExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#partySystemExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep1 ::: To begin with, let's create the `/party create ` command. First, we must declare our arguments: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#partySystemExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#partySystemExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep2 ::: In this argument declaration, we put a requirement on the literal `create`, where the player does not have a party. In other words, if the player does not have a party, they are allowed to run `/party create `. If a player already has a party, then they won't be allowed to run this command. @@ -89,18 +89,18 @@ Now that we've declared our arguments, we can now declare our main command `/par :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#partySystemExampleStep3 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#partySystemExampleStep3 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep3 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep3 ::: So now we've added the ability to create a party if we're not already in it. Now we need to implement our `party tp ` command. Again, we must start by declaring our arguments: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#partySystemExampleStep4 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#partySystemExampleStep4 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep4 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep4 ::: Notice something here? There's some code repetition for the `withRequirement` method - this is the same predicate that we used earlier, except we remove the negation. If you are interested, you can view the section [Predicate tips](../tips/predicate-tips) for a method to improve code reuse. @@ -109,9 +109,9 @@ Once the arguments have been declared, we can now implement our party teleportat :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#partySystemExampleStep5 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#partySystemExampleStep5 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep5 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#partySystemExampleStep5 ::: What's important to note in this example is that if you spend the time to set up the arguments properly, it severely decreases the amount of code required to write your command. This makes the commands you declare easier to understand and follow and you don't end up having to put all of these checks in the body of your command executor. @@ -181,9 +181,9 @@ When a player creates a new party, we need to ensure that their requirements are :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#updateRequirementsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#updateRequirementsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#updateRequirementsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#updateRequirementsExample ::: That's it! @@ -200,9 +200,9 @@ For example, you can apply multiple requirements for a command by calling the `w :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Requirements.java#multipleRequirementsExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Requirements.java#multipleRequirementsExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Requirements.kt#multipleRequirementsExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt#multipleRequirementsExample ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/subcommands.md b/docs/en/create-commands/subcommands.md index 9a58fa4c1..21a889ce8 100644 --- a/docs/en/create-commands/subcommands.md +++ b/docs/en/create-commands/subcommands.md @@ -38,44 +38,44 @@ We can implement this by creating a `CommandAPICommand` with the command name `a :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Subcommands.java#subcommandsExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Subcommands.java#subcommandsExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep1 ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep1DSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep1DSL ::: Similarly, we have another part `remove `. We can declare this similar to our `add` command. Once we've done that, we can now join everything up together. Here, we create a command `group` which adds the two other subcommands: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Subcommands.java#subcommandsExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Subcommands.java#subcommandsExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep2 ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep2DSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep2DSL ::: Finally, we can link everything up together to the `perm` command and register the whole thing together: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Subcommands.java#subcommandsExampleStep3 +<<< @/../reference-code/bukkit/src/main/java/createcommands/Subcommands.java#subcommandsExampleStep3 ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep3 +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep3 ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep3DSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsExampleStep3DSL ::: Another, more intuitive method, is to shove everything in one go without creating lots of variables all over the place: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Subcommands.java#subcommandsFullExample +<<< @/../reference-code/bukkit/src/main/java/createcommands/Subcommands.java#subcommandsFullExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsFullExample +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsFullExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/Subcommands.kt#subcommandsFullExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt#subcommandsFullExampleDSL ::: :::: \ No newline at end of file diff --git a/docs/en/create-commands/unregistration.md b/docs/en/create-commands/unregistration.md index 98fd23f88..b795fd7f3 100644 --- a/docs/en/create-commands/unregistration.md +++ b/docs/en/create-commands/unregistration.md @@ -1,6 +1,8 @@ --- order: 2 +preferences: ["paper-spigot"] authors: + - DerEchtePilz - willkroboth - MC-XiaoHei --- @@ -17,7 +19,32 @@ CommandAPI.unregister(String commandName, boolean unregisterNamespaces); CommandAPIBukkit.unregister(String commandName, boolean unregisterNamespaces, boolean unregisterBukkit); ``` -To understand when and how to use these methods, you need to know a little about how Bukkit loads and sets up commands. This is basically the order of events when a Bukkit server starts: +
+ +To understand when and how to use these methods, you need to know a little about how Paper loads and sets up commands. This is basically the order of events when a Paper server starts: + +1. Plugins are initialized + - `PluginBootstrap#boostrap(BootstrapContext)` is called +2. Vanilla commands are registered +3. Lifecycle events for the bootstrap stage are executed +4. Bukkit commands are placed in the Bukkit CommandMap + - Given the `bukkit` namespace +5. Plugins are loaded + - `onLoad()` is called +6. Plugins are enabled + - If a plugin uses it, then + - Plugin commands are read from the [`plugin.yml` file](https://www.spigotmc.org/wiki/plugin-yml/#commands) and placed in the Bukkit CommandMap + - Given the plugin's name as their namespace (e.g. `luckperms:lp`) + - `onEnable` is called + - Repeat for each plugin +7. Bukkit's help command is registered +8. Lifecycle events for the plugin stage are executed +9. The server is done loading + +
+
+ +To understand when and how to use these methods, you need to know a little about how Spigot loads and sets up commands. This is basically the order of events when a Spigot server starts: 1. Vanilla commands are placed in the Vanilla CommandDispatcher 2. Bukkit commands are placed in the Bukkit CommandMap @@ -34,6 +61,8 @@ To understand when and how to use these methods, you need to know a little about - Given the `minecraft` namespace (e.g. `minecraft:gamemode`) 7. The server is done loading +
+ Unregistering a command only works if it happens after the command is created. Bukkit's command system is special and has two locations where commands can exist -- either the Vanilla CommandDispatcher or the Bukkit CommandMap -- so you also need to know where your command is registered. With that in mind, here is what each of the `unregister` methods do: ```java @@ -56,57 +85,133 @@ Unregisters a command from Bukkit. As before, if `unregisterNamespaces` is `true To give a better idea of how and when to use these methods, the rest of this page documents how to unregister different types of commands. +
+ +::::tip Developer's Note: +But first, let's take a look at where the CommandAPI registers commands. While you are able to call the `register()` method basically anywhere (as mentioned on the [registration page](registration.md#command-loading-order)), CommandAPI commands +are only actually registered in two places: step 3 and step 8 of the loading sequence above. + +Step 3 applies if you register commands in a bootstrap context which may look something like this: + +:::tabs +===Java +<<< @/../reference-code/paper/src/main/java/createcommands/Unregistration.java#registerBootstrapExample +===Kotlin +<<< @/../reference-code/paper/src/main/kotlin/createcommands/Unregistration.kt#registerBootstrapExample +::: + +Note that the `CommandAPI#onLoad(CommandAPIConfig)` call is now in the `bootstrap` method. + +Step 8 applies if you register commands in the `JavaPlugin#onLoad()` or the `JavaPlugin#onEnable()` methods. + +Similarly, unregistrations are also handled in a lifecycle event which runs after the events that register commands. + +:::: + +
+ ## Unregistering a Bukkit command - `/version` +
+ +:::tip Developer's Note: +Paper has recently converted some commands that were Bukkit commands before to Brigadier commands. This includes the `/version` command. For demonstration's sake we'll assume it is still a Bukkit command (which still does apply to some versions). +::: + +`/version` is a command provided by Bukkit. Looking at the sequence of events above, that means it is created during step 4, before plugins are loaded in step 5. Consequently, the command will exist when the unregistration event is ran after step 8. Here we'll unregister the command in `onLoad`, but the same would work in `onEnable` too. + +
+
+ `/version` is a command provided by Bukkit. Looking at the sequence of events above, that means it is created during step 2, before plugins are loaded in step 3. Consequently, the command will exist when our plugin's `onLoad` method is called, so we'll unregister it there. The same code will work in `onEnable` too, since step 4 is also after step 2. +
+ Since this command exists in the Bukkit CommandMap, we'll need to use `CommandAPIBukkit#unregister` with `unregisterBukkit` set to `true`. We'll also remove the namespaced version -- `/bukkit:version` -- so `unregisterNamespaces` will be `true`. All together, the code looks like this: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterBukkitExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterBukkitExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterBukkitExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterBukkitExample ::: With this plugin, executing `/version` or `/bukkit:version` will give the unknown command message. Note that aliases like `/ver` and its namespaced version `/bukkit:ver` will still work. To remove aliases as well, you need to unregister each as its own command. For, `/ver`, that would mean calling `CommandAPIBukkit.unregister("ver", true, true)`. ## Unregistering a Vanilla command - `/gamemode` +
+ +`/gamemode` is a command provided by Vanilla Minecraft. Like the [previous example](#unregistering-a-bukkit-command-version), Vanilla commands are created in step 2, before lifecycle events for the bootstrap stage are ran and plugins are loaded in step 5. For variety, we'll unregister the command in our plugin's `onEnable` -- step 6 -- but the same code would also work in `onLoad`. + +
+
+ `/gamemode` is a command provided by Vanilla Minecraft. Like the [previous example](#unregistering-a-bukkit-command-version), Vanilla commands are created in step 1, before plugins are loaded in step 3. For variety, we'll unregister the command in our plugin's `onEnable` -- step 4 -- but the same code would also work in `onLoad`. +
+ Since this command exists in the Vanilla CommandDispatcher, we can use `CommandAPI#unregister`. That works the same as `CommandAPIBukkit#unregister` with `unregisterBukkit` set to `false`. We don't care about the namespace, so `unregisterNamespaces` will be `false`. That means we can use the simplest method, `CommandAPI.unregister(String commandName)`, since it sets `unregisterNamespaces` to `false` by default. All together, the code looks like this: :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterVanillaExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterVanillaExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaExample ::: +
+ With this code, executing `/gamemode` will give the unknown command exception as expected. However, even though `unregisterNamespaces` was `false`, `/minecraft:gamemode` can also not be run. This happens because Vanilla commands are given their namespace in step 6, after our plugin has removed `/gamemode`. When the server starts, `/gamemode` is created in step 2 inside the Vanilla CommandDispatcher. In step 4, our plugin is enabled and we remove the `/gamemode` command from that CommandDispatcher. After all the plugins enable, step 6 moves all commands in the Vanilla CommandDispatcher to the Bukkit CommandMap and gives them the `minecraft` namespace. Since `/gamemode` doesn't exist at this point, step 6 cannot create the `/minecraft:gamemode` command. So, even though `unregisterNamespaces` was `false`, `/minecraft:gamemode` doesn't exist anyway. +
+ ::::tip Example - Replacing Minecraft's `/gamemode` command +
+ +To replace a command, simply register a new implementation for that command. Any attempts to unregister first will result in the new implementation to also not be present. + +:::tabs +===Java +<<< @/../reference-code/paper/src/main/java/createcommands/Unregistration.java#unregisterVanillaAndReplaceExample +===Kotlin +<<< @/../reference-code/paper/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaAndReplaceExample +::: + +
+
+ To replace a command, first unregister the original command, then register a new implementation for that command. :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterVanillaAndReplaceExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterVanillaAndReplaceExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaAndReplaceExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaAndReplaceExample ::: +
+ Now, when `/gamemode` is executed, it will use the new implementation defined using the CommandAPI. :::: ## Unregistering a Plugin command - `/luckperms:luckperms` +
+ +The `/luckperms` command is provided by the Bukkit [LuckPerms](https://luckperms.net/) plugin. Plugin commands are created during step 6, immediately before calling the `onEnable` method of the respective plugin. Since unregistrations run after step 8, it does not matter where we unregister, however here we choose to do it in the `onEnable`. We also have to make sure that our plugin is loaded after LuckPerms. The best way to make sure that happens is to add LuckPerms as a `depend` or `softdepend` in our plugin's plugin.yml. You can read more about the different between `depend` and `softdepend` in [Spigot's documentation](https://www.spigotmc.org/wiki/plugin-yml/#optional-attributes), but that will look something like this: + +
+
+ The `/luckperms` command is provided by the Bukkit [LuckPerms](https://luckperms.net/) plugin. Plugin commands are created during step 4, immediately before calling the `onEnable` method of the respective plugin. In this case, unregistering the command in our own plugin's `onLoad` would not work, since the command wouldn't exist yet. We also have to make sure that our `onEnable` method is called after LuckPerm's. The best way to make sure that happens is to add LuckPerms as a `depend` or `softdepend` in our plugin's plugin.yml. You can read more about the different between `depend` and `softdepend` in [Spigot's documentation](https://www.spigotmc.org/wiki/plugin-yml/#optional-attributes), but that will look something like this: +
+ ```yaml name: MyPlugin main: some.package.name.Main @@ -119,15 +224,24 @@ Since plugin commands are stored in the Bukkit CommandMap, we need to use `Comma :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterPluginExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterPluginExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterPluginExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterPluginExample ::: Executing `/luckperms` will work as normal, but `/luckperms:luckperms` will give the unknown command message. ## Unregistering a CommandAPI command +
+ +Unregistering a command created by the CommandAPI is easy. + +For our example, let's say we want to unregister the `/break` command created by the [Bukkit Maven Example Project](https://github.com/CommandAPI/CommandAPI/tree/master/examples/bukkit/maven) for the CommandAPI. + +
+
+ Unregistering a command created by the CommandAPI is similar to both unregistering a Vanilla command and a plugin command. Like a Vanilla command, CommandAPI commands are stored in the Vanilla CommandDispatcher, so they should be unregistered with `unregisterBukkit` set to `false`. Like plugin commands, they may be created in `onEnable`, so you need to make sure your plugin is enabled after the plugin that adds the command. Unlike plugin commands, CommandAPI commands may be created in `onLoad`, as discussed in [Command loading order](./registration#command-loading-order). That just means you may also be able to unregister the command in you own plugin's `onLoad`. As always, simply make sure you unregister a command after it is created, and it will be removed properly. @@ -152,7 +266,7 @@ For the ExamplePlugin, setting `verbose-outputs` to `true` gives this: ```log [Server thread/INFO]: [ExamplePlugin] Enabling ExamplePlugin v0.0.1 [Server thread/INFO]: [CommandAPI] Registering command /break block -[Server thread/INFO]: [CommandAPI] Registering command /myeffect target potion +[Server thread/INFO]: [CommandAPI] Registering command /myeffect target potion [Server thread/INFO]: [CommandAPI] Registering command /nbt nbt ``` @@ -162,15 +276,19 @@ You can see that the ExamplePlugin registers its commands when `onEnable` is cal In summary, we will unregister the `/break` command in our plugin's `onEnable`. We added Example plugin to the `depend` list in our plugin.yml so that our `onEnable` method runs second. `unregisterNamespaces` and `unregisterBukkit` will be set to `false`, and those are the default values, so we can simply use `CommandAPI.unregister(String commandName)`. All together, the code looks like this: +
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterCommandAPIExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterCommandAPIExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterCommandAPIExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterCommandAPIExample ::: Now, when you try to execute `/break`, you will just get the unknown command message as if it never existed. +
+ ## Special case: Unregistering Bukkit's `/help` If you look at the sequence of events at the top of this page, you might notice that Bukkit's `/help` command gets its own place in step 5. Unlike the other [Bukkit commands](#unregistering-a-bukkit-command-version), `/help` is special and gets registered after plugins are loaded and enabled (don't ask, I don't know why :P). That means unregistering `/help` in `onLoad` or `onEnable` does not work, since the command doesn't exist yet. @@ -181,9 +299,9 @@ Since `/help` is in the Bukkit CommandMap, we need to use `CommandAPIBukkit#unre :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterBukkitHelpExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterBukkitHelpExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterBukkitHelpExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterBukkitHelpExample ::: Funnily, if you try to execute `/help`, the server will still tell you: `Unknown command. Type "/help" for help.`. Luckily, `unregisterNamespaces` was `false`, so you can still use `/bukkit:help` to figure out your problem. @@ -200,9 +318,9 @@ Finally, `unregisterNamespaces` should be `false`, and since that's the default :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterVanillaNamespaceOnlyExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterVanillaNamespaceOnlyExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaNamespaceOnlyExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterVanillaNamespaceOnlyExample ::: With this code, `/gamemode` will execute as normal, but `/minecraft:gamemode` will give the unknown command message. @@ -213,9 +331,9 @@ Doing the opposite action here -- only unregistering `/gamemode` but keeping `/m :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterDelayedVanillaBadExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterDelayedVanillaBadExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterDelayedVanillaBadExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterDelayedVanillaBadExample ::: The expected outcome of this code is that `/minecraft:gamemode` would work as expected, and `/gamemode` would give the command not found message. However, that is only true for the player's commands. If you try to use `/minecraft:gamemode` in the console, it *will not work* properly. Specifically, while you can tab-complete the command's label, `minecraft:gamemode` the command's arguments will not have any suggestions. If you try to execute `/minecraft:gamemode` in the console, it will always tell you your command is unknown or incomplete. @@ -224,9 +342,11 @@ The main point is that if you ever try to unregister a Vanilla command after the :::tabs ===Java -<<< @/../reference-code/src/main/java/createcommands/Unregistration.java#unregisterDelayedVanillaGoodExample +<<< @/../reference-code/spigot/src/main/java/createcommands/Unregistration.java#unregisterDelayedVanillaGoodExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/Unregistration.kt#unregisterDelayedVanillaGoodExample +<<< @/../reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt#unregisterDelayedVanillaGoodExample ::: -:::: \ No newline at end of file +:::: + +
\ No newline at end of file diff --git a/docs/en/dev-setup/annotations.md b/docs/en/dev-setup/annotations.md index 8624b3617..8d7685583 100644 --- a/docs/en/dev-setup/annotations.md +++ b/docs/en/dev-setup/annotations.md @@ -22,7 +22,7 @@ The annotation system effectively needs to be added twice: Once for compilation dev.jorel commandapi-annotations - 10.1.2 + 11.0.0 provided @@ -42,7 +42,7 @@ The annotation system effectively needs to be added twice: Once for compilation dev.jorel commandapi-annotations - 10.1.2 + 11.0.0 @@ -81,8 +81,8 @@ The annotation system effectively needs to be added twice: Once for compilation ```groovy dependencies { - compileOnly "dev.jorel:commandapi-annotations:10.1.2" - annotationProcessor "dev.jorel:commandapi-annotations:10.1.2" + compileOnly "dev.jorel:commandapi-annotations:11.0.0" + annotationProcessor "dev.jorel:commandapi-annotations:11.0.0" } ``` @@ -90,8 +90,8 @@ The annotation system effectively needs to be added twice: Once for compilation ```kotlin dependencies { - compileOnly("dev.jorel:commandapi-annotations:10.1.2") - annotationProcessor("dev.jorel:commandapi-annotations:10.1.2") + compileOnly("dev.jorel:commandapi-annotations:11.0.0") + annotationProcessor("dev.jorel:commandapi-annotations:11.0.0") } ``` diff --git a/docs/en/dev-setup/setup.md b/docs/en/dev-setup/setup.md index c4b7d4f16..4df4f2351 100644 --- a/docs/en/dev-setup/setup.md +++ b/docs/en/dev-setup/setup.md @@ -1,6 +1,6 @@ --- order: 1 -preferences: ["build-system"] +preferences: ["build-system", "paper-spigot"] authors: - JorelAli - DerEchtePilz @@ -46,17 +46,35 @@ If you've never used a build system before, I highly recommend it! It makes it e - Add the dependency to your `pom.xml`: +
+ + ```xml + + + dev.jorel + commandapi-paper-core + 11.0.0 + provided + + + ``` + +
+
+ ```xml dev.jorel - commandapi-bukkit-core - 10.1.2 + commandapi-spigot-core + 11.0.0 provided ``` +
+
@@ -88,22 +106,47 @@ If you've never used a build system before, I highly recommend it! It makes it e
+
+ + ```groovy + dependencies { + compileOnly "dev.jorel:commandapi-paper-core:11.0.0" + } + ``` + +
+
+ ```groovy dependencies { - compileOnly "dev.jorel:commandapi-bukkit-core:10.1.2" + compileOnly "dev.jorel:commandapi-spigot-core:11.0.0" } ``` +
+
+
+ + ```kotlin + dependencies { + compileOnly("dev.jorel:commandapi-paper-core:11.0.0") + } + ``` + +
+
+ ```kotlin dependencies { - compileOnly("dev.jorel:commandapi-bukkit-core:10.1.2") + compileOnly("dev.jorel:commandapi-spigot-core:11.0.0") } ```
+
diff --git a/docs/en/dev-setup/shading.md b/docs/en/dev-setup/shading.md index dc9fcb2a4..97b06c640 100644 --- a/docs/en/dev-setup/shading.md +++ b/docs/en/dev-setup/shading.md @@ -1,6 +1,6 @@ --- order: 2 -preferences: ["build-system", "mapping"] +preferences: ["build-system", "paper-spigot"] authors: - JorelAli - DerEchtePilz @@ -31,48 +31,82 @@ If you want to handle reloading, the CommandAPI has minimal support for it with ### Loading -The `onLoad(CommandAPIConfig)` method initializes the CommandAPI's loading sequence. This must be called _before_ you start to access the CommandAPI and must be placed in your plugin's `onLoad()` method. The argument `CommandAPIConfig` is used to configure how the CommandAPI works. The `CommandAPIConfig` class has the following parameters which let you set how the CommandAPI works similar to the `config.yml`, which is described [here](../user-setup/config). +The `onLoad(CommandAPIConfig)` method initializes the CommandAPI. This must be called _before_ you access any other CommandAPI features. The `CommandAPIConfig` argument is used to configure how the CommandAPI works, similar to the `config.yml`. The `CommandAPIConfig` class follows a builder pattern, with methods for each option in the `config.yml`, which are listed and described [here](../user-setup/config). + +
+ +However, the `CommandAPIConfig` class is abstract and can’t be used to configure the CommandAPI directly. Instead, you must use a subclass of `CommandAPIConfig` that corresponds to the platform you’re developing for. For example, when developing for a Paper server, you should use the `CommandAPIPaperConfig` class. ```java -public class CommandAPIConfig { - CommandAPIConfig verboseOutput(boolean value); // Enables verbose logging - CommandAPIConfig silentLogs(boolean value); // Disables ALL logging (except errors) - CommandAPIConfig useLatestNMSVersion(boolean value); // Whether the latest NMS implementation should be used or not - CommandAPIConfig beLenientForMinorVersions(boolean value); // Whether the CommandAPI should be more lenient with minor Minecraft versions - CommandAPIConfig missingExecutorImplementationMessage(String value); // Set message to display when executor implementation is missing - CommandAPIConfig dispatcherFile(File file); // If not null, the CommandAPI will create a JSON file with Brigadier's command tree - CommandAPIConfig setNamespace(String namespace); // The namespace to use when the CommandAPI registers a command - - CommandAPIConfig initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor); // Initializes hooks with an NBT API. See NBT arguments documentation page for more info +public class CommandAPIPaperConfig { + // Create a new config object + CommandAPIPaperConfig(PluginMeta pluginMeta, LifecycleEventOwner lifecycleEventOwner); + + // General CommandAPI configuration + CommandAPIPaperConfig verboseOutput(boolean value); // Enables verbose logging + CommandAPIPaperConfig silentLogs(boolean value); // Disables ALL logging (except errors) + CommandAPIPaperConfig dispatcherFile(File file); // If not null, the CommandAPI will create a JSON file with Brigadier's command tree + CommandAPIPaperConfig setNamespace(String namespace); // The namespace to use when the CommandAPI registers a command + + // General CommandAPI configuration for Bukkit-based servers + CommandAPIPaperConfig fallbackToLatestNMS(boolean fallbackToLatestNMS); // Whether the CommandAPI should fall back to the latest NMS version if no implementation for the current version was found + CommandAPIPaperConfig missingExecutorImplementationMessage(String value); // Set message to display when executor implementation is missing + CommandAPIPaperConfig initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor); // Initializes hooks with an NBT API. See NBT arguments documentation page for more info } ``` -The `CommandAPIConfig` class follows a typical builder pattern (without you having to run `.build()` at the end), which lets you easily construct configuration instances. +In order to create a `CommandAPIPaperConfig` object, you must give it a reference to a `LifecycleEventOwner` instance, meaning either a `JavaPlugin` or `BootstrapContext` instance. The CommandAPI always uses this to register commands and events, so it is required when loading the CommandAPI on Paper. -However, the `CommandAPIConfig` class is abstract and can’t be used to configure the CommandAPI directly. Instead, you must use a subclass of `CommandAPIConfig` that corresponds to the platform you’re developing for. For example, when developing for Bukkit, you should use the `CommandAPIBukkitConfig` class. +For example, to load the CommandAPI on Paper with all logging disabled, you can use the following: - +:::tabs +===Java +<<< @/../reference-code/paper/src/main/java/devsetup/Shading.java#bukkitConfigExample +===Kotlin +<<< @/../reference-code/paper/src/main/kotlin/devsetup/Shading.kt#bukkitConfigExample +::: -```java -public class CommandAPIBukkitConfig extends CommandAPIConfig { - CommandAPIBukkitConfig(JavaPlugin plugin); +
+
+ +However, the `CommandAPIConfig` class is abstract and can’t be used to configure the CommandAPI directly. Instead, you must use a subclass of `CommandAPIConfig` that corresponds to the platform you’re developing for. For example, when developing for a Spigot server, you should use the `CommandAPISpigotConfig` class. - CommandAPIBukkitConfig shouldHookPaperReload(boolean hooked); // Whether the CommandAPI should hook into the Paper-exclusive ServerResourcesReloadedEvent - CommandAPIBukkitConfig skipReloadDatapacks(boolean skip); // Whether the CommandAPI should reload datapacks on server load +```java +public class CommandAPISpigotConfig { + // Create a new config object + CommandAPISpigotConfig(JavaPlugin plugin); + + // General CommandAPI configuration + CommandAPISpigotConfig verboseOutput(boolean value); // Enables verbose logging + CommandAPISpigotConfig silentLogs(boolean value); // Disables ALL logging (except errors) + CommandAPISpigotConfig dispatcherFile(File file); // If not null, the CommandAPI will create a JSON file with Brigadier's command tree + CommandAPISpigotConfig setNamespace(String namespace); // The namespace to use when the CommandAPI registers a command + + // General CommandAPI configuration for Bukkit-based servers + CommandAPISpigotConfig fallbackToLatestNMS(boolean fallbackToLatestNMS); // Whether the CommandAPI should fall back to the latest NMS version if no implementation for the current version was found + CommandAPISpigotConfig missingExecutorImplementationMessage(String value); // Set message to display when executor implementation is missing + CommandAPISpigotConfig initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor); // Initializes hooks with an NBT API. See NBT arguments documentation page for more info + + // Spigot-specific configuration + CommandAPISpigotConfig skipReloadDatapacks(boolean skip); // Whether the CommandAPI should reload datapacks on server load } ``` -In order to create a `CommandAPIBukkitConfig` object, you must give it a reference to your `JavaPlugin` instance. The CommandAPI always uses this to register events, so it is required when loading the CommandAPI on Bukkit. There are also Bukkit-specific features, such as the `hook-paper-reload` configuration option, which may be configured using a `CommandAPIBukkitConfig` instance. +In order to create a `CommandAPISpigotConfig` object, you must give it a reference to your `JavaPlugin` instance. The CommandAPI always uses this to register events, so it is required when loading the CommandAPI on Spigot. -For example, to load the CommandAPI on Bukkit with all logging disabled, you can use the following: +For example, to load the CommandAPI on Spigot with all logging disabled, you can use the following: :::tabs ===Java -<<< @/../reference-code/src/main/java/devsetup/Shading.java#bukkitConfigExample +<<< @/../reference-code/spigot/src/main/java/devsetup/Shading.java#bukkitConfigExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/devsetup/Shading.kt#bukkitConfigExample +<<< @/../reference-code/spigot/src/main/kotlin/devsetup/Shading.kt#bukkitConfigExample ::: +
+ + + ### Enabling & Disabling The `onEnable()` method initializes the CommandAPI's enabling sequence. Similar to the `onLoad(CommandAPIConfig)` method, this must be placed in your plugin's `onEnable()` method. This isn't as strict as the `onLoad(CommandAPIConfig)` method, and can be placed anywhere in your `onEnable()` method. @@ -81,13 +115,29 @@ The `onDisable()` method disables the CommandAPI gracefully. This should be plac :::tip Example – Setting up the CommandAPI in your plugin +
+
+ :::tabs ===Java -<<< @/../reference-code/src/main/java/devsetup/Shading.java#shadingExample +<<< @/../reference-code/paper/src/main/java/devsetup/Shading.java#shadingExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/devsetup/Shading.kt#shadingExample +<<< @/../reference-code/paper/src/main/kotlin/devsetup/Shading.kt#shadingExample ::: +
+
+ +:::tabs +===Java +<<< @/../reference-code/spigot/src/main/java/devsetup/Shading.java#shadingExample +===Kotlin +<<< @/../reference-code/spigot/src/main/kotlin/devsetup/Shading.kt#shadingExample +::: + +
+
+ ## A note about relocating By default, the CommandAPI is written in the `dev.jorel.commandapi` package. It is **highly recommended** to "relocate" the shaded copy of the CommandAPI to your own package instead to prevent package clashes with other projects that shade the CommandAPI: @@ -106,29 +156,31 @@ To shade the CommandAPI into a maven project, you'll need to use the `commandapi Add the CommandAPI shade dependency: -
+
```xml dev.jorel - commandapi-bukkit-shade - 10.1.2 + commandapi-spigot-shade + 11.0.0 ``` +
-
+
```xml dev.jorel - commandapi-bukkit-shade-mojang-mapped - 10.1.2 + commandapi-paper-shade + 11.0.0 ``` +
You can shade the CommandAPI easily by adding the `maven-shade-plugin` to your build sequence: @@ -217,39 +269,43 @@ repositories { Next, we declare our dependencies:
-
+
```groovy dependencies { - implementation "dev.jorel:commandapi-bukkit-shade:10.1.2" + implementation "dev.jorel:commandapi-spigot-shade:11.0.0" } ``` +
-
+
```groovy dependencies { - implementation "dev.jorel:commandapi-bukkit-shade-mojang-mapped:10.1.2" + implementation "dev.jorel:commandapi-paper-shade:11.0.0" } ``` +
-
+
```kotlin dependencies { - implementation("dev.jorel:commandapi-bukkit-shade:10.1.2") + implementation("dev.jorel:commandapi-spigot-shade:11.0.0") } ``` +
-
+
```kotlin dependencies { - implementation("dev.jorel:commandapi-bukkit-shade-mojang-mapped:10.1.2") + implementation("dev.jorel:commandapi-paper-shade:11.0.0") } ``` +
diff --git a/docs/en/internal/brigadier-plus-commandapi.md b/docs/en/internal/brigadier-plus-commandapi.md index c0289d7e1..9d93ca3ec 100644 --- a/docs/en/internal/brigadier-plus-commandapi.md +++ b/docs/en/internal/brigadier-plus-commandapi.md @@ -94,54 +94,54 @@ Now that we've established what we want, we can finally begin writing the code! :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep1 ::: With that completed, we can now create our "argument" to this predicate. To do this, we'll use the regular declaration of arguments that we would normally use for commands. In this example, because we're computing $\frac{numerator}{denominator}$, we want our numerator to be 0 or greater and our denominator to be 1 or greater (we don't want any negative numbers or division by zero!): :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep2 ::: Now we're going to get into the very nitty-gritty part - the predicate declaration. First, we'll create some variables `numerator` and `denominator` to represent the brigadier instances of these arguments. This can be handled by using the `Brigadier.argBuildOf` function: :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep3 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep3 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep3 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep3 ::: Now we'll define our predicate. Since this is sort of a "meta-command" (it directly affects the outcome of the `run` command), we need to use the `ArgumentBuilder`'s `fork` method. Remember that after we run this predicate, we want to link back to `execute` again, so our first argument is the `CommandNode` for `execute`, which we can get using `Brigadier.getRootNode().getChild("execute")`. Then, we can simply use `Brigadier.fromPredicate` to finish our declaration: :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep4 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep4 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep4 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep4 ::: Finally, we can now link everything up. We know that `numerator` comes first, **then** `denominator`, so we have to have `numerator.then(denominator)`. We also know that these arguments are the **children** of the `randomChance` literal, so we use the following code to state all of this: :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep5 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep5 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep5 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep5 ::: Finally, we "register" the command. In this case, we're actually just adding the `randomChance` node under `execute → if`, which we can add using the following code: :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep6 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExampleStep6 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep6 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExampleStep6 ::: #### Code summary @@ -150,9 +150,9 @@ So, hopefully that wasn't too confusing! If you're still lost, here's the whole :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExample +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java#addPredicateExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExample +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt#addPredicateExample ::: :::: \ No newline at end of file diff --git a/docs/en/internal/brigadier-suggestions.md b/docs/en/internal/brigadier-suggestions.md index 9cb9bca9c..52a4dccc3 100644 --- a/docs/en/internal/brigadier-suggestions.md +++ b/docs/en/internal/brigadier-suggestions.md @@ -42,9 +42,9 @@ For this command, we'll use a `GreedyStringArgument` as if we were making a gene :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierSuggestions.java#emojiCommandExample +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierSuggestions.java#emojiCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierSuggestions.kt#emojiCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierSuggestions.kt#emojiCommandExample ::: In this example, we simply create the `GreedyStringArgument` and use `replaceSuggestions()` to specify our suggestion rules. We create an offset using the current builder to make suggestions start at the last character (the current builder start `builder.getStart()` and the current length of what the user has already typed `info.currentArg().length()`). Finally, we build the suggestions with `builder.buildFuture()` and then register our command as normal. @@ -67,9 +67,9 @@ For this command, we'll use a `GreedyStringArgument` because that allows users t :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierSuggestions.java#commandArgumentsExampleStep1 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierSuggestions.java#commandArgumentsExampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierSuggestions.kt#commandArgumentsExampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierSuggestions.kt#commandArgumentsExampleStep1 ::: There's a lot to unpack there, but it's generally split up into four key sections: @@ -92,9 +92,9 @@ We use the command suggestions declared above by using the `replaceSuggestions` :::tabs ===Java -<<< @/../reference-code/src/main/java/internal/BrigadierSuggestions.java#commandArgumentsExampleStep2 +<<< @/../reference-code/bukkit/src/main/java/internal/BrigadierSuggestions.java#commandArgumentsExampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/internal/BrigadierSuggestions.kt#commandArgumentsExampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/internal/BrigadierSuggestions.kt#commandArgumentsExampleStep2 ::: :::: \ No newline at end of file diff --git a/docs/en/internal/internal.md b/docs/en/internal/internal.md index b07cef7bb..a97d78679 100644 --- a/docs/en/internal/internal.md +++ b/docs/en/internal/internal.md @@ -33,11 +33,10 @@ The CommandAPI's arguments are representations of the different arguments that t | `minecraft:entity` | [`EntitySelectorArgument`](../create-commands/arguments/types/entities-arguments#entity-selector-argument) | | `minecraft:entity_anchor` | | | `minecraft:entity_summon` | [`EntityTypeArgument`](../create-commands/arguments/types/entities-arguments#entity-type-argument) | -| `minecraft:float_range` | [`FloatRangeArgument`](../create-commands/arguments/types/ranged-arguments#the-integerrange--floatrange-class) | +| `minecraft:float_range` | [`DoubleRangeArgument`](../create-commands/arguments/types/ranged-arguments#the-integer-range-and-double-range-class) | | `minecraft:function` | [`FunctionArgument`](../create-commands/functions-and-tags/function-arguments) | -| `minecraft:game_profile` | [`PlayerArgument`](../create-commands/arguments/types/entities-arguments#player-argument) | -| `minecraft:game_profile` | [`OfflinePlayerArgument`](../create-commands/arguments/types/entities-arguments#offlineplayer-argument) | -| `minecraft:int_range` | [`IntegerRangeArgument`](../create-commands/arguments/types/ranged-arguments#the-integerrange--floatrange-class) | +| `minecraft:game_profile` | [`PlayerProfileArgument`](../create-commands/arguments/types/entities-arguments#playerprofile-argument) | +| `minecraft:int_range` | [`IntegerRangeArgument`](../create-commands/arguments/types/ranged-arguments#the-integer-range-and-double-range-class) | | `minecraft:item_enchantment` | [`EnchantmentArgument`](../create-commands/arguments/types/misc/enchantment-arguments) | | `minecraft:item_predicate` | [`ItemStackPredicateArgument`](../create-commands/arguments/types/predicate/itemstack-predicate-arguments) | | `minecraft:item_slot` | | diff --git a/docs/en/kotlin-dsl/delegated-properties.md b/docs/en/kotlin-dsl/delegated-properties.md index 8b6e1c580..d6e2feda0 100644 --- a/docs/en/kotlin-dsl/delegated-properties.md +++ b/docs/en/kotlin-dsl/delegated-properties.md @@ -24,7 +24,7 @@ To be able to access arguments by using delegated properties, your variable name :::tabs ===Kotlin -<<< @/../reference-code/src/main/kotlin/kotlindsl/DelegatedProperties.kt#delegatedPropertiesExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/DelegatedProperties.kt#delegatedPropertiesExample ===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/kotlindsl/DelegatedProperties.kt#delegatedPropertiesExampleDSL +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/DelegatedProperties.kt#delegatedPropertiesExampleDSL ::: \ No newline at end of file diff --git a/docs/en/kotlin-dsl/intro.md b/docs/en/kotlin-dsl/intro.md index 54abf6a3a..345f69ec3 100644 --- a/docs/en/kotlin-dsl/intro.md +++ b/docs/en/kotlin-dsl/intro.md @@ -1,6 +1,6 @@ --- order: 1 -preferences: ["build-system"] +preferences: ["build-system", "paper-spigot"] authors: - JorelAli - willkroboth @@ -15,22 +15,38 @@ This DSL provides many methods to easily add arguments to your command structure ## Installing the DSL -To install the DSL, you need to add the `commandapi-bukkit-kotlin` dependency into your `pom.xml` or your `build.gradle`, making sure to specify the server flavor you are developing for: +To install the DSL, you need to add the Kotlin DSL dependency into your build script, making sure to specify the server flavor you are developing for: ### Adding the dependency
+
```xml dev.jorel - commandapi-bukkit-kotlin - 10.1.2 + commandapi-kotlin-paper + 11.0.0 ``` +
+
+ +```xml + + + dev.jorel + commandapi-kotlin-spigot + 11.0.0 + + +``` + +
+ Next, you need to add Kotlin to your project. For this, you first need to add the dependency: ```xml @@ -104,21 +120,46 @@ Next, you need to add the dependency:
+
+ ```groovy dependencies { - implementation "dev.jorel:commandapi-bukkit-kotlin:10.1.2" + implementation "dev.jorel:commandapi-kotlin-paper:11.0.0" } ``` +
+
+ +```groovy +dependencies { + implementation "dev.jorel:commandapi-kotlin-spigot:11.0.0" +} +``` + +
+
+ ```kotlin dependencies { - implementation("dev.jorel:commandapi-bukkit-kotlin:10.1.2") + implementation("dev.jorel:commandapi-kotlin-paper:11.0.0") } ``` +
+
+ +```kotlin +dependencies { + implementation("dev.jorel:commandapi-kotlin-spigot:11.0.0") +} +``` + +
+
You also need to add Kotlin to your project. For this, you first need to add the Kotlin plugin: diff --git a/docs/en/kotlin-dsl/usage.md b/docs/en/kotlin-dsl/usage.md index 2dbb1c5aa..345894d03 100644 --- a/docs/en/kotlin-dsl/usage.md +++ b/docs/en/kotlin-dsl/usage.md @@ -25,9 +25,9 @@ We can then use the following command registration: :::tabs key:dsl-usage-page ===CommandTree -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#dslTreeExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#dslTreeExample ===CommandAPICommand -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#dslExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#dslExample ::: @@ -57,7 +57,7 @@ To find out which DSL executor corresponds to "normal" executors, you can refer ## Arguments -The DSL implements almost every argument with a method. You've seen the `playerArgument()` and the `greedyStringArgument()` method in the example at the top of this page. +The DSL implements almost every argument with a method. You've seen the `entitySelectorArgumentOnePlayer()` and the `greedyStringArgument()` method in the example at the top of this page. The way arguments are implemented is pretty straight forward: It's basically the argument class' name, but as a method. So if you wanted to use a `ItemStackArgument` in your command, you would use the `itemStackArgument()` method of the DSL. @@ -91,9 +91,9 @@ To give you a general idea how you could accomplish that, the `sendMessageTo` co :::tabs key:dsl-usage-page ===CommandTree -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#argumentRequirementsTreeExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#argumentRequirementsTreeExample ===CommandAPICommand -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#argumentRequirementsExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#argumentRequirementsExample ::: Notice how you can just add the requirement in a CommandTree by adding it to the argument block where you also define the next arguments and the executor. @@ -108,9 +108,9 @@ This works similar to how argument behaviour is modified in a CommandTree: :::tabs key:dsl-usage-page ===CommandTree -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#commandRequirementsTreeExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#commandRequirementsTreeExample ===CommandAPICommand -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#commandRequirementsExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#commandRequirementsExample ::: ## More examples @@ -130,9 +130,9 @@ To declare an argument as optional you need to set the `optional` value to `true :::tabs key:dsl-usage-page ===CommandTree -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#optionalArgumentsTreeExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#optionalArgumentsTreeExample ===CommandAPICommand -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#optionalArgumentsExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#optionalArgumentsExample ::: :::: @@ -151,9 +151,9 @@ You just have to use the `replaceSuggestions` method this time: :::tabs key:dsl-usage-page ===CommandTree -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#replaceSuggestionsTreeExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#replaceSuggestionsTreeExample ===CommandAPICommand -<<< @/../reference-code/src/main/kotlin/kotlindsl/Usage.kt#replaceSuggestionsExample +<<< @/../reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt#replaceSuggestionsExample ::: :::: \ No newline at end of file diff --git a/docs/en/test/intro.md b/docs/en/test/intro.md index 0a0410afc..61e291cf6 100644 --- a/docs/en/test/intro.md +++ b/docs/en/test/intro.md @@ -6,13 +6,13 @@ authors: # Testing Commands -When developing large projects, it is good practice to add automated tests for your code. This section of the documentation describes how to use the `commandapi-bukkit-test-toolkit` dependency along with [MockBukkit](https://github.com/MockBukkit/MockBukkit) and [JUnit](https://junit.org/junit5/) to test the usage of commands registered with the CommandAPI. +When developing large projects, it is good practice to add automated tests for your code. This section of the documentation describes how to use the `commandapi-spigot-test-toolkit`/`commandapi-paper-test-toolkit` dependency along with [MockBukkit](https://github.com/MockBukkit/MockBukkit) and [JUnit](https://junit.org/junit5/) to test the usage of commands registered with the CommandAPI. For a big-picture view, you can find example projects that include automated tests in the [CommandAPI GitHub repository](https://github.com/CommandAPI/CommandAPI/tree/master/examples). :::danger Developer's Note: -Many methods have not yet been implemented in the test toolkit. Most notably, only [primitive arguments](../create-commands/arguments/types/primitive-arguments), [String arguments](../create-commands/arguments/types/string-arguments), [literal arguments](../create-commands/arguments/types/literal/literal-arguments), and the [`IntegerRangeArgument`](../create-commands/arguments/types/ranged-arguments) are fully implemented. The [`EntitySelectorArgument`, `PlayerArgument`, and `OfflinePlayerArgument`](../create-commands/arguments/types/entities-arguments) should mostly work, though [target selector arguments](https://minecraft.wiki/w/Target_selectors#Target_selector_arguments) (e.g. `@e[type=pig]`) are not yet implemented. +Many methods have not yet been implemented in the test toolkit. Most notably, only [primitive arguments](../create-commands/arguments/types/primitive-arguments), [String arguments](../create-commands/arguments/types/string-arguments), [literal arguments](../create-commands/arguments/types/literal/literal-arguments), and the [`IntegerRangeArgument`](../create-commands/arguments/types/ranged-arguments) are fully implemented. The [`EntitySelectorArgument`, `PlayerProfileArgument`, and `AsyncPlayerProfileArgument`](../create-commands/arguments/types/entities-arguments) should mostly work, though [target selector arguments](https://minecraft.wiki/w/Target_selectors#Target_selector_arguments) (e.g. `@e[type=pig]`) are not yet implemented. If a test ends up calling a method that has not yet been implemented, an `UnimplementedMethodException` will be thrown, causing the test to fail. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord. Pull requests are also always welcome! diff --git a/docs/en/test/load-mock-commandapi.md b/docs/en/test/load-mock-commandapi.md index d2893fda5..d2cb86a9f 100644 --- a/docs/en/test/load-mock-commandapi.md +++ b/docs/en/test/load-mock-commandapi.md @@ -1,5 +1,6 @@ --- order: 3 +preferences: ["paper-spigot"] authors: - willkroboth --- @@ -16,28 +17,63 @@ MockCommandAPIPlugin load() Loads the CommandAPI Plugin in the test environment. Works exactly the same as `MockBukkit.load(MockCommandAPIPlugin.class)`. +
+ +```java +MockCommandAPIPlugin load(Consumer configureSettings) +``` + +Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](../user-setup/config#configuration-settings) using the methods provided by [CommandAPIPaperConfig](../dev-setup/shading#loading). + +:::tip Example - Loading test CommandAPI with settings + +To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPIPaperConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run: + +<<< @/../reference-code/paper/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample + +::: + +
+
+ ```java -MockCommandAPIPlugin load(Consumer configureSettings) +MockCommandAPIPlugin load(Consumer configureSettings) ``` -Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](../user-setup/config#configuration-settings) using the methods provided by [CommandAPIBukkitConfig](../dev-setup/shading#loading). +Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](../user-setup/config#configuration-settings) using the methods provided by [CommandAPISpigotConfig](../dev-setup/shading#loading). :::tip Example - Loading test CommandAPI with settings -To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPIBukkitConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run: +To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPISpigotConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run: -<<< @/../reference-code/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample +<<< @/../reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample ::: +
+ ## Shaded Dependency If your plugin shades the CommandAPI, the CommandAPI will automatically load as usual when you use MockBukkit to load your plugin. Just note that you **must** call `CommandAPI.onDisable()` in your plugin's `onDisable` method in order for the test environment to reset properly after each test. ## Loading a custom CommandAPI platform implementation -By default, the testing environment will load `MockCommandAPIBukkit` as the CommandAPI platform object. This works for basic tests, but many methods in `MockCommandAPIBukkit` are not yet implemented and just throw an `UnimplementedMethodException`. This may cause your tests to fail if your code relies on any of these methods. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord so we can get it solved for everyone. -In the short term, you can also try to avoid an `UnimplementedMethodException` by implementing the required method yourself. Simply create a class that extends `MockCommandAPIBukkit` and override the required method with an appropriate implementation. Before each test where you want to use your custom implementation, make sure to call `CommandAPIVersionHandler#usePlatformImplementation` to let the CommandAPI know what it should load. +
+ +By default, the testing environment will load `MockCommandAPIPaper` and `MockPaperNMS` as the CommandAPI platform object. This works for basic tests, but many methods in `MockPaperNMS` are not yet implemented and just throw an `UnimplementedMethodException`. This may cause your tests to fail if your code relies on any of these methods. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord so we can get it solved for everyone. + +In the short term, you can also try to avoid an `UnimplementedMethodException` by implementing the required method yourself. Simply create a class that extends `MockCommandAPIPaper` or `MockPaperNMS` and override the required method with an appropriate implementation. Before each test where you want to use your custom implementation, make sure to call `CommandAPIVersionHandler#usePlatformImplementation` to let the CommandAPI know what it should load. + +<<< @/../reference-code/paper/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample + +
+
+ +By default, the testing environment will load `MockCommandAPISpigot` as the CommandAPI platform object. This works for basic tests, but many methods in `MockCommandAPISpigot` are not yet implemented and just throw an `UnimplementedMethodException`. This may cause your tests to fail if your code relies on any of these methods. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord so we can get it solved for everyone. + +In the short term, you can also try to avoid an `UnimplementedMethodException` by implementing the required method yourself. Simply create a class that extends `MockCommandAPISpigot` and override the required method with an appropriate implementation. Before each test where you want to use your custom implementation, make sure to call `CommandAPIVersionHandler#usePlatformImplementation` to let the CommandAPI know what it should load. + +<<< @/../reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample -<<< @/../reference-code/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample \ No newline at end of file +
diff --git a/docs/en/test/setup.md b/docs/en/test/setup.md index 5956afa89..cad6433dc 100644 --- a/docs/en/test/setup.md +++ b/docs/en/test/setup.md @@ -1,6 +1,6 @@ --- order: 2 -preferences: ['build-system'] +preferences: ['paper-spigot', 'build-system'] authors: - willkroboth - JorelAli @@ -12,7 +12,106 @@ In the most common simple case, tests can be added directly next to plugin code. ## Dependencies -When you add the dependencies for MockBukkit and `commandapi-bukkit-test-toolkit`, make sure to place them before your main dependencies for the CommandAPI and Spigot/Paper API. This ensures that certain classes that are compatible with the testing environment override the regular classes when running tests. +
+ +When you add the dependencies for MockBukkit and `commandapi-paper-test-toolkit`, make sure to place them before your main dependencies for the CommandAPI and Paper API. This ensures that certain classes that are compatible with the testing environment override the regular classes when running tests. + +
+ +```xml + + + + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.72.8 + test + + + + dev.jorel + commandapi-paper-test-toolkit + 11.0.0 + test + + + + + dev.jorel + commandapi-paper-core + 11.0.0 + provided + + + + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT + provided + + + + + org.junit.jupiter + junit-jupiter-engine + 5.13.3 + test + + +``` + +
+ +
+ +
+ +```groovy +dependencies { + // See https://github.com/MockBukkit/MockBukkit?tab=readme-ov-file#mag-usage for latest version + testImplementation 'org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.72.8' + + testImplementation 'dev.jorel:commandapi-paper-test-toolkit:11.0.0' + + // May also be the shade dependency + compileOnly 'dev.jorel:commandapi-paper-core:11.0.0' + + compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT' + + // See https://junit.org/junit5/ for latest version + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.13.3' +} +``` + +
+
+ +```kotlin +dependencies { + // See https://github.com/MockBukkit/MockBukkit?tab=readme-ov-file#mag-usage for latest version + testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.72.8") + + testImplementation("dev.jorel:commandapi-paper-test-toolkit:11.0.0") + + // May also be the shade dependency + compileOnly("dev.jorel:commandapi-paper-core:11.0.0") + + compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT") + + // See https://junit.org/junit5/ for latest version + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.3") +} +``` + +
+ +
+ +
+ +
+ +When you add the dependencies for MockBukkit and `commandapi-spigot-test-toolkit`, make sure to place them before your main dependencies for the CommandAPI and Spigot API. This ensures that certain classes that are compatible with the testing environment override the regular classes when running tests.
@@ -20,32 +119,31 @@ When you add the dependencies for MockBukkit and `commandapi-bukkit-test-toolkit - com.github.seeseemelk - MockBukkit-v1.21 - 3.128.0 + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.72.8 test dev.jorel - commandapi-bukkit-test-toolkit - 10.1.2 + commandapi-spigot-test-toolkit + 11.0.0 test - + dev.jorel - commandapi-bukkit-core - 10.1.2 + commandapi-spigot-core + 11.0.0 provided - org.spigotmc spigot-api - 1.21.1-R0.1-SNAPSHOT + 1.21.8-R0.1-SNAPSHOT provided @@ -53,7 +151,7 @@ When you add the dependencies for MockBukkit and `commandapi-bukkit-test-toolkit org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.13.3 test @@ -68,18 +166,17 @@ When you add the dependencies for MockBukkit and `commandapi-bukkit-test-toolkit ```groovy dependencies { // See https://github.com/MockBukkit/MockBukkit?tab=readme-ov-file#mag-usage for latest version - testImplementation 'com.github.seeseemelk:MockBukkit-v1.21:3.128.0' + testImplementation 'org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.72.8' - testImplementation 'dev.jorel:commandapi-bukkit-test-toolkit:10.1.2' + testImplementation 'dev.jorel:commandapi-spigot-test-toolkit:11.0.0' - // May be the shade dependency and/or mojang-mapped - compileOnly 'dev.jorel:commandapi-bukkit-core:10.1.2' + // May also be the shade dependency + compileOnly 'dev.jorel:commandapi-spigot-core:11.0.0' - // Can also be paper-api - compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.21.8-R0.1-SNAPSHOT' // See https://junit.org/junit5/ for latest version - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.13.3' } ``` @@ -89,21 +186,22 @@ dependencies { ```kotlin dependencies { // See https://github.com/MockBukkit/MockBukkit?tab=readme-ov-file#mag-usage for latest version - testImplementation("com.github.seeseemelk:MockBukkit-v1.21:3.128.0") + testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.72.8") - testImplementation("dev.jorel:commandapi-bukkit-test-toolkit:10.1.2") + testImplementation("dev.jorel:commandapi-spigot-test-toolkit:11.0.0") - // May be the shade dependency and/or mojang-mapped - compileOnly("dev.jorel:commandapi-bukkit-core:10.1.2") + // May also be the shade dependency + compileOnly("dev.jorel:commandapi-spigot-core:11.0.0") - // Can also be paper-api - compileOnly("org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21.8-R0.1-SNAPSHOT") // See https://junit.org/junit5/ for latest version - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.3") } ```
+
+
\ No newline at end of file diff --git a/docs/en/test/utils.md b/docs/en/test/utils.md index 519b29654..08a94ebe0 100644 --- a/docs/en/test/utils.md +++ b/docs/en/test/utils.md @@ -77,7 +77,7 @@ void assertCommandFailsWithArguments(CommandSender sender, String command, Strin If you expect the command to succeed, use `assertCommandSucceedsWithArguments`. If you expect the command's executor to throw a [`WrapperCommandSyntaxException`](../create-commands/executors/handle-failures#handle-command-failures), use `assertCommandFailsWithArguments`. You can give these methods either an array or a Map holding all arguments you expect to be present for the command. -Note that if the command input cannot be parsed, the command will fail, but a CommandAPI executor will never be run. In this case, a CommandAPI executor will have never been run, so `assertCommandFailsWithArguments` will not have any arguments to inspect, and the test will fail. You can only successfully use `assertCommandFails` in this situation. +Note that if the command input cannot be parsed, the command will fail, but a CommandAPI executor will never be run. In this case, the CommandAPI won't parse arguments, so `assertCommandFailsWithArguments` will not have any arguments to inspect, and the test will fail. You can only successfully use `assertCommandFails` in this situation. ## Verifying suggestions diff --git a/docs/en/tips/predicate-tips.md b/docs/en/tips/predicate-tips.md index 5ab097028..0d41ed855 100644 --- a/docs/en/tips/predicate-tips.md +++ b/docs/en/tips/predicate-tips.md @@ -12,18 +12,18 @@ In our [example for creating a party system](../create-commands/requirements#exa :::tabs ===Java -<<< @/../reference-code/src/main/java/tips/PredicateTips.java#exampleStep1 +<<< @/../reference-code/bukkit/src/main/java/tips/PredicateTips.java#exampleStep1 ===Kotlin -<<< @/../reference-code/src/main/kotlin/tips/PredicateTips.kt#exampleStep1 +<<< @/../reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt#exampleStep1 ::: And for our party teleportation command, we had the following code: :::tabs ===Java -<<< @/../reference-code/src/main/java/tips/PredicateTips.java#exampleStep2 +<<< @/../reference-code/bukkit/src/main/java/tips/PredicateTips.java#exampleStep2 ===Kotlin -<<< @/../reference-code/src/main/kotlin/tips/PredicateTips.kt#exampleStep2 +<<< @/../reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt#exampleStep2 ::: @@ -31,9 +31,9 @@ We can simplify this code by declaring the predicate: :::tabs ===Java -<<< @/../reference-code/src/main/java/tips/PredicateTips.java#exampleStep3 +<<< @/../reference-code/bukkit/src/main/java/tips/PredicateTips.java#exampleStep3 ===Kotlin -<<< @/../reference-code/src/main/kotlin/tips/PredicateTips.kt#exampleStep3 +<<< @/../reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt#exampleStep3 ::: @@ -41,9 +41,9 @@ Now, we can use the predicate `testIfPlayerHasParty` in our code for creating a :::tabs ===Java -<<< @/../reference-code/src/main/java/tips/PredicateTips.java#exampleStep4 +<<< @/../reference-code/bukkit/src/main/java/tips/PredicateTips.java#exampleStep4 ===Kotlin -<<< @/../reference-code/src/main/kotlin/tips/PredicateTips.kt#exampleStep4 +<<< @/../reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt#exampleStep4 ::: @@ -51,7 +51,7 @@ And we can use it again for our code for teleporting to party members: :::tabs ===Java -<<< @/../reference-code/src/main/java/tips/PredicateTips.java#exampleStep5 +<<< @/../reference-code/bukkit/src/main/java/tips/PredicateTips.java#exampleStep5 ===Kotlin -<<< @/../reference-code/src/main/kotlin/tips/PredicateTips.kt#exampleStep5 +<<< @/../reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt#exampleStep5 ::: diff --git a/docs/en/upgrading-parts/10.1.2-to-11.0.0.md b/docs/en/upgrading-parts/10.1.2-to-11.0.0.md new file mode 100644 index 000000000..16b73c763 --- /dev/null +++ b/docs/en/upgrading-parts/10.1.2-to-11.0.0.md @@ -0,0 +1,65 @@ +### CommandAPI restructure + +#### General module changes + +For 11.0.0, the `commandapi-bukkit-xxx` modules have mostly been removed in favour of new platform specific modules that have been made for Paper or Spigot respectively: + +- `commandapi-paper-xxx` +- `commandapi-spigot-xxx` + +In order to update please replace your `commandapi-bukkit-xxx` dependency with either `commandapi-paper-xxx` or `commandapi-spigot-xxx`. + +More dependency-related changes have taken place, here they all are listed: + +```diff +commandapi-bukkit-xxx // [!code --] +commandapi-paper-xxx // [!code ++] +commandapi-spigot-xxx // [!code ++] + +commandapi-core-kotlin // [!code --] +commandapi-kotlin-core // [!code ++] + +commandapi-bukkit-kotlin // [!code --] +commandapi-kotlin-paper // [!code ++] +commandapi-kotlin-spigot // [!code ++] + +commandapi-bukkit-test-toolkit // [!code --] +commandapi-paper-test-toolkit // [!code --] +commandapi-spigot-test-toolkit // [!code --] +``` + +:::danger **Developer's Note:** + +The fact that Paper is a fork of Spigot does not mean that the Spigot modules work on Paper. Paper has, especially in newer versions, made changes to internal systems the CommandAPI +uses. There are no guarantees that the Spigot modules will work on Paper in any kind or form. + +Similarly, if you try to use the Paper modules on Spigot you will face registration issues and potential `NoClassDefFoundError`s, depending on the server version you use. +There again is no guarantee for any kind of compatibility. + +::: + +#### Code changes + +The `CommandAPIBukkitConfig` class has been converted into an abstract class and is no longer used to construct a config instance. Instead, use the new `CommandAPIPaperConfig` or `CommandAPISpigotConfig` classes, depending on the module you use. If you were using `CommandAPIVersionHandler#usePlatformImplementation` from the test toolkit, `MockCommandAPIBukkit` has been changed to `MockCommandAPIPaper` or `MockCommandAPISpigot`. See the new documentation for [that method](/test/load-mock-commandapi#loading-a-custom-command-api-platform-implementation) for details. + +Further changes have been made to arguments that work with components. The classes `AdventureChatArgument`, `AdventureChatComponentArgument` and `AdventureChatColorArgument` have been +removed. Instead, the `ChatArgument`, `ChatComponentArgument` and `ChatColorArgument` have been implemented platform specific and return different types on Paper and Spigot. +On Paper, Adventure components are used while Spigot uses BungeeCord components. + +**More argument changes have been made:** + +- The `FloatRangeArgument` has been renamed to `DoubleRangeArgument` and now returns a `DoubleRange` object +- The `PlayerArgument` and `OfflinePlayerArgument` have been replaced by the `PlayerProfileArgument` which returns a `List`. The `PlayerProfile` class changes depending on if you are on Paper or on Spigot. Use the `EntitySelectorArgument.OnePlayer` if you want a `Player` object. +- The `AsyncOfflinePlayerArgument` has been replaced by the `AsyncPlayerProfileArgument` +- The `ChatArgument`, `ChatComponentArgument` and `ChatColorArgument` do no longer have any `Adventure` prefixes and return different types depending on the platform. +- The `ChatArgument` returns a `SignedMessage` object on Paper +- The `BlockStateArgument` now returns a `BlockState` object instead of a `BlockData` object + +#### Config changes + +The `use-latest-nms-version` and `be-lenient-for-minor-versions` config options have been removed and have been replaced by the new `fallback-to-latest-nms` config option. +This config options combines the functionality of the former config options by first trying to load the correct version and if it can't find a matching implementation for the current version, +it, if set to `true`, will load the latest implementation. +On Paper it is set to `true` by default and on Spigot it is set to `false`. + +Furthermore, any config options relating to reloading datapacks have been removed on Paper as they are not needed anymore. \ No newline at end of file diff --git a/docs/en/user-setup/config.md b/docs/en/user-setup/config.md index 69fb3c670..eaaf42d1c 100644 --- a/docs/en/user-setup/config.md +++ b/docs/en/user-setup/config.md @@ -1,5 +1,6 @@ --- order: 2 +preferences: ["paper-spigot"] authors: - DerEchtePilz - JorelAli @@ -16,6 +17,8 @@ The default `config.yml` is shown below: ::: details **config.yml** +
+ ```yaml # Verbose outputs (default: false) # If "true", outputs command registration and unregistration logs in the console @@ -42,28 +45,75 @@ messages: # setting this to "false" will improve command registration performance. create-dispatcher-json: false -# Use latest version (default: false) -# If "true", the CommandAPI will use the latest available NMS implementation -# when the CommandAPI is used. This avoids all checks to see if the latest NMS -# implementation is actually compatible with the current Minecraft version. -use-latest-nms-version: false +# Fallback to latest version (default: true) +# If "true", the CommandAPI will fall back to the latest available NMS +# implementation when the CommandAPI is used and no implementation for the +# current Minecraft version was found. +fallback-to-latest-nms: true -# Be lenient with version checks when loading for new minor Minecraft versions (default: false) -# If "true", the CommandAPI loads NMS implementations for potentially unsupported Minecraft versions. -# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing -# but will not allow an update from 1.21.2 to 1.22. -# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. -be-lenient-for-minor-versions: false +# Skips the initial datapack reload when the server loads (default: true) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: true # Hook into Paper's ServerResourcesReloadedEvent (default: false) -# If "true", and the CommandAPI detects it is running on a Paper server, it will -# hook into Paper's ServerResourcesReloadedEvent to detect when /minecraft:reload is run. -# This allows the CommandAPI to automatically call its custom datapack-reloading +# If "true", the CommandAPI will hook into Paper's ServerResourcesReloadedEvent to detect when +# /minecraft:reload is run. This allows the CommandAPI to automatically call its custom datapack-reloading # function which allows CommandAPI commands to be used in datapacks. -# If you set this to false, CommandAPI commands may not work inside datapacks after -# reloading datapacks. hook-paper-reload: false +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] +``` + +
+
+ +```yaml +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: This command has no implementations for %s + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Fallback to latest version (default: false) +# If "true", the CommandAPI will fall back to the latest available NMS +# implementation when the CommandAPI is used and no implementation for the +# current Minecraft version was found. +fallback-to-latest-nms: false + # Skips the initial datapack reload when the server loads (default: true) # If "true", the CommandAPI will not reload datapacks when the server has finished # loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" @@ -86,6 +136,7 @@ other-commands-to-convert: [] skip-sender-proxy: [] ``` +
::: ## Configuration settings @@ -157,94 +208,103 @@ create-dispatcher-json: false create-dispatcher-json: true ``` -### `use-latest-nms-version` +### `fallback-to-latest-nms` -Controls whether the CommandAPI should use the latest NMS implementation for command registration and execution. +Controls whether the CommandAPI should use the latest NMS implementation for command registration and execution if no matching CommandAPI implementation for the version used is found. This setting can be used to run the CommandAPI on Minecraft versions higher than it can support. For example, if the CommandAPI supports Minecraft 1.18 and Minecraft 1.18.1 comes out, you can use this to enable support for 1.18.1 before an official CommandAPI release comes out that supports 1.18.1. -:::danger +
-This feature is very experimental and should only be used if you know what you’re doing. In almost every case, it is better to wait for an official CommandAPI release that supports the latest version of Minecraft. Using `use-latest-nms-version` is _not_ guaranteed to work and can cause unexpected side effects! +:::warning + +Using `fallback-to-latest-nms` is _not_ guaranteed to work and can cause unexpected side effects! However, since we expect very few major breaking changes, we decided to set this value to `true` by default. ::: **Default value** ```yaml -use-latest-nms-version: false +fallback-to-latest-nms: true ``` **Example value** ```yaml -use-latest-nms-version: true +fallback-to-latest-nms: false ``` -### `be-lenient-for-minor-versions` - -Controls whether the CommandAPI should be more lenient when updating to a new Minecraft version. - -Similar to the [`use-latest-nms-version`](#use-latest-nms-version) setting, this can allow the CommandAPI to run on a version higher than it officially supports. As an example, this setting can allow updating to 1.21.2 from 1.21.1 but doesn't allow updating to 1.22 from 1.21.2. +
+
:::danger -Take the warning from the [`use-latest-nms-version`](#use-latest-nms-version) and apply it here too. This is _not_ guaranteed to work either and also may cause unexpected side effects. +This feature is very experimental and should only be used if you know what you’re doing. In almost every case, it is better to wait for an official CommandAPI release that supports the latest version of Minecraft. Using `fallback-to-latest-nms` is _not_ guaranteed to work and can cause unexpected side effects! ::: **Default value** ```yaml -be-lenient-for-minor-versions: false +fallback-to-latest-nms: false ``` **Example value** ```yaml -be-lenient-for-minor-versions: true +fallback-to-latest-nms: true ``` -### `hook-paper-reload` +
-Controls whether the CommandAPI hooks into the Paper-exclusive `ServerResourcesReloadedEvent` when available. +### `skip-initial-datapack-reload` -When the CommandAPI detects it is running on a Paper-based server, this config option controls if the CommandAPI hooks into the `ServerResourcesReloadedEvent`, which triggers when `/minecraft:reload` is run. During this event, the CommandAPI runs a custom datapack reloading sequence that helps commands registered with the CommandAPI work within datapacks. See [Reloading datapacks](../internal/internal#reloading-datapacks) for more information on this process. +Controls whether the CommandAPI should perform its initial datapack reload when the server has finished loading. -By default, this value is set to `false` and the CommandAPI will not hook into the `ServerResourcesReloadedEvent`. If you want, you can set this to `true`, and the CommandAPI will hook into this event. +If set to `false`, the CommandAPI reloads all datapacks in a similar fashion to `/minecraft:reload` in order to propagate CommandAPI commands into datapack functions and tags. This operation may cause a slight delay to server startup and is not necessary if you aren’t using datapacks or functions that use CommandAPI commands. + +
+ +Note that datapacks will still be reloaded if performed manually when `hook-paper-reload` is set to `true` and you run `/minecraft:reload`. + +
**Default value** ```yaml -hook-paper-reload: false +skip-initial-datapack-reload: true ``` **Example value** ```yaml -hook-paper-reload: true +skip-initial-datapack-reload: false ``` -### `skip-initial-datapack-reload` +
-Controls whether the CommandAPI should perform its initial datapack reload when the server has finished loading. +### `hook-paper-reload` -If set to `false`, the CommandAPI reloads all datapacks in a similar fashion to `/minecraft:reload` in order to propagate CommandAPI commands into datapack functions and tags. This operation may cause a slight delay to server startup and is not necessary if you aren’t using datapacks or functions that use CommandAPI commands. +Controls whether the CommandAPI hooks into the Paper-exclusive `ServerResourcesReloadedEvent` when available. -Note that datapacks will still be reloaded if performed manually when `hook-paper-reload` is set to `true` and you run `/minecraft:reload`. +When the CommandAPI detects it is running on a Paper-based server, this config option controls if the CommandAPI hooks into the `ServerResourcesReloadedEvent`, which triggers when `/minecraft:reload` is run. During this event, the CommandAPI runs a custom datapack reloading sequence that helps commands registered with the CommandAPI work within datapacks. See [Reloading datapacks](../internal/internal.md#reloading-datapacks) for more information on this process. + +By default, this value is set to `false` and the CommandAPI will not hook into the `ServerResourcesReloadedEvent`. If you want, you can set this to `true`, and the CommandAPI will hook into this event. **Default value** ```yaml -skip-initial-datapack-reload: true +hook-paper-reload: false ``` **Example value** ```yaml -skip-initial-datapack-reload: false +hook-paper-reload: true ``` +
+ ### `plugins-to-convert` Controls the list of plugins to process for command conversion. See [Command conversion](command-conversion/conversion) for more information. diff --git a/docs/en/utils/conversion.md b/docs/en/utils/conversion.md index 4cebdbe20..331057b70 100644 --- a/docs/en/utils/conversion.md +++ b/docs/en/utils/conversion.md @@ -45,9 +45,9 @@ As you can see, it declares three commands: `/gmc`, `/gms` and `/i`. We can now :::tabs ===Java -<<< @/../reference-code/src/main/java/utils/Conversion.java#simpleConvertExample +<<< @/../reference-code/bukkit/src/main/java/utils/Conversion.java#simpleConvertExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/utils/Conversion.kt#simpleConvertExample +<<< @/../reference-code/bukkit/src/main/kotlin/utils/Conversion.kt#simpleConvertExample ::: When this is run, the commands `/gmc`, `/gm1`, `/gms` and `/i` will all be registered by the CommandAPI. @@ -92,9 +92,9 @@ With the EssentialsX plugin, the `` value can only take numbers between 0 :::tabs ===Java -<<< @/../reference-code/src/main/java/utils/Conversion.java#convertSpeedCommandExample +<<< @/../reference-code/bukkit/src/main/java/utils/Conversion.java#convertSpeedCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/utils/Conversion.kt#convertSpeedCommandExample +<<< @/../reference-code/bukkit/src/main/kotlin/utils/Conversion.kt#convertSpeedCommandExample ::: ![An image showing /execute run for EssentialsX's /speed command](/images/speed.gif) diff --git a/docs/en/velocity/intro.md b/docs/en/velocity/intro.md index dbe9da299..335faf742 100644 --- a/docs/en/velocity/intro.md +++ b/docs/en/velocity/intro.md @@ -26,7 +26,7 @@ Add the dependency to your list of dependencies in your build script: dev.jorel commandapi-velocity-shade - 10.1.2 + 11.0.0 ``` @@ -38,7 +38,7 @@ Add the dependency to your list of dependencies in your build script: ```groovy dependencies { - implementation "dev.jorel:commandapi-velocity-shade:10.1.2" + implementation "dev.jorel:commandapi-velocity-shade:11.0.0" } ``` @@ -47,7 +47,7 @@ dependencies { ```kotlin dependencies { - implementation("dev.jorel:commandapi-velocity-shade:10.1.2") + implementation("dev.jorel:commandapi-velocity-shade:11.0.0") } ``` @@ -60,12 +60,12 @@ dependencies { The CommandAPI requires two steps: loading and enabling. We will perform these steps in Velocity's loading stages, construction and initialization. These two stages are explained in [their documentation](https://docs.papermc.io/velocity/dev/api-basics#a-word-of-caution). We will perform the CommandAPI's loading step in the construction phase first: -<<< @/../reference-code/src/main/java/velocity/Intro.java#loadCommandAPIExample +<<< @/../reference-code/velocity/src/main/java/velocity/Intro.java#loadCommandAPIExample Next, we want to utilise Velocity's `ProxyInitializeEvent` to perform the CommandAPI's enabling step: -<<< @/../reference-code/src/main/java/velocity/Intro.java#enableCommandAPIExample +<<< @/../reference-code/velocity/src/main/java/velocity/Intro.java#enableCommandAPIExample ## Current limitations @@ -99,9 +99,9 @@ To accomplish that, we register the command like this: :::tabs ===Java -<<< @/../reference-code/src/main/java/velocity/Intro.java#registerCommandExample +<<< @/../reference-code/velocity/src/main/java/velocity/Intro.java#registerCommandExample ===Kotlin -<<< @/../reference-code/src/main/kotlin/velocity/Intro.kt#registerCommandExample +<<< @/../reference-code/velocity/src/main/kotlin/velocity/Intro.kt#registerCommandExample ::: :::: diff --git a/docs/public/images/arguments/doublerange.png b/docs/public/images/arguments/doublerange.png new file mode 100644 index 000000000..64b86d100 Binary files /dev/null and b/docs/public/images/arguments/doublerange.png differ diff --git a/docs/public/images/arguments/floatrange.png b/docs/public/images/arguments/floatrange.png deleted file mode 100644 index b15ebbc92..000000000 Binary files a/docs/public/images/arguments/floatrange.png and /dev/null differ diff --git a/docs/public/versions.yml b/docs/public/versions.yml index f7b2c5f34..74dc92c89 100644 --- a/docs/public/versions.yml +++ b/docs/public/versions.yml @@ -1,6 +1,6 @@ versions: + - 11.0.0 - 10.1.2 - - 11.0.0-SNAPSHOT - 9.7.0 - 9.6.1 - 9.4.2 diff --git a/package.json b/package.json index 57699fe3c..f2d25371f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "@types/markdown-it": "^14.1.2", "@types/markdown-it-container": "^2.0.10", "@types/node": "^22.10.1", - "fs": "^0.0.1-security", "markdown-it": "^14.1.0", "markdown-it-container": "^4.0.0", "markdown-it-mathjax3": "^4.3.2", @@ -36,5 +35,6 @@ "vitepress-i18n": "^1.3.0", "vue": "^3.5.13", "yaml": "^2.6.1" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/reference-code/build.gradle.kts b/reference-code/build.gradle.kts deleted file mode 100644 index 46d21eebc..000000000 --- a/reference-code/build.gradle.kts +++ /dev/null @@ -1,69 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -/* - * This file was generated by the Gradle 'init' task. - */ - -plugins { - `java-library` - kotlin("jvm") version "2.1.0" -} - -repositories { - mavenLocal() - maven { - url = uri("https://libraries.minecraft.net") - } - - maven { - url = uri("https://repo.papermc.io/repository/maven-public/") - } - - maven { - url = uri("https://repo.codemc.org/repository/maven-public/") - } - - maven { - url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") - } - - maven { - url = uri("https://repo.maven.apache.org/maven2/") - } -} - -dependencies { - api(libs.net.kyori.adventure.platform.bukkit) - api(libs.dev.jorel.commandapi.bukkit.core) - api(libs.dev.jorel.commandapi.bukkit.kotlin) - api(libs.dev.jorel.commandapi.annotations) - compileOnly(libs.dev.jorel.commandapi.velocity.shade) - api(libs.de.tr7zw.item.nbt.api) - api(libs.org.jetbrains.kotlin.kotlin.stdlib) - testImplementation(libs.org.junit.jupiter.junit.jupiter) - testImplementation(libs.dev.jorel.commandapi.bukkit.test.toolkit) - testImplementation(libs.com.github.seeseemelk.mockbukkit.v1.v21) - compileOnly(libs.com.mojang.brigadier) - compileOnly(libs.com.mojang.authlib) - compileOnly(libs.io.papermc.paper.paper.api) - compileOnly(libs.com.velocitypowered.velocity.api) -} - -group = "dev.jorel.commandapi" -version = "1.0-SNAPSHOT" -description = "reference-code" -java.sourceCompatibility = JavaVersion.VERSION_21 -java.targetCompatibility = JavaVersion.VERSION_21 - -tasks.withType { - options.encoding = "UTF-8" -} - -tasks.withType { - options.encoding = "UTF-8" -} - -tasks.withType { - compilerOptions.jvmTarget = JvmTarget.JVM_21 -} diff --git a/reference-code/buildSrc/build.gradle.kts b/reference-code/buildSrc/build.gradle.kts new file mode 100644 index 000000000..9df5a3849 --- /dev/null +++ b/reference-code/buildSrc/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + gradlePluginPortal() +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") +} \ No newline at end of file diff --git a/reference-code/buildSrc/settings.gradle.kts b/reference-code/buildSrc/settings.gradle.kts new file mode 100644 index 000000000..3f87d39f0 --- /dev/null +++ b/reference-code/buildSrc/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "buildSrc" \ No newline at end of file diff --git a/reference-code/buildSrc/src/main/kotlin/common.gradle.kts b/reference-code/buildSrc/src/main/kotlin/common.gradle.kts new file mode 100644 index 000000000..81f313885 --- /dev/null +++ b/reference-code/buildSrc/src/main/kotlin/common.gradle.kts @@ -0,0 +1,63 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + `java-library` + kotlin("jvm") +} + +java.sourceCompatibility = JavaVersion.VERSION_21 +java.targetCompatibility = JavaVersion.VERSION_21 + +val commandApiVersion: String by project +val brigadierVersion: String by project +val authlibVersion: String by project +val nbtApiVersion: String by project +val kotlinVersion: String by project +val junitVersion: String by project +val mockBukkitVersion: String by project + +repositories { + mavenLocal() + maven { + url = uri("https://libraries.minecraft.net") + } + + maven { + url = uri("https://repo.papermc.io/repository/maven-public/") + } + + maven { + url = uri("https://repo.codemc.org/repository/maven-public/") + } + + maven { + url = uri("https://central.sonatype.com/repository/maven-snapshots/") + } + + maven { + url = uri("https://repo.maven.apache.org/maven2/") + } +} + +dependencies { + compileOnly("dev.jorel:commandapi-annotations:$commandApiVersion") + compileOnly("de.tr7zw:item-nbt-api:$nbtApiVersion") + compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") + testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion") + testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:$mockBukkitVersion") + compileOnly("com.mojang:brigadier:$brigadierVersion") + compileOnly("com.mojang:authlib:$authlibVersion") +} + +tasks.withType { + options.encoding = "UTF-8" +} + +tasks.withType { + options.encoding = "UTF-8" +} + +tasks.withType { + compilerOptions.jvmTarget = JvmTarget.JVM_21 +} \ No newline at end of file diff --git a/reference-code/bukkit/build.gradle.kts b/reference-code/bukkit/build.gradle.kts new file mode 100644 index 000000000..de37e6a9b --- /dev/null +++ b/reference-code/bukkit/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + common +} + +group = "dev.jorel.commandapi" +version = "1.0-SNAPSHOT" +description = "reference-code-bukkit" + +val commandApiVersion: String by project +val paperVersion: String by project + +dependencies { + compileOnly("dev.jorel:commandapi-bukkit-core:$commandApiVersion") + compileOnly("dev.jorel:commandapi-kotlin-bukkit:$commandApiVersion") + compileOnly("io.papermc.paper:paper-api:$paperVersion") +} \ No newline at end of file diff --git a/reference-code/src/main/java/annotations/DefaultMethodExample.java b/reference-code/bukkit/src/main/java/annotations/DefaultMethodExample.java similarity index 100% rename from reference-code/src/main/java/annotations/DefaultMethodExample.java rename to reference-code/bukkit/src/main/java/annotations/DefaultMethodExample.java diff --git a/reference-code/src/main/java/annotations/Intro.java b/reference-code/bukkit/src/main/java/annotations/Intro.java similarity index 100% rename from reference-code/src/main/java/annotations/Intro.java rename to reference-code/bukkit/src/main/java/annotations/Intro.java diff --git a/reference-code/src/main/java/annotations/ParameterExample.java b/reference-code/bukkit/src/main/java/annotations/ParameterExample.java similarity index 100% rename from reference-code/src/main/java/annotations/ParameterExample.java rename to reference-code/bukkit/src/main/java/annotations/ParameterExample.java diff --git a/reference-code/src/main/java/annotations/PermissionMethodExample.java b/reference-code/bukkit/src/main/java/annotations/PermissionMethodExample.java similarity index 100% rename from reference-code/src/main/java/annotations/PermissionMethodExample.java rename to reference-code/bukkit/src/main/java/annotations/PermissionMethodExample.java diff --git a/reference-code/src/main/java/annotations/Registration.java b/reference-code/bukkit/src/main/java/annotations/Registration.java similarity index 100% rename from reference-code/src/main/java/annotations/Registration.java rename to reference-code/bukkit/src/main/java/annotations/Registration.java diff --git a/reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java b/reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java new file mode 100644 index 000000000..62c7dff6d --- /dev/null +++ b/reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java @@ -0,0 +1,26 @@ +package annotations; + +import dev.jorel.commandapi.annotations.Permission; +import dev.jorel.commandapi.annotations.Subcommand; +import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; +import dev.jorel.commandapi.annotations.arguments.AStringArgument; +import org.bukkit.entity.Player; + +import static annotations.WarpCommand.warps; + +class SubcommandMethodExample { + // #region subcommandMethodExample + @Subcommand("create") + @Permission("warps.create") + public static void createWarp(Player player, @AStringArgument String warpName) { + warps.put(warpName, player.getLocation()); + } + // #endregion subcommandMethodExample + + // #region subcommandAliasesMethodExample + @Subcommand({"teleport", "tp"}) + public static void teleport(Player player, @AEntitySelectorArgument.OnePlayer Player target) { + player.teleport(target); + } + // #endregion subcommandAliasesMethodExample +} diff --git a/reference-code/src/main/java/annotations/WarpCommand.java b/reference-code/bukkit/src/main/java/annotations/WarpCommand.java similarity index 100% rename from reference-code/src/main/java/annotations/WarpCommand.java rename to reference-code/bukkit/src/main/java/annotations/WarpCommand.java diff --git a/reference-code/src/main/java/annotations/aliasClassExample/TeleportCommand.java b/reference-code/bukkit/src/main/java/annotations/aliasClassExample/TeleportCommand.java similarity index 100% rename from reference-code/src/main/java/annotations/aliasClassExample/TeleportCommand.java rename to reference-code/bukkit/src/main/java/annotations/aliasClassExample/TeleportCommand.java diff --git a/reference-code/src/main/java/annotations/helpClassExample/TeleportCommand.java b/reference-code/bukkit/src/main/java/annotations/helpClassExample/TeleportCommand.java similarity index 100% rename from reference-code/src/main/java/annotations/helpClassExample/TeleportCommand.java rename to reference-code/bukkit/src/main/java/annotations/helpClassExample/TeleportCommand.java diff --git a/reference-code/src/main/java/annotations/needsOpClassExample/TeleportCommand.java b/reference-code/bukkit/src/main/java/annotations/needsOpClassExample/TeleportCommand.java similarity index 100% rename from reference-code/src/main/java/annotations/needsOpClassExample/TeleportCommand.java rename to reference-code/bukkit/src/main/java/annotations/needsOpClassExample/TeleportCommand.java diff --git a/reference-code/src/main/java/annotations/permissionClassExample/TeleportCommand.java b/reference-code/bukkit/src/main/java/annotations/permissionClassExample/TeleportCommand.java similarity index 100% rename from reference-code/src/main/java/annotations/permissionClassExample/TeleportCommand.java rename to reference-code/bukkit/src/main/java/annotations/permissionClassExample/TeleportCommand.java diff --git a/reference-code/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java b/reference-code/bukkit/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java similarity index 100% rename from reference-code/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java rename to reference-code/bukkit/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java diff --git a/reference-code/src/main/java/createcommands/Aliases.java b/reference-code/bukkit/src/main/java/createcommands/Aliases.java similarity index 100% rename from reference-code/src/main/java/createcommands/Aliases.java rename to reference-code/bukkit/src/main/java/createcommands/Aliases.java diff --git a/reference-code/src/main/java/createcommands/CommandTrees.java b/reference-code/bukkit/src/main/java/createcommands/CommandTrees.java similarity index 97% rename from reference-code/src/main/java/createcommands/CommandTrees.java rename to reference-code/bukkit/src/main/java/createcommands/CommandTrees.java index 9db3b541c..569642c48 100644 --- a/reference-code/src/main/java/createcommands/CommandTrees.java +++ b/reference-code/bukkit/src/main/java/createcommands/CommandTrees.java @@ -3,10 +3,10 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandTree; import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.LiteralArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import org.bukkit.block.Block; @@ -23,7 +23,7 @@ class CommandTrees { .executes((sender, args) -> { sender.sendMessage("Hi!"); }) - .then(new PlayerArgument("target") + .then(new EntitySelectorArgument.OnePlayer("target") .executes((sender, args) -> { Player target = (Player) args.get("target"); target.sendMessage("Hi"); diff --git a/reference-code/src/main/java/createcommands/Help.java b/reference-code/bukkit/src/main/java/createcommands/Help.java similarity index 100% rename from reference-code/src/main/java/createcommands/Help.java rename to reference-code/bukkit/src/main/java/createcommands/Help.java diff --git a/reference-code/src/main/java/createcommands/Permissions.java b/reference-code/bukkit/src/main/java/createcommands/Permissions.java similarity index 91% rename from reference-code/src/main/java/createcommands/Permissions.java rename to reference-code/bukkit/src/main/java/createcommands/Permissions.java index 07afa79e6..5b7f712ba 100644 --- a/reference-code/src/main/java/createcommands/Permissions.java +++ b/reference-code/bukkit/src/main/java/createcommands/Permissions.java @@ -3,8 +3,8 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.LiteralArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import org.bukkit.entity.Player; class Permissions { @@ -43,7 +43,7 @@ class Permissions { // #region argumentPermissionExampleStep2 // Adds the OP permission to the "target" argument. The sender requires OP to execute /kill new CommandAPICommand("kill") - .withArguments(new PlayerArgument("target").withPermission(CommandPermission.OP)) + .withArguments(new EntitySelectorArgument.OnePlayer("target").withPermission(CommandPermission.OP)) .executesPlayer((player, args) -> { ((Player) args.get("target")).setHealth(0); }) @@ -62,7 +62,7 @@ class Permissions { // /economy - requires the permission "economy.other" to execute new CommandAPICommand("economy") .withPermission("economy.other") // The important part of this example - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .executesPlayer((player, args) -> { Player target = (Player) args.get("target"); @@ -75,7 +75,7 @@ class Permissions { new CommandAPICommand("economy") .withPermission("economy.admin.give") // The important part of this example .withArguments(new LiteralArgument("give")) - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new DoubleArgument("amount")) .executesPlayer((player, args) -> { Player target = (Player) args.get("target"); @@ -90,7 +90,7 @@ class Permissions { new CommandAPICommand("economy") .withPermission("economy.admin.reset") // The important part of this example .withArguments(new LiteralArgument("reset")) - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .executesPlayer((player, args) -> { Player target = (Player) args.get("target"); diff --git a/reference-code/src/main/java/createcommands/Registration.java b/reference-code/bukkit/src/main/java/createcommands/Registration.java similarity index 100% rename from reference-code/src/main/java/createcommands/Registration.java rename to reference-code/bukkit/src/main/java/createcommands/Registration.java diff --git a/reference-code/src/main/java/createcommands/Requirements.java b/reference-code/bukkit/src/main/java/createcommands/Requirements.java similarity index 91% rename from reference-code/src/main/java/createcommands/Requirements.java rename to reference-code/bukkit/src/main/java/createcommands/Requirements.java index 74efc23a6..f47b8f527 100644 --- a/reference-code/src/main/java/createcommands/Requirements.java +++ b/reference-code/bukkit/src/main/java/createcommands/Requirements.java @@ -3,9 +3,9 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.LiteralArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; -import dev.jorel.commandapi.arguments.SafeSuggestions; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -76,11 +76,11 @@ class Requirements { .withRequirement(sender -> partyMembers.containsKey(((Player) sender).getUniqueId())) ); - arguments.add(new PlayerArgument("player") - .replaceSafeSuggestions(SafeSuggestions.suggest(info -> { + arguments.add(new EntitySelectorArgument.OnePlayer("player") + .replaceSuggestions(ArgumentSuggestions.strings(info -> { // Store the list of party members to teleport to - List playersToTeleportTo = new ArrayList<>(); + List playersToTeleportTo = new ArrayList<>(); String partyName = partyMembers.get(((Player) info.sender()).getUniqueId()); // Find the party members @@ -95,13 +95,13 @@ class Requirements { Player target = Bukkit.getPlayer(entry.getKey()); if (target.isOnline()) { // Add them if they are online - playersToTeleportTo.add(target); + playersToTeleportTo.add(target.getName()); } } } } - return playersToTeleportTo.toArray(new Player[0]); + return playersToTeleportTo.toArray(new String[0]); }))); // #endregion partySystemExampleStep4 diff --git a/reference-code/src/main/java/createcommands/Subcommands.java b/reference-code/bukkit/src/main/java/createcommands/Subcommands.java similarity index 100% rename from reference-code/src/main/java/createcommands/Subcommands.java rename to reference-code/bukkit/src/main/java/createcommands/Subcommands.java diff --git a/reference-code/src/main/java/createcommands/arguments/Arguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/Arguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/Arguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/Arguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/CommandArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java similarity index 87% rename from reference-code/src/main/java/createcommands/arguments/CommandArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java index 6eccdf40b..13ab0d9e5 100644 --- a/reference-code/src/main/java/createcommands/arguments/CommandArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/CommandArguments.java @@ -4,7 +4,6 @@ import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.entity.Player; @@ -14,8 +13,8 @@ class CommandArguments { new CommandAPICommand("mycommand") .withArguments(new StringArgument("name")) .withArguments(new IntegerArgument("amount")) - .withOptionalArguments(new PlayerArgument("player")) - .withOptionalArguments(new PlayerArgument("target")) + .withOptionalArguments(new EntitySelectorArgument.OnePlayer("player")) + .withOptionalArguments(new EntitySelectorArgument.OnePlayer("target")) .withOptionalArguments(new GreedyStringArgument("message")) .executesPlayer((player, args) -> { String name = (String) args.get(0); // Access arguments by index @@ -40,7 +39,7 @@ class CommandArguments { // #region getUncheckedExample new CommandAPICommand("mycommand") - .withArguments(new PlayerArgument("player")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) .executesPlayer((player, args) -> { Player p = args.getUnchecked("player"); // Do whatever with the player @@ -51,8 +50,8 @@ class CommandArguments { // #region getByArgumentExample StringArgument nameArgument = new StringArgument("name"); IntegerArgument amountArgument = new IntegerArgument("amount"); - PlayerArgument playerArgument = new PlayerArgument("player"); - PlayerArgument targetArgument = new PlayerArgument("target"); + EntitySelectorArgument.OnePlayer playerArgument = new EntitySelectorArgument.OnePlayer("player"); + EntitySelectorArgument.OnePlayer targetArgument = new EntitySelectorArgument.OnePlayer("target"); GreedyStringArgument messageArgument = new GreedyStringArgument("message"); new CommandAPICommand("mycommand") diff --git a/reference-code/src/main/java/createcommands/arguments/ListedArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/ListedArguments.java similarity index 86% rename from reference-code/src/main/java/createcommands/arguments/ListedArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/ListedArguments.java index 489800bcd..1574c5186 100644 --- a/reference-code/src/main/java/createcommands/arguments/ListedArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/ListedArguments.java @@ -1,16 +1,16 @@ package createcommands.arguments; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import org.bukkit.entity.Player; class ListedArguments { static { // #region listedArgumentsExample new CommandAPICommand("mycommand") - .withArguments(new PlayerArgument("player")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) .withArguments(new IntegerArgument("value").setListed(false)) .withArguments(new GreedyStringArgument("message")) .executes((sender, args) -> { diff --git a/reference-code/src/main/java/createcommands/arguments/OptionalArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/OptionalArguments.java similarity index 88% rename from reference-code/src/main/java/createcommands/arguments/OptionalArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/OptionalArguments.java index 331bacb5d..86081b4f4 100644 --- a/reference-code/src/main/java/createcommands/arguments/OptionalArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/OptionalArguments.java @@ -1,8 +1,8 @@ package createcommands.arguments; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -11,7 +11,7 @@ class OptionalArguments { static { // #region simpleOptionalArgumentsExample new CommandAPICommand("sayhi") - .withOptionalArguments(new PlayerArgument("target")) + .withOptionalArguments(new EntitySelectorArgument.OnePlayer("target")) .executesPlayer((player, args) -> { Player target = (Player) args.get("target"); if (target != null) { @@ -25,7 +25,7 @@ class OptionalArguments { // #region getOptionalExample new CommandAPICommand("sayhi") - .withOptionalArguments(new PlayerArgument("target")) + .withOptionalArguments(new EntitySelectorArgument.OnePlayer("target")) .executesPlayer((player, args) -> { Player target = (Player) args.getOptional("target").orElse(player); target.sendMessage("Hi!"); @@ -36,7 +36,7 @@ class OptionalArguments { // #region argumentsAfterOptionalArgumentsExample new CommandAPICommand("rate") .withOptionalArguments(new StringArgument("topic").combineWith(new IntegerArgument("rating", 0, 10))) - .withOptionalArguments(new PlayerArgument("target")) + .withOptionalArguments(new EntitySelectorArgument.OnePlayer("target")) .executes((sender, args) -> { String topic = (String) args.get("topic"); if (topic == null) { diff --git a/reference-code/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java b/reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java diff --git a/reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java b/reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java diff --git a/reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java b/reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java similarity index 94% rename from reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java index 6ca972028..a0ba03258 100644 --- a/reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java @@ -3,9 +3,9 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -59,7 +59,7 @@ public static String[] getFriends(CommandSender sender) { { // #region createFriendCommand List> arguments = new ArrayList<>(); - arguments.add(new PlayerArgument("friend").replaceSuggestions( + arguments.add(new EntitySelectorArgument.OnePlayer("friend").replaceSuggestions( ArgumentSuggestions.strings(info -> Friends.getFriends(info.sender()) )) @@ -82,7 +82,7 @@ public static String[] getFriends(CommandSender sender) { // Replace the suggestions for the PlayerArgument. // info.sender() refers to the command sender that is running this command // info.previousArgs() refers to the Object[] of previously declared arguments (in this case, the IntegerArgument radius) - commandArgs.add(new PlayerArgument("target").replaceSuggestions( + commandArgs.add(new EntitySelectorArgument.OnePlayer("target").replaceSuggestions( ArgumentSuggestions.strings(info -> { // Cast the first argument (radius, which is an IntegerArgument) to get its value diff --git a/reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java b/reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java similarity index 97% rename from reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java index 86228d430..cb11f4e54 100644 --- a/reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/suggestions/Tooltips.java @@ -7,8 +7,8 @@ import dev.jorel.commandapi.StringTooltip; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.LocationArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.SafeSuggestions; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.Location; @@ -34,7 +34,7 @@ class Tooltips { } )) ); - arguments.add(new PlayerArgument("target")); + arguments.add(new EntitySelectorArgument.OnePlayer("target")); // #endregion createArgumentsWithTooltips // #region registerEmoteCommand diff --git a/reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java similarity index 96% rename from reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java index 44ad54dd6..a0b1a208d 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/CommandArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/CommandArguments.java @@ -3,7 +3,7 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.ArgumentSuggestions; import dev.jorel.commandapi.arguments.CommandArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.SuggestionsBranch; import dev.jorel.commandapi.wrappers.CommandResult; import org.bukkit.Bukkit; @@ -14,7 +14,7 @@ class CommandArguments { static { // #region sudoCommandExample new CommandAPICommand("sudo") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new CommandArgument("command")) .executes((sender, args) -> { Player target = (Player) args.get("target"); diff --git a/reference-code/src/main/java/createcommands/arguments/types/ListArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/ListArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/ListArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/ListArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/MapArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/MapArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/MapArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/MapArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/PrimitiveArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/PrimitiveArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/PrimitiveArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/PrimitiveArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/RangedArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/RangedArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/RangedArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/RangedArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/StringsArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/StringsArguments.java similarity index 81% rename from reference-code/src/main/java/createcommands/arguments/types/StringsArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/StringsArguments.java index d3fcbcc76..e4b71719e 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/StringsArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/StringsArguments.java @@ -1,15 +1,15 @@ package createcommands.arguments.types; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import org.bukkit.entity.Player; class StringsArguments { static { // #region greedyStringArgumentsExample new CommandAPICommand("message") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new GreedyStringArgument("message")) .executes((sender, args) -> { ((Player) args.get("target")).sendMessage((String) args.get("message")); diff --git a/reference-code/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/LiteralArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/literal/MultiLiteralArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/MultiLiteralArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/literal/MultiLiteralArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/literal/MultiLiteralArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java similarity index 88% rename from reference-code/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java index 428ed253c..ed6f42db4 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java @@ -2,7 +2,7 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.AdvancementArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import org.bukkit.advancement.Advancement; import org.bukkit.advancement.AdvancementProgress; import org.bukkit.entity.Player; @@ -11,7 +11,7 @@ class AdvancementArguments { static { // #region advancementArgumentsExample new CommandAPICommand("award") - .withArguments(new PlayerArgument("player")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) .withArguments(new AdvancementArgument("advancement")) .executes((sender, args) -> { Player target = (Player) args.get("player"); diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java similarity index 71% rename from reference-code/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java index 4ff17045e..c38958e1b 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java @@ -3,6 +3,7 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.BlockStateArgument; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; class BlockStateArguments { @@ -11,12 +12,12 @@ class BlockStateArguments { new CommandAPICommand("set") .withArguments(new BlockStateArgument("block")) .executesPlayer((player, args) -> { - BlockData blockdata = (BlockData) args.get("block"); + BlockState blockState = (BlockState) args.get("block"); Block targetBlock = player.getTargetBlockExact(256); // Set the block, along with its data - targetBlock.setType(blockdata.getMaterial()); - targetBlock.getState().setBlockData(blockdata); + targetBlock.setType(blockState.getBlockData().getMaterial()); + targetBlock.getState().setBlockData(blockState.getBlockData()); }) .register(); // #endregion blockStateArgumentsExample diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java similarity index 87% rename from reference-code/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java index b0673053f..46b74ec36 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java @@ -1,9 +1,9 @@ package createcommands.arguments.types.misc; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.MathOperationArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.wrappers.MathOperation; import org.bukkit.entity.Player; @@ -11,7 +11,7 @@ class MathOperationArguments { static { // #region mathOperationArgumentsExample new CommandAPICommand("changelevel") - .withArguments(new PlayerArgument("player")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) .withArguments(new MathOperationArgument("operation")) .withArguments(new IntegerArgument("value")) .executes((sender, args) -> { diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/ParticleArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/PotionArguments.java similarity index 91% rename from reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/PotionArguments.java index 82decd3fc..7e1e05d3d 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/PotionArguments.java @@ -1,8 +1,8 @@ package createcommands.arguments.types.misc; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.PotionEffectArgument; import dev.jorel.commandapi.arguments.TimeArgument; import org.bukkit.NamespacedKey; @@ -14,7 +14,7 @@ class PotionArguments { static { // #region potionEffectArgumentsExample new CommandAPICommand("potion") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new PotionEffectArgument("potion")) .withArguments(new TimeArgument("duration")) .withArguments(new IntegerArgument("strength")) @@ -32,7 +32,7 @@ class PotionArguments { // #region potionEffectArgumentsNamespacedKeyExample new CommandAPICommand("potion") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new PotionEffectArgument.NamespacedKey("potion")) .withArguments(new TimeArgument("duration")) .withArguments(new IntegerArgument("strength")) diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java similarity index 89% rename from reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java index 768171e23..a3327d84d 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java +++ b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java @@ -1,7 +1,7 @@ package createcommands.arguments.types.misc; import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.RecipeArgument; import org.bukkit.entity.Player; import org.bukkit.inventory.ComplexRecipe; @@ -20,7 +20,7 @@ class RecipeArguments { // #region getKeyExample new CommandAPICommand("unlockrecipe") - .withArguments(new PlayerArgument("player")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) .withArguments(new RecipeArgument("recipe")) .executes((sender, args) -> { Player target = (Player) args.get("player"); diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/SoundArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/SoundArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/SoundArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/SoundArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/TimeArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/TimeArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/TimeArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/TimeArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/misc/WorldArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/WorldArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/misc/WorldArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/misc/WorldArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/position/LocationArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/position/LocationArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/position/LocationArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/position/LocationArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/position/RotationArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/position/RotationArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/position/RotationArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/position/RotationArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/BlockPredicateArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/predicate/ItemStackPredicateArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/ItemStackPredicateArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/predicate/ItemStackPredicateArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/predicate/ItemStackPredicateArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ObjectiveArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/ScoreboardArguments.java diff --git a/reference-code/src/main/java/createcommands/arguments/types/scoreboard/TeamArguments.java b/reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/TeamArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/scoreboard/TeamArguments.java rename to reference-code/bukkit/src/main/java/createcommands/arguments/types/scoreboard/TeamArguments.java diff --git a/reference-code/src/main/java/createcommands/executors/HandleFailures.java b/reference-code/bukkit/src/main/java/createcommands/executors/HandleFailures.java similarity index 100% rename from reference-code/src/main/java/createcommands/executors/HandleFailures.java rename to reference-code/bukkit/src/main/java/createcommands/executors/HandleFailures.java diff --git a/reference-code/src/main/java/createcommands/executors/NativeSender.java b/reference-code/bukkit/src/main/java/createcommands/executors/NativeSender.java similarity index 100% rename from reference-code/src/main/java/createcommands/executors/NativeSender.java rename to reference-code/bukkit/src/main/java/createcommands/executors/NativeSender.java diff --git a/reference-code/src/main/java/createcommands/executors/NormalExecutors.java b/reference-code/bukkit/src/main/java/createcommands/executors/NormalExecutors.java similarity index 100% rename from reference-code/src/main/java/createcommands/executors/NormalExecutors.java rename to reference-code/bukkit/src/main/java/createcommands/executors/NormalExecutors.java diff --git a/reference-code/src/main/java/createcommands/executors/ProxySender.java b/reference-code/bukkit/src/main/java/createcommands/executors/ProxySender.java similarity index 100% rename from reference-code/src/main/java/createcommands/executors/ProxySender.java rename to reference-code/bukkit/src/main/java/createcommands/executors/ProxySender.java diff --git a/reference-code/src/main/java/createcommands/executors/ResultingExecutors.java b/reference-code/bukkit/src/main/java/createcommands/executors/ResultingExecutors.java similarity index 100% rename from reference-code/src/main/java/createcommands/executors/ResultingExecutors.java rename to reference-code/bukkit/src/main/java/createcommands/executors/ResultingExecutors.java diff --git a/reference-code/src/main/java/createcommands/functionsandtags/FunctionArguments.java b/reference-code/bukkit/src/main/java/createcommands/functionsandtags/FunctionArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/functionsandtags/FunctionArguments.java rename to reference-code/bukkit/src/main/java/createcommands/functionsandtags/FunctionArguments.java diff --git a/reference-code/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java b/reference-code/bukkit/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java similarity index 100% rename from reference-code/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java rename to reference-code/bukkit/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java diff --git a/reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java b/reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java similarity index 100% rename from reference-code/src/main/java/internal/BrigadierPlusCommandAPI.java rename to reference-code/bukkit/src/main/java/internal/BrigadierPlusCommandAPI.java diff --git a/reference-code/src/main/java/internal/BrigadierSuggestions.java b/reference-code/bukkit/src/main/java/internal/BrigadierSuggestions.java similarity index 100% rename from reference-code/src/main/java/internal/BrigadierSuggestions.java rename to reference-code/bukkit/src/main/java/internal/BrigadierSuggestions.java diff --git a/reference-code/src/main/java/tips/PredicateTips.java b/reference-code/bukkit/src/main/java/tips/PredicateTips.java similarity index 97% rename from reference-code/src/main/java/tips/PredicateTips.java rename to reference-code/bukkit/src/main/java/tips/PredicateTips.java index ee24088bf..d3528b392 100644 --- a/reference-code/src/main/java/tips/PredicateTips.java +++ b/reference-code/bukkit/src/main/java/tips/PredicateTips.java @@ -1,10 +1,10 @@ package tips; -import com.velocitypowered.api.proxy.Player; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; diff --git a/reference-code/src/main/java/utils/Conversion.java b/reference-code/bukkit/src/main/java/utils/Conversion.java similarity index 86% rename from reference-code/src/main/java/utils/Conversion.java rename to reference-code/bukkit/src/main/java/utils/Conversion.java index 8a243f9ea..484d6c616 100644 --- a/reference-code/src/main/java/utils/Conversion.java +++ b/reference-code/bukkit/src/main/java/utils/Conversion.java @@ -1,9 +1,9 @@ package utils; import dev.jorel.commandapi.Converter; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.MultiLiteralArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -26,7 +26,7 @@ public void onEnable() { Converter.convert(essentials, "speed", new IntegerArgument("speed", 0, 10)); // /speed - Converter.convert(essentials, "speed", new PlayerArgument("target")); + Converter.convert(essentials, "speed", new EntitySelectorArgument.OnePlayer("target")); // /speed Converter.convert(essentials, "speed", @@ -38,7 +38,7 @@ public void onEnable() { Converter.convert(essentials, "speed", new MultiLiteralArgument("modes", "walk", "fly"), new IntegerArgument("speed", 0, 10), - new PlayerArgument("target") + new EntitySelectorArgument.OnePlayer("target") ); // #endregion convertSpeedCommandExample } diff --git a/reference-code/src/main/kotlin/createcommands/Aliases.kt b/reference-code/bukkit/src/main/kotlin/createcommands/Aliases.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/Aliases.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/Aliases.kt diff --git a/reference-code/src/main/kotlin/createcommands/CommandTrees.kt b/reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt similarity index 99% rename from reference-code/src/main/kotlin/createcommands/CommandTrees.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt index 943a7cd5e..d1b475989 100644 --- a/reference-code/src/main/kotlin/createcommands/CommandTrees.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/CommandTrees.kt @@ -18,7 +18,7 @@ fun commandTrees() { sender.sendMessage("Hi!") }) .then( - PlayerArgument("target") + EntitySelectorArgument.OnePlayer("target") .executes(CommandExecutor { _, args -> val target = args["target"] as Player target.sendMessage("Hi") diff --git a/reference-code/src/main/kotlin/createcommands/Help.kt b/reference-code/bukkit/src/main/kotlin/createcommands/Help.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/Help.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/Help.kt diff --git a/reference-code/src/main/kotlin/createcommands/Permissions.kt b/reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt similarity index 90% rename from reference-code/src/main/kotlin/createcommands/Permissions.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt index b13df41b7..4e167181b 100644 --- a/reference-code/src/main/kotlin/createcommands/Permissions.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/Permissions.kt @@ -4,8 +4,8 @@ import createcommands.Permissions.Economy import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.CommandPermission import dev.jorel.commandapi.arguments.DoubleArgument -import dev.jorel.commandapi.arguments.LiteralArgument; -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.EntitySelectorArgument +import dev.jorel.commandapi.arguments.LiteralArgument import dev.jorel.commandapi.executors.PlayerCommandExecutor import org.bukkit.entity.Player @@ -44,7 +44,7 @@ fun permissions() { // #region argumentPermissionExampleStep2 // Adds the OP permission to the "target" argument. The sender requires OP to execute /kill CommandAPICommand("kill") - .withArguments(PlayerArgument("target").withPermission(CommandPermission.OP)) + .withArguments(EntitySelectorArgument.OnePlayer("target").withPermission(CommandPermission.OP)) .executesPlayer(PlayerCommandExecutor { _, args -> (args["target"] as Player).health = 0.0 }) @@ -63,7 +63,7 @@ fun permissions() { // /economy - requires the permission "economy.other" to execute CommandAPICommand("economy") .withPermission("economy.other") // The important part of this example - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .executesPlayer(PlayerCommandExecutor { player, args -> val target = args["target"] as Player @@ -76,7 +76,7 @@ fun permissions() { CommandAPICommand("economy") .withPermission("economy.admin.give") // The important part of this example .withArguments(LiteralArgument("give")) - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .withArguments(DoubleArgument("amount")) .executesPlayer(PlayerCommandExecutor { player, args -> val target = args["target"] as Player @@ -91,7 +91,7 @@ fun permissions() { CommandAPICommand("economy") .withPermission("economy.admin.reset") // The important part of this example .withArguments(LiteralArgument("reset")) - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .executesPlayer(PlayerCommandExecutor { player, args -> val target = args["target"] as Player diff --git a/reference-code/src/main/kotlin/createcommands/Registration.kt b/reference-code/bukkit/src/main/kotlin/createcommands/Registration.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/Registration.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/Registration.kt diff --git a/reference-code/src/main/kotlin/createcommands/Requirements.kt b/reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt similarity index 94% rename from reference-code/src/main/kotlin/createcommands/Requirements.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt index 056d1222d..22d1a8f2f 100644 --- a/reference-code/src/main/kotlin/createcommands/Requirements.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/Requirements.kt @@ -63,11 +63,11 @@ fun requirements() { arguments.add(LiteralArgument("tp") .withRequirement { partyMembers.containsKey((it as Player).uniqueId) }) - arguments.add(PlayerArgument("player") - .replaceSafeSuggestions(SafeSuggestions.suggest { info -> + arguments.add(EntitySelectorArgument.OnePlayer("player") + .replaceSuggestions(ArgumentSuggestions.strings { info -> // Store the list of party members to teleport to - val playersToTeleportTo = mutableListOf() + val playersToTeleportTo = mutableListOf() val partyName = partyMembers[(info.sender() as Player).uniqueId] @@ -83,7 +83,7 @@ fun requirements() { val target = Bukkit.getPlayer(uuid)!! if (target.isOnline) { // Add them if they are online - playersToTeleportTo.add(target) + playersToTeleportTo.add(target.name) } } } diff --git a/reference-code/src/main/kotlin/createcommands/Subcommands.kt b/reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/Subcommands.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/Subcommands.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/Arguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt similarity index 89% rename from reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt index 4a5818f6f..4773cafe9 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/CommandArguments.kt @@ -10,8 +10,8 @@ fun commandArguments() { CommandAPICommand("mycommand") .withArguments(StringArgument("name")) .withArguments(IntegerArgument("amount")) - .withOptionalArguments(PlayerArgument("player")) - .withOptionalArguments(PlayerArgument("target")) + .withOptionalArguments(EntitySelectorArgument.OnePlayer("player")) + .withOptionalArguments(EntitySelectorArgument.OnePlayer("target")) .withOptionalArguments(GreedyStringArgument("message")) .executesPlayer(PlayerCommandExecutor { player, args -> val name = args[0] as String // Access arguments by index @@ -36,7 +36,7 @@ fun commandArguments() { // #region getUncheckedExample CommandAPICommand("mycommand") - .withArguments(PlayerArgument("player")) + .withArguments(EntitySelectorArgument.OnePlayer("player")) .executesPlayer(PlayerCommandExecutor { player, args -> val p: Player = args.getUnchecked("player")!! // Do whatever with the player @@ -47,8 +47,8 @@ fun commandArguments() { // #region getByArgumentExample val nameArgument = StringArgument("name") val amountArgument = IntegerArgument("amount") - val playerArgument = PlayerArgument("player") - val targetArgument = PlayerArgument("target") + val playerArgument = EntitySelectorArgument.OnePlayer("player") + val targetArgument = EntitySelectorArgument.OnePlayer("target") val messageArgument = GreedyStringArgument("message") CommandAPICommand("mycommand") diff --git a/reference-code/src/main/kotlin/createcommands/arguments/ListedArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/ListedArguments.kt similarity index 77% rename from reference-code/src/main/kotlin/createcommands/arguments/ListedArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/ListedArguments.kt index e276e45d2..731aa92e5 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/ListedArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/ListedArguments.kt @@ -1,21 +1,17 @@ package createcommands.arguments import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.GreedyStringArgument import dev.jorel.commandapi.arguments.IntegerArgument -import dev.jorel.commandapi.arguments.PlayerArgument import dev.jorel.commandapi.executors.CommandExecutor -import dev.jorel.commandapi.kotlindsl.anyExecutor -import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.greedyStringArgument -import dev.jorel.commandapi.kotlindsl.integerArgument -import dev.jorel.commandapi.kotlindsl.playerArgument +import dev.jorel.commandapi.kotlindsl.* import org.bukkit.entity.Player fun listedArguments() { // #region listedArgumentsExample CommandAPICommand("mycommand") - .withArguments(PlayerArgument("player")) + .withArguments(EntitySelectorArgument.OnePlayer("player")) .withArguments(IntegerArgument("value").setListed(false)) .withArguments(GreedyStringArgument("message")) .executes(CommandExecutor { _, args -> @@ -31,7 +27,7 @@ fun listedArguments() { fun listedArgumentsDSL() { // #region listedArgumentsExampleDSL commandAPICommand("mycommand") { - playerArgument("player") + entitySelectorArgumentOnePlayer("player") integerArgument("value") { isListed = false } greedyStringArgument("message") anyExecutor { _, args -> diff --git a/reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt similarity index 86% rename from reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt index 10512917c..f716c3f5c 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/OptionalArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/OptionalArguments.kt @@ -1,23 +1,19 @@ package createcommands.arguments import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.IntegerArgument -import dev.jorel.commandapi.arguments.PlayerArgument import dev.jorel.commandapi.arguments.StringArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.executors.PlayerCommandExecutor -import dev.jorel.commandapi.kotlindsl.anyExecutor -import dev.jorel.commandapi.kotlindsl.argument -import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.playerArgument -import dev.jorel.commandapi.kotlindsl.playerExecutor +import dev.jorel.commandapi.kotlindsl.* import org.bukkit.command.CommandSender import org.bukkit.entity.Player fun optionalArguments() { // #region simpleOptionalArgumentsExample CommandAPICommand("sayhi") - .withOptionalArguments(PlayerArgument("target")) + .withOptionalArguments(EntitySelectorArgument.OnePlayer("target")) .executesPlayer(PlayerCommandExecutor { player, args -> val target: Player? = args["target"] as Player? if (target != null) { @@ -31,7 +27,7 @@ fun optionalArguments() { // #region getOptionalExample CommandAPICommand("sayhi") - .withOptionalArguments(PlayerArgument("target")) + .withOptionalArguments(EntitySelectorArgument.OnePlayer("target")) .executesPlayer(PlayerCommandExecutor { player, args -> val target: Player = args.getOptional("target").orElse(player) as Player target.sendMessage("Hi!") @@ -42,7 +38,7 @@ fun optionalArguments() { // #region argumentsAfterOptionalArgumentsExample CommandAPICommand("rate") .withOptionalArguments(StringArgument("topic").combineWith(IntegerArgument("rating", 0, 10))) - .withOptionalArguments(PlayerArgument("target")) + .withOptionalArguments(EntitySelectorArgument.OnePlayer("target")) .executes(CommandExecutor { sender, args -> val topic: String? = args["topic"] as String? if (topic == null) { @@ -69,7 +65,7 @@ fun optionalArguments() { fun optionalArgumentsDSL() { // #region simpleOptionalArgumentsExampleDSL commandAPICommand("sayhi") { - playerArgument("target", optional = true) + entitySelectorArgumentOnePlayer("target", optional = true) playerExecutor { player, args -> val target: Player? = args["target"] as Player? if (target != null) { @@ -83,7 +79,7 @@ fun optionalArgumentsDSL() { // #region getOptionalExampleDSL commandAPICommand("sayhi") { - playerArgument("target", optional = true) + entitySelectorArgumentOnePlayer("target", optional = true) playerExecutor { player, args -> val target: Player = args.getOptional("target").orElse(player) as Player target.sendMessage("Hi!") @@ -94,7 +90,7 @@ fun optionalArgumentsDSL() { // #region argumentsAfterOptionalArgumentsExampleDSL commandAPICommand("rate") { argument(StringArgument("topic").setOptional(true).combineWith(IntegerArgument("rating", 0, 10))) - playerArgument("target", optional = true) + entitySelectorArgumentOnePlayer("target", optional = true) anyExecutor { sender, args -> val topic: String? = args["topic"] as String? if (topic == null) { diff --git a/reference-code/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt similarity index 84% rename from reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt index c54656de8..ab3efedcf 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt @@ -2,18 +2,13 @@ package createcommands.arguments.suggestions import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.SuggestionInfo -import dev.jorel.commandapi.arguments.Argument -import dev.jorel.commandapi.arguments.ArgumentSuggestions -import dev.jorel.commandapi.arguments.GreedyStringArgument -import dev.jorel.commandapi.arguments.IntegerArgument -import dev.jorel.commandapi.arguments.PlayerArgument -import dev.jorel.commandapi.arguments.StringArgument +import dev.jorel.commandapi.arguments.* import dev.jorel.commandapi.executors.PlayerCommandExecutor import org.bukkit.Location import org.bukkit.command.CommandSender import org.bukkit.entity.EntityType import org.bukkit.entity.Player -import java.util.UUID +import java.util.* // #region createFriendsClass object Friends { @@ -54,7 +49,7 @@ fun stringSuggestions() { fun stringSuggestions2() { // #region createFriendCommand val arguments = listOf>( - PlayerArgument("friend").replaceSuggestions( + EntitySelectorArgument.OnePlayer("friend").replaceSuggestions( ArgumentSuggestions.strings { info -> Friends.getFriends(info.sender()) } @@ -75,10 +70,10 @@ fun stringSuggestions2() { val commandArgs = mutableListOf>() commandArgs.add(IntegerArgument("radius")) - // Replace the suggestions for the PlayerArgument. + // Replace the suggestions for the EntitySelectorArgument.OnePlayer. // info.sender() refers to the command sender running this command // info.previousArgs() refers to the Object[] of previously declared arguments (in this case, the IntegerArgument radius) - commandArgs.add(PlayerArgument("target").replaceSuggestions(ArgumentSuggestions.strings { info: SuggestionInfo -> + commandArgs.add(EntitySelectorArgument.OnePlayer("target").replaceSuggestions(ArgumentSuggestions.strings { info: SuggestionInfo -> // Cast the first argument (radius, which is an IntegerArgument) to get its value val radius = (info.previousArgs()["radius"] as Int).toDouble() diff --git a/reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt similarity index 93% rename from reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt index d1329fb9e..d1f31fd66 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt @@ -5,12 +5,8 @@ import dev.jorel.commandapi.BukkitTooltip import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.IStringTooltip import dev.jorel.commandapi.StringTooltip -import dev.jorel.commandapi.arguments.Argument -import dev.jorel.commandapi.arguments.ArgumentSuggestions -import dev.jorel.commandapi.arguments.LocationArgument -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.* import dev.jorel.commandapi.arguments.SafeSuggestions -import dev.jorel.commandapi.arguments.StringArgument import dev.jorel.commandapi.executors.PlayerCommandExecutor import org.bukkit.Location import org.bukkit.Material @@ -30,7 +26,7 @@ fun tooltips() { ) }) ) - arguments.add(PlayerArgument("target")) + arguments.add(EntitySelectorArgument.OnePlayer("target")) // #endregion createArgumentsWithTooltips // #region registerEmoteCommand diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt similarity index 93% rename from reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt index 1c313862a..046d9411a 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/CommandArguments.kt @@ -3,13 +3,13 @@ package createcommands.arguments.types import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.arguments.ArgumentSuggestions import dev.jorel.commandapi.arguments.CommandArgument -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.SuggestionsBranch import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.kotlindsl.anyExecutor import dev.jorel.commandapi.kotlindsl.commandAPICommand import dev.jorel.commandapi.kotlindsl.commandArgument -import dev.jorel.commandapi.kotlindsl.playerArgument +import dev.jorel.commandapi.kotlindsl.entitySelectorArgumentOnePlayer import dev.jorel.commandapi.wrappers.CommandResult import org.bukkit.Bukkit import org.bukkit.command.CommandSender @@ -18,7 +18,7 @@ import org.bukkit.entity.Player fun commandArguments() { // #region sudoCommandExample CommandAPICommand("sudo") - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .withArguments(CommandArgument("command")) .executes(CommandExecutor { _, args -> val target = args["target"] as Player @@ -83,7 +83,7 @@ fun commandArguments() { fun commandArgumentsDSL() { // #region sudoCommandExampleDSL commandAPICommand("sudo") { - playerArgument("target") + entitySelectorArgumentOnePlayer("target") commandArgument("command") anyExecutor { _, args -> val target = args["target"] as Player diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/ListArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/ListArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/ListArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/ListArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/MapArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/MapArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/MapArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/MapArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/PrimitiveArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/RangedArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt similarity index 81% rename from reference-code/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt index 041b5925a..ce5f27297 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/StringsArguments.kt @@ -1,19 +1,19 @@ package createcommands.arguments.types import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.GreedyStringArgument -import dev.jorel.commandapi.arguments.PlayerArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.kotlindsl.anyExecutor import dev.jorel.commandapi.kotlindsl.commandAPICommand +import dev.jorel.commandapi.kotlindsl.entitySelectorArgumentOnePlayer import dev.jorel.commandapi.kotlindsl.greedyStringArgument -import dev.jorel.commandapi.kotlindsl.playerArgument import org.bukkit.entity.Player fun stringsArguments() { // #region greedyStringArgumentsExample CommandAPICommand("message") - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .withArguments(GreedyStringArgument("message")) .executes(CommandExecutor { _, args -> (args["target"] as Player).sendMessage(args["message"] as String) @@ -25,7 +25,7 @@ fun stringsArguments() { fun stringsArgumentsDSL() { // #region greedyStringArgumentsExampleDSL commandAPICommand("message") { - playerArgument("target") + entitySelectorArgumentOnePlayer("target") greedyStringArgument("message") anyExecutor { _, args -> (args["target"] as Player).sendMessage(args["message"] as String) diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/LiteralArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/literal/MultiLiteralArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt similarity index 87% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt index eccdf56f8..ccc24b642 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt @@ -2,19 +2,19 @@ package createcommands.arguments.types.misc import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.arguments.AdvancementArgument -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.kotlindsl.advancementArgument import dev.jorel.commandapi.kotlindsl.anyExecutor import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.playerArgument +import dev.jorel.commandapi.kotlindsl.entitySelectorArgumentOnePlayer import org.bukkit.advancement.Advancement import org.bukkit.entity.Player fun advancementArguments() { // #region advancementArgumentsExample CommandAPICommand("award") - .withArguments(PlayerArgument("player")) + .withArguments(EntitySelectorArgument.OnePlayer("player")) .withArguments(AdvancementArgument("advancement")) .executes(CommandExecutor { _, args -> val target = args["player"] as Player @@ -33,7 +33,7 @@ fun advancementArguments() { fun advancementArgumentsDSL() { // #region advancementArgumentsExampleDSL commandAPICommand("award") { - playerArgument("player") + entitySelectorArgumentOnePlayer("player") advancementArgument("advancement") anyExecutor { _, args -> val target = args["player"] as Player diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt similarity index 73% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt index bba5283f3..554ed9831 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt @@ -6,19 +6,19 @@ import dev.jorel.commandapi.executors.PlayerCommandExecutor import dev.jorel.commandapi.kotlindsl.blockStateArgument import dev.jorel.commandapi.kotlindsl.commandAPICommand import dev.jorel.commandapi.kotlindsl.playerExecutor -import org.bukkit.block.data.BlockData +import org.bukkit.block.BlockState fun blockStateArguments() { // #region blockStateArgumentsExample CommandAPICommand("set") .withArguments(BlockStateArgument("block")) .executesPlayer(PlayerCommandExecutor { player, args -> - val blockdata = args["block"] as BlockData + val blockState = args["block"] as BlockState val targetBlock = player.getTargetBlockExact(256) // Set the block, along with its data - targetBlock?.type = blockdata.material - targetBlock?.state?.blockData = blockdata + targetBlock?.type = blockState.blockData.material + targetBlock?.state?.blockData = blockState.blockData }) .register() // #endregion blockStateArgumentsExample @@ -29,12 +29,12 @@ fun blockStateArgumentsDSL() { commandAPICommand("set") { blockStateArgument("block") playerExecutor { player, args -> - val blockdata = args["block"] as BlockData + val blockState = args["block"] as BlockState val targetBlock = player.getTargetBlockExact(256) // Set the block, along with its data - targetBlock?.type = blockdata.material - targetBlock?.state?.blockData = blockdata + targetBlock?.type = blockState.blockData.material + targetBlock?.state?.blockData = blockState.blockData } } // #endregion blockStateArgumentsExampleDSL diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt similarity index 89% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt index db30c1c06..56cebdd30 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt @@ -1,9 +1,9 @@ package createcommands.arguments.types.misc import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.IntegerArgument import dev.jorel.commandapi.arguments.MathOperationArgument -import dev.jorel.commandapi.arguments.PlayerArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.kotlindsl.* import dev.jorel.commandapi.wrappers.MathOperation @@ -12,7 +12,7 @@ import org.bukkit.entity.Player fun mathOperationArguments() { // #region mathOperationArgumentsExample CommandAPICommand("changelevel") - .withArguments(PlayerArgument("player")) + .withArguments(EntitySelectorArgument.OnePlayer("player")) .withArguments(MathOperationArgument("operation")) .withArguments(IntegerArgument("value")) .executes(CommandExecutor { _, args -> @@ -29,7 +29,7 @@ fun mathOperationArguments() { fun mathOperationArgumentsDSL() { // #region mathOperationArgumentsExampleDSL commandAPICommand("changelevel") { - playerArgument("player") + entitySelectorArgumentOnePlayer("player") mathOperationArgument("operation") integerArgument("value") anyExecutor { _, args -> diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/ParticleArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt similarity index 92% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt index aee9cc27a..837a293b7 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt @@ -1,8 +1,8 @@ package createcommands.arguments.types.misc import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.IntegerArgument -import dev.jorel.commandapi.arguments.PlayerArgument import dev.jorel.commandapi.arguments.PotionEffectArgument import dev.jorel.commandapi.arguments.TimeArgument import dev.jorel.commandapi.executors.CommandExecutor @@ -15,7 +15,7 @@ import org.bukkit.potion.PotionEffectType fun potionArguments() { // #region potionEffectArgumentsExample CommandAPICommand("potion") - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .withArguments(PotionEffectArgument("potion")) .withArguments(TimeArgument("duration")) .withArguments(IntegerArgument("strength")) @@ -33,7 +33,7 @@ fun potionArguments() { // #region potionEffectArgumentsNamespacedKeyExample CommandAPICommand("potion") - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .withArguments(PotionEffectArgument.NamespacedKey("potion")) .withArguments(TimeArgument("duration")) .withArguments(IntegerArgument("strength")) @@ -55,7 +55,7 @@ fun potionArguments() { fun potionArgumentsDSL() { // region potionEffectArgumentsExampleDSL commandAPICommand("potion") { - playerArgument("target") + entitySelectorArgumentOnePlayer("target") potionEffectArgument("potion") timeArgument("duration") integerArgument("strength") @@ -73,7 +73,7 @@ fun potionArgumentsDSL() { // region potionEffectArgumentsNamespacedKeyExampleDSL commandAPICommand("potion") { - playerArgument("target") + entitySelectorArgumentOnePlayer("target") potionEffectArgument("potion", true) timeArgument("duration") integerArgument("strength") diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt similarity index 91% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt index 3ea1aed74..6da753a08 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt +++ b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt @@ -1,7 +1,7 @@ package createcommands.arguments.types.misc import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.RecipeArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.executors.PlayerCommandExecutor @@ -22,7 +22,7 @@ fun recipeArguments() { // #region getKeyExample CommandAPICommand("unlockrecipe") - .withArguments(PlayerArgument("player")) + .withArguments(EntitySelectorArgument.OnePlayer("player")) .withArguments(RecipeArgument("recipe")) .executes(CommandExecutor { _, args -> val target = args["player"] as Player @@ -47,7 +47,7 @@ fun recipeArgumentsDSL() { // #region getKeyExampleDSL commandAPICommand("unlockrecipe") { - playerArgument("player") + entitySelectorArgumentOnePlayer("player") recipeArgument("recipe") anyExecutor { _, args -> val target = args["player"] as Player diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/LocationArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/position/RotationArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/BlockPredicateArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/predicate/ItemStackPredicateArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ObjectiveArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/ScoreboardArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/arguments/types/scoreboard/TeamArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/executors/HandleFailures.kt b/reference-code/bukkit/src/main/kotlin/createcommands/executors/HandleFailures.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/executors/HandleFailures.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/executors/HandleFailures.kt diff --git a/reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt b/reference-code/bukkit/src/main/kotlin/createcommands/executors/NativeSender.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/executors/NativeSender.kt diff --git a/reference-code/src/main/kotlin/createcommands/executors/NormalExecutors.kt b/reference-code/bukkit/src/main/kotlin/createcommands/executors/NormalExecutors.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/executors/NormalExecutors.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/executors/NormalExecutors.kt diff --git a/reference-code/src/main/kotlin/createcommands/executors/ProxySender.kt b/reference-code/bukkit/src/main/kotlin/createcommands/executors/ProxySender.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/executors/ProxySender.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/executors/ProxySender.kt diff --git a/reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt b/reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/executors/ResultingExecutors.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/executors/ResultingExecutors.kt diff --git a/reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt b/reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt b/reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt rename to reference-code/bukkit/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt diff --git a/reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt b/reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt similarity index 100% rename from reference-code/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt rename to reference-code/bukkit/src/main/kotlin/internal/BrigadierPlusCommandAPI.kt diff --git a/reference-code/src/main/kotlin/internal/BrigadierSuggestions.kt b/reference-code/bukkit/src/main/kotlin/internal/BrigadierSuggestions.kt similarity index 100% rename from reference-code/src/main/kotlin/internal/BrigadierSuggestions.kt rename to reference-code/bukkit/src/main/kotlin/internal/BrigadierSuggestions.kt diff --git a/reference-code/src/main/kotlin/kotlindsl/DelegatedProperties.kt b/reference-code/bukkit/src/main/kotlin/kotlindsl/DelegatedProperties.kt similarity index 85% rename from reference-code/src/main/kotlin/kotlindsl/DelegatedProperties.kt rename to reference-code/bukkit/src/main/kotlin/kotlindsl/DelegatedProperties.kt index c1691b905..4b95ccd12 100644 --- a/reference-code/src/main/kotlin/kotlindsl/DelegatedProperties.kt +++ b/reference-code/bukkit/src/main/kotlin/kotlindsl/DelegatedProperties.kt @@ -1,7 +1,7 @@ package kotlindsl import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.StringArgument import dev.jorel.commandapi.executors.PlayerCommandExecutor import dev.jorel.commandapi.kotlindsl.* @@ -11,7 +11,7 @@ fun delegatedProperties() { // #region delegatedPropertiesExample CommandAPICommand("mycommand") .withArguments(StringArgument("string")) - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .executesPlayer(PlayerCommandExecutor { player, args -> val string: String by args val target: Player by args @@ -25,7 +25,7 @@ fun delegatedPropertiesDSL() { // #region delegatedPropertiesExampleDSL commandAPICommand("mycommand") { stringArgument("string") - playerArgument("target") + entitySelectorArgumentOnePlayer("target") playerExecutor { player, args -> val string: String by args val target: Player by args diff --git a/reference-code/src/main/kotlin/kotlindsl/Usage.kt b/reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt similarity index 95% rename from reference-code/src/main/kotlin/kotlindsl/Usage.kt rename to reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt index d13a564b0..bd673e3a4 100644 --- a/reference-code/src/main/kotlin/kotlindsl/Usage.kt +++ b/reference-code/bukkit/src/main/kotlin/kotlindsl/Usage.kt @@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack fun usage() { // #region dslExample commandAPICommand("sendmessageto") { - playerArgument("player") // Defines a new PlayerArgument("player") + entitySelectorArgumentOnePlayer("player") // Defines a new EntitySelectorArgument.OnePlayer("player") greedyStringArgument("msg") // Defines a new GreedyStringArgument("msg") anyExecutor { _, args -> // Command can be executed by anyone and anything (such as entities, the console, etc.) val player: Player = args["player"] as Player @@ -22,7 +22,7 @@ fun usage() { // #region argumentRequirementsExample commandAPICommand("sendMessageTo") { - playerArgument("player") + entitySelectorArgumentOnePlayer("player") greedyStringArgument("msg") playerExecutor { _, args -> val player: Player = args["player"] as Player @@ -85,7 +85,7 @@ fun usage() { fun usageTree() { // #region dslTreeExample commandTree("sendmessageto") { - playerArgument("player") { // Defines a new PlayerArgument("player") + entitySelectorArgumentOnePlayer("player") { // Defines a new EntitySelectorArgument.OnePlayer("player") greedyStringArgument("msg") { // Defines a new GreedyStringArgument("msg") anyExecutor { _, args -> // Command can be executed by anyone and anything (such as entities, the console, etc.) val player: Player = args["player"] as Player @@ -99,7 +99,7 @@ fun usageTree() { // #region argumentRequirementsTreeExample commandTree("sendMessageTo") { - playerArgument("player") { + entitySelectorArgumentOnePlayer("player") { greedyStringArgument("msg") { playerExecutor { _, args -> val player: Player = args["player"] as Player diff --git a/reference-code/src/main/kotlin/tips/PredicateTips.kt b/reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt similarity index 100% rename from reference-code/src/main/kotlin/tips/PredicateTips.kt rename to reference-code/bukkit/src/main/kotlin/tips/PredicateTips.kt diff --git a/reference-code/src/main/kotlin/utils/Conversion.kt b/reference-code/bukkit/src/main/kotlin/utils/Conversion.kt similarity index 85% rename from reference-code/src/main/kotlin/utils/Conversion.kt rename to reference-code/bukkit/src/main/kotlin/utils/Conversion.kt index 14fbbe8a0..10b38235e 100644 --- a/reference-code/src/main/kotlin/utils/Conversion.kt +++ b/reference-code/bukkit/src/main/kotlin/utils/Conversion.kt @@ -1,9 +1,9 @@ package utils import dev.jorel.commandapi.Converter +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.arguments.IntegerArgument import dev.jorel.commandapi.arguments.MultiLiteralArgument -import dev.jorel.commandapi.arguments.PlayerArgument import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin @@ -24,7 +24,7 @@ fun conversion() { Converter.convert(essentials, "speed", IntegerArgument("speed", 0, 10)) // /speed - Converter.convert(essentials, "speed", PlayerArgument("target")) + Converter.convert(essentials, "speed", EntitySelectorArgument.OnePlayer("target")) // /speed Converter.convert(essentials, "speed", @@ -36,7 +36,7 @@ fun conversion() { Converter.convert(essentials, "speed", MultiLiteralArgument("modes", "walk", "fly"), IntegerArgument("speed", 0, 10), - PlayerArgument("target") + EntitySelectorArgument.OnePlayer("target") ) // #endregion convertSpeedCommandExample } \ No newline at end of file diff --git a/reference-code/gradle.properties b/reference-code/gradle.properties new file mode 100644 index 000000000..a71589fbd --- /dev/null +++ b/reference-code/gradle.properties @@ -0,0 +1,10 @@ +commandApiVersion=11.0.0 +paperVersion=1.20.6-R0.1-SNAPSHOT +spigotVersion=1.20-R0.1-SNAPSHOT +velocityVersion=3.4.0-SNAPSHOT +brigadierVersion=1.0.17 +authlibVersion=3.3.39 +nbtApiVersion=2.11.1 +kotlinVersion=2.0.0 +junitVersion=5.11.0 +mockBukkitVersion=4.76.0 diff --git a/reference-code/gradle/libs.versions.toml b/reference-code/gradle/libs.versions.toml deleted file mode 100644 index bf73e2495..000000000 --- a/reference-code/gradle/libs.versions.toml +++ /dev/null @@ -1,34 +0,0 @@ -# This file was generated by the Gradle 'init' task. -# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format - -[versions] -com-github-seeseemelk-mockbukkit-v1-v21 = "3.133.2" -com-mojang-authlib = "3.3.39" -com-mojang-brigadier = "1.0.17" -com-velocitypowered-velocity-api = "3.4.0-SNAPSHOT" -de-tr7zw-item-nbt-api = "2.11.1" -dev-jorel-commandapi-annotations = "10.1.2" -dev-jorel-commandapi-bukkit-core = "10.1.2" -dev-jorel-commandapi-bukkit-kotlin = "10.1.2" -dev-jorel-commandapi-bukkit-test-toolkit = "10.1.2" -dev-jorel-commandapi-velocity-shade = "10.1.2" -io-papermc-paper-paper-api = "1.21-R0.1-SNAPSHOT" -net-kyori-adventure-platform-bukkit = "4.2.0" -org-jetbrains-kotlin-kotlin-stdlib = "2.0.0" -org-junit-jupiter-junit-jupiter = "5.11.0" - -[libraries] -com-github-seeseemelk-mockbukkit-v1-v21 = { module = "com.github.seeseemelk:MockBukkit-v1.21", version.ref = "com-github-seeseemelk-mockbukkit-v1-v21" } -com-mojang-authlib = { module = "com.mojang:authlib", version.ref = "com-mojang-authlib" } -com-mojang-brigadier = { module = "com.mojang:brigadier", version.ref = "com-mojang-brigadier" } -com-velocitypowered-velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "com-velocitypowered-velocity-api" } -de-tr7zw-item-nbt-api = { module = "de.tr7zw:item-nbt-api", version.ref = "de-tr7zw-item-nbt-api" } -dev-jorel-commandapi-annotations = { module = "dev.jorel:commandapi-annotations", version.ref = "dev-jorel-commandapi-annotations" } -dev-jorel-commandapi-bukkit-core = { module = "dev.jorel:commandapi-bukkit-core", version.ref = "dev-jorel-commandapi-bukkit-core" } -dev-jorel-commandapi-bukkit-kotlin = { module = "dev.jorel:commandapi-bukkit-kotlin", version.ref = "dev-jorel-commandapi-bukkit-kotlin" } -dev-jorel-commandapi-bukkit-test-toolkit = { module = "dev.jorel:commandapi-bukkit-test-toolkit", version.ref = "dev-jorel-commandapi-bukkit-test-toolkit" } -dev-jorel-commandapi-velocity-shade = { module = "dev.jorel:commandapi-velocity-shade", version.ref = "dev-jorel-commandapi-velocity-shade" } -io-papermc-paper-paper-api = { module = "io.papermc.paper:paper-api", version.ref = "io-papermc-paper-paper-api" } -net-kyori-adventure-platform-bukkit = { module = "net.kyori:adventure-platform-bukkit", version.ref = "net-kyori-adventure-platform-bukkit" } -org-jetbrains-kotlin-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "org-jetbrains-kotlin-kotlin-stdlib" } -org-junit-jupiter-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "org-junit-jupiter-junit-jupiter" } diff --git a/reference-code/paper/build.gradle.kts b/reference-code/paper/build.gradle.kts new file mode 100644 index 000000000..eb77720bb --- /dev/null +++ b/reference-code/paper/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + common +} + +group = "dev.jorel.commandapi" +version = "1.0-SNAPSHOT" +description = "reference-code-paper" + +val commandApiVersion: String by project +val paperVersion: String by project + +dependencies { + implementation("dev.jorel:commandapi-paper-core:$commandApiVersion") + implementation("dev.jorel:commandapi-kotlin-paper:$commandApiVersion") + implementation("io.papermc.paper:paper-api:$paperVersion") + + testImplementation("dev.jorel:commandapi-paper-test-toolkit:${commandApiVersion}") +} \ No newline at end of file diff --git a/reference-code/paper/src/main/java/createcommands/Unregistration.java b/reference-code/paper/src/main/java/createcommands/Unregistration.java new file mode 100644 index 000000000..e1c40ba79 --- /dev/null +++ b/reference-code/paper/src/main/java/createcommands/Unregistration.java @@ -0,0 +1,137 @@ +package createcommands; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaperConfig; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import net.kyori.adventure.text.Component; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; + +class Unregistration { + + // #region registerBootstrapExample + public class MyPluginBootstrap implements PluginBootstrap { + + @Override + public void bootstrap(@NotNull BootstrapContext context) { + CommandAPI.onLoad(new CommandAPIPaperConfig(context)); + + new CommandAPICommand("inbootstrap") + .executes((sender, args) -> { + sender.sendMessage(Component.text("This command is registed in step 3!")); + }) + .register(); + } + } + // #endregion registerBootstrapExample + + { + new JavaPlugin() { + // #region unregisterBukkitExample + @Override + public void onLoad() { + CommandAPIBukkit.unregister("version", true, true); + } + // #endregion unregisterBukkitExample + }; + + new JavaPlugin() { + // #region unregisterVanillaExample + @Override + public void onEnable() { + CommandAPI.unregister("gamemode"); + } + // #endregion unregisterVanillaExample + }; + + new JavaPlugin() { + // #region unregisterVanillaAndReplaceExample + @Override + public void onEnable() { + // Register our new /gamemode, with survival, creative, adventure and spectator + new CommandAPICommand("gamemode") + .withArguments(new MultiLiteralArgument("gamemodes", "survival", "creative", "adventure", "spectator")) + .executes((sender, args) -> { + // Implementation of our /gamemode command + }) + .register(); + } + // #endregion unregisterVanillaAndReplaceExample + }; + + new JavaPlugin() { + // #region unregisterPluginExample + @Override + public void onEnable() { + CommandAPIBukkit.unregister("luckperms:luckperms", false, true); + } + // #endregion unregisterPluginExample + }; + + new JavaPlugin() { + // #region unregisterCommandAPIExample + @Override + public void onEnable() { + CommandAPI.unregister("break"); + } + // #endregion unregisterCommandAPIExample + }; + + new JavaPlugin() { + // #region unregisterBukkitHelpExample + @Override + public void onEnable() { + CommandAPIBukkit.unregister("help", false, true); + } + // #endregion unregisterBukkitHelpExample + }; + + new JavaPlugin() { + // #region unregisterVanillaNamespaceOnlyExample + @Override + public void onEnable() { + new BukkitRunnable() { + @Override + public void run() { + CommandAPI.unregister("minecraft:gamemode"); + } + }.runTaskLater(this, 0); + } + // #endregion unregisterVanillaNamespaceOnlyExample + }; + + new JavaPlugin() { + // #region unregisterDelayedVanillaBadExample + // NOT RECOMMENDED + @Override + public void onEnable() { + new BukkitRunnable() { + @Override + public void run() { + CommandAPI.unregister("gamemode"); + } + }.runTaskLater(this, 0); + } + // #endregion unregisterDelayedVanillaBadExample + }; + + new JavaPlugin() { + // #region unregisterDelayedVanillaGoodExample + @Override + public void onEnable() { + new BukkitRunnable() { + @Override + public void run() { + CommandAPI.unregister("gamemode", true); + } + }.runTaskLater(this, 0); + } + // #endregion unregisterDelayedVanillaGoodExample + }; + } +} diff --git a/reference-code/src/main/java/createcommands/arguments/types/CustomArguments.java b/reference-code/paper/src/main/java/createcommands/arguments/types/CustomArguments.java similarity index 100% rename from reference-code/src/main/java/createcommands/arguments/types/CustomArguments.java rename to reference-code/paper/src/main/java/createcommands/arguments/types/CustomArguments.java diff --git a/reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java b/reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java new file mode 100644 index 000000000..d341bfe4c --- /dev/null +++ b/reference-code/paper/src/main/java/createcommands/arguments/types/EntitiesArguments.java @@ -0,0 +1,97 @@ +package createcommands.arguments.types; + +import com.destroystokyo.paper.profile.PlayerProfile; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import dev.jorel.commandapi.arguments.SafeSuggestions; +import dev.jorel.commandapi.executors.CommandArguments; +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +class EntitiesArguments { + static { + // #region entitySelectorArgumentExample + new CommandAPICommand("remove") + // Using a collective entity selector to select multiple entities + .withArguments(new EntitySelectorArgument.ManyEntities("entities")) + .executes((sender, args) -> { + // Parse the argument as a collection of entities (as stated above in the documentation) + @SuppressWarnings("unchecked") + Collection entities = (Collection) args.get("entities"); + + sender.sendMessage("Removed " + entities.size() + " entities"); + for (Entity e : entities) { + e.remove(); + } + }) + .register(); + // #endregion entitySelectorArgumentExample + + // #region buildNoSelectorSuggestions + Argument noSelectorSuggestions = new PlayerProfileArgument("target") + .replaceSafeSuggestions(SafeSuggestions.suggest(info -> + Bukkit.getOnlinePlayers().stream().map(Player::getPlayerProfile).toArray(PlayerProfile[]::new) + )); + // #endregion buildNoSelectorSuggestions + + // #region noSelectorSuggestionsExample + new CommandAPICommand("warp") + .withArguments(noSelectorSuggestions) + .executesPlayer((player, args) -> { + Player target = (Player) args.get("target"); + player.teleport(target); + }) + .register(); + // #endregion noSelectorSuggestionsExample + + // #region playedBeforeArgumentExample + new CommandAPICommand("playedbefore") + .withArguments(new AsyncPlayerProfileArgument("player")) + .executes((sender, args) -> { + CompletableFuture> profiles = (CompletableFuture>) args.get("player"); + + // Directly sends a message to the sender, indicating that the command is running to prevent confusion + sender.sendMessage("Checking if the player has played before..."); + + profiles.thenAccept(profileList -> { + if (Bukkit.getOfflinePlayer(profileList.getFirst().getId()).hasPlayedBefore()) { + sender.sendMessage("Player has played before"); + } else { + sender.sendMessage("Player has never played before"); + } + }).exceptionally(throwable -> { + // We have to partly handle exceptions ourselves, since we are using a CompletableFuture + Throwable cause = throwable.getCause(); + Throwable rootCause = cause instanceof RuntimeException ? cause.getCause() : cause; + + sender.sendMessage(rootCause.getMessage()); + return null; + }); + }) + .register(); + // #endregion playedBeforeArgumentExample + + // #region entityTypeArgumentExample + new CommandAPICommand("spawnmob") + .withArguments(new EntityTypeArgument("entity")) + .withArguments(new IntegerArgument("amount", 1, 100)) // Prevent spawning too many entities + .executesPlayer((Player player, CommandArguments args) -> { + for (int i = 0; i < (int) args.get("amount"); i++) { + player.getWorld().spawnEntity(player.getLocation(), (EntityType) args.get("entity")); + } + }) + .register(); + // #endregion entityTypeArgumentExample + } +} diff --git a/reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java b/reference-code/paper/src/main/java/createcommands/arguments/types/NBTArguments.java similarity index 90% rename from reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java rename to reference-code/paper/src/main/java/createcommands/arguments/types/NBTArguments.java index b93dd082b..85cca346c 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java +++ b/reference-code/paper/src/main/java/createcommands/arguments/types/NBTArguments.java @@ -4,6 +4,7 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIBukkitConfig; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.arguments.NBTCompoundArgument; import org.bukkit.plugin.java.JavaPlugin; @@ -13,7 +14,7 @@ class NBTArguments { // #region hookNbtAPIExample @Override public void onLoad() { - CommandAPI.onLoad(new CommandAPIBukkitConfig(this) + CommandAPI.onLoad(new CommandAPIPaperConfig(this) .initializeNBTAPI(NBTContainer.class, NBTContainer::new) ); } diff --git a/reference-code/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java b/reference-code/paper/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java similarity index 68% rename from reference-code/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java rename to reference-code/paper/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java index 41fa941b0..903c0659d 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java +++ b/reference-code/paper/src/main/java/createcommands/arguments/types/chat/AdventureChatArguments.java @@ -1,24 +1,25 @@ package createcommands.arguments.types.chat; import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.AdventureChatArgument; -import dev.jorel.commandapi.arguments.AdventureChatColorArgument; -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.arguments.TextArgument; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; -import org.bukkit.Server; import org.bukkit.entity.Player; class AdventureChatArguments { static { // #region namedTextColorExample new CommandAPICommand("namecolor") - .withArguments(new AdventureChatColorArgument("chatcolor")) + .withArguments(new ChatColorArgument("chatcolor")) .executesPlayer((player, args) -> { NamedTextColor color = (NamedTextColor) args.get("chatcolor"); player.displayName(Component.text().color(color).append(Component.text(player.getName())).build()); @@ -28,10 +29,10 @@ class AdventureChatArguments { // #region componentExample new CommandAPICommand("showbook") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new TextArgument("title")) .withArguments(new StringArgument("author")) - .withArguments(new AdventureChatComponentArgument("contents")) + .withArguments(new ChatComponentArgument("contents")) .executes((sender, args) -> { Player target = (Player) args.get("target"); String title = (String) args.get("title"); @@ -47,13 +48,12 @@ class AdventureChatArguments { // #region chatArgumentExample new CommandAPICommand("pbroadcast") - .withArguments(new AdventureChatArgument("message")) + .withArguments(new ChatArgument("message")) .executes((sender, args) -> { - Component message = (Component) args.get("message"); + SignedMessage message = (SignedMessage) args.get("message"); - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS); - Bukkit.getServer().broadcast(message); + // Sends the message as if it was sent by a player + Bukkit.getServer().sendMessage(message, ChatType.CHAT.bind(Component.text(sender.getName()))); }) .register(); // #endregion chatArgumentExample diff --git a/reference-code/paper/src/main/java/createcommands/functionsandtags/Functions.java b/reference-code/paper/src/main/java/createcommands/functionsandtags/Functions.java new file mode 100644 index 000000000..f6f6ffc21 --- /dev/null +++ b/reference-code/paper/src/main/java/createcommands/functionsandtags/Functions.java @@ -0,0 +1,25 @@ +package createcommands.functionsandtags; + +import dev.jorel.commandapi.CommandAPICommand; +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +class Functions { + // #region functionsExample + public class MainBoostrap implements PluginBootstrap { + @Override + public void bootstrap(BootstrapContext context) { + // Commands which will be used in Minecraft functions are registered here + + new CommandAPICommand("killall") + .executes((sender, args) -> { + // Kills all enemies in all worlds + Bukkit.getWorlds().forEach(w -> w.getLivingEntities().forEach(e -> e.setHealth(0))); + }) + .register(); + } + } + // #endregion functionsExample +} diff --git a/reference-code/paper/src/main/java/devsetup/Shading.java b/reference-code/paper/src/main/java/devsetup/Shading.java new file mode 100644 index 000000000..4e89b3a13 --- /dev/null +++ b/reference-code/paper/src/main/java/devsetup/Shading.java @@ -0,0 +1,42 @@ +package devsetup; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaperConfig; +import org.bukkit.plugin.java.JavaPlugin; + +class Shading { + static { + JavaPlugin plugin = null; + // #region bukkitConfigExample + CommandAPI.onLoad(new CommandAPIPaperConfig(plugin).silentLogs(true)); + // #endregion bukkitConfigExample + } + + // #region shadingExample + class MyPlugin extends JavaPlugin { + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIPaperConfig(this).verboseOutput(true)); // Load with verbose output + + new CommandAPICommand("ping") + .executes((sender, args) -> { + sender.sendMessage("pong!"); + }) + .register(); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + // Register commands, listeners etc. + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } + } + // #endregion shadingExample +} diff --git a/reference-code/paper/src/main/kotlin/createcommands/Unregistration.kt b/reference-code/paper/src/main/kotlin/createcommands/Unregistration.kt new file mode 100644 index 000000000..f1cf3570a --- /dev/null +++ b/reference-code/paper/src/main/kotlin/createcommands/Unregistration.kt @@ -0,0 +1,122 @@ +package createcommands + +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPIBukkit +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPIPaperConfig +import dev.jorel.commandapi.arguments.MultiLiteralArgument +import dev.jorel.commandapi.executors.CommandExecutor +import io.papermc.paper.plugin.bootstrap.BootstrapContext +import io.papermc.paper.plugin.bootstrap.PluginBootstrap +import net.kyori.adventure.text.Component +import org.bukkit.plugin.java.JavaPlugin +import org.bukkit.scheduler.BukkitRunnable + +class UnregistrationKT { + + // #region registerBootstrapExample + class MyPluginBootstrap : PluginBootstrap { + + override fun bootstrap(context: BootstrapContext) { + CommandAPI.onLoad(CommandAPIPaperConfig(context)) + + CommandAPICommand("inbootstrap") + .executes(CommandExecutor { sender, _ -> + sender.sendMessage(Component.text("This command is registed in step 3!")) + }) + .register() + } + } + // #endregion registerBootstrapExample + + class A : JavaPlugin() { + // #region unregisterBukkitExample + override fun onLoad() { + CommandAPIBukkit.unregister("version", true, true) + } + // #endregion unregisterBukkitExample + } + + class B : JavaPlugin() { + // #region unregisterVanillaExample + override fun onEnable() { + CommandAPI.unregister("gamemode") + } + // #endregion unregisterVanillaExample + } + + class C : JavaPlugin() { + // #region unregisterVanillaAndReplaceExample + override fun onEnable() { + // Register our new /gamemode, with survival, creative, adventure and spectator + CommandAPICommand("gamemode") + .withArguments(MultiLiteralArgument("gamemodes", "survival", "creative", "adventure", "spectator")) + .executes(CommandExecutor { sender, args -> + // Implementation of our /gamemode command + }) + .register() + } + // #endregion unregisterVanillaAndReplaceExample + } + + class D : JavaPlugin() { + // #region unregisterPluginExample + override fun onEnable() { + CommandAPIBukkit.unregister("luckperms:luckperms", false, true) + } + // #endregion unregisterPluginExample + } + + class E : JavaPlugin() { + // #region unregisterCommandAPIExample + override fun onEnable() { + CommandAPI.unregister("break") + } + // #endregion unregisterCommandAPIExample + } + + class F : JavaPlugin() { + // #region unregisterBukkitHelpExample + override fun onEnable() { + CommandAPIBukkit.unregister("help", false, true) + } + // #endregion unregisterBukkitHelpExample + } + + class G : JavaPlugin() { + // #region unregisterVanillaNamespaceOnlyExample + override fun onEnable() { + object : BukkitRunnable() { + override fun run() { + CommandAPI.unregister("minecraft:gamemode") + } + }.runTaskLater(this, 0) + } + // #endregion unregisterVanillaNamespaceOnlyExample + } + + class H : JavaPlugin() { + // #region unregisterDelayedVanillaBadExample + // NOT RECOMMENDED + override fun onEnable() { + object : BukkitRunnable() { + override fun run() { + CommandAPI.unregister("gamemode") + } + }.runTaskLater(this, 0) + } + // #endregion unregisterDelayedVanillaBadExample + } + + class I : JavaPlugin() { + // #region unregisterDelayedVanillaGoodExample + override fun onEnable() { + object : BukkitRunnable() { + override fun run() { + CommandAPI.unregister("gamemode", true) + } + }.runTaskLater(this, 0) + } + // #endregion unregisterDelayedVanillaGoodExample + } +} \ No newline at end of file diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt rename to reference-code/paper/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt similarity index 78% rename from reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt rename to reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt index b36173bea..f00b48921 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt +++ b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt @@ -1,23 +1,12 @@ package createcommands.arguments.types +import com.destroystokyo.paper.profile.PlayerProfile import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.arguments.AsyncOfflinePlayerArgument -import dev.jorel.commandapi.arguments.EntitySelectorArgument -import dev.jorel.commandapi.arguments.EntityTypeArgument -import dev.jorel.commandapi.arguments.IntegerArgument -import dev.jorel.commandapi.arguments.PlayerArgument -import dev.jorel.commandapi.arguments.SafeSuggestions +import dev.jorel.commandapi.arguments.* import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.executors.PlayerCommandExecutor -import dev.jorel.commandapi.kotlindsl.anyExecutor -import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.asyncOfflinePlayerArgument -import dev.jorel.commandapi.kotlindsl.entitySelectorArgumentManyEntities -import dev.jorel.commandapi.kotlindsl.entityTypeArgument -import dev.jorel.commandapi.kotlindsl.integerArgument -import dev.jorel.commandapi.kotlindsl.playerExecutor +import dev.jorel.commandapi.kotlindsl.* import org.bukkit.Bukkit -import org.bukkit.OfflinePlayer import org.bukkit.entity.Entity import org.bukkit.entity.EntityType import org.bukkit.entity.Player @@ -41,9 +30,9 @@ fun entitiesArguments() { // #endregion entitySelectorArgumentExample // #region buildNoSelectorSuggestions - val noSelectorSuggestions = PlayerArgument("target") - .replaceSafeSuggestions(SafeSuggestions.suggest { - Bukkit.getOnlinePlayers().toTypedArray() + val noSelectorSuggestions = PlayerProfileArgument("target") + .replaceSafeSuggestions(SafeSuggestions.suggest { info -> + Bukkit.getOnlinePlayers().map { player -> player.playerProfile }.toTypedArray() }) // #endregion buildNoSelectorSuggestions @@ -59,15 +48,15 @@ fun entitiesArguments() { // #region playedBeforeArgumentExample CommandAPICommand("playedbefore") - .withArguments(AsyncOfflinePlayerArgument("player")) + .withArguments(AsyncPlayerProfileArgument("player")) .executes(CommandExecutor { sender, args -> - val player = args["player"] as CompletableFuture + val profiles = args["player"] as CompletableFuture> // Directly sends a message to the sender, indicating that the command is running to prevent confusion sender.sendMessage("Checking if the player has played before...") - player.thenAccept { offlinePlayer -> - if (offlinePlayer.hasPlayedBefore()) { + profiles.thenAccept { profileList -> + if (Bukkit.getPlayer(profileList.first().id!!)!!.hasPlayedBefore()) { sender.sendMessage("Player has played before") } else { sender.sendMessage("Player has never played before") @@ -116,15 +105,15 @@ fun entitiesArgumentsDSL() { // #region playedBeforeArgumentExampleDSL commandAPICommand("playedbefore") { - asyncOfflinePlayerArgument("player") + asyncPlayerProfileArgument("player") anyExecutor { sender, args -> - val player = args["player"] as CompletableFuture + val profiles = args["player"] as CompletableFuture> // Directly sends a message to the sender, indicating that the command is running to prevent confusion sender.sendMessage("Checking if the player has played before...") - player.thenAccept { offlinePlayer -> - if (offlinePlayer.hasPlayedBefore()) { + profiles.thenAccept { profileList -> + if (Bukkit.getPlayer(profileList.first().id!!)!!.hasPlayedBefore()) { sender.sendMessage("Player has played before") } else { sender.sendMessage("Player has never played before") diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt similarity index 93% rename from reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt rename to reference-code/paper/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt index 5a5758f85..5ebf427f9 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt +++ b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt @@ -2,8 +2,8 @@ package createcommands.arguments.types import de.tr7zw.changeme.nbtapi.NBTContainer import dev.jorel.commandapi.CommandAPI -import dev.jorel.commandapi.CommandAPIBukkitConfig import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPIPaperConfig import dev.jorel.commandapi.arguments.NBTCompoundArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.kotlindsl.anyExecutor @@ -14,7 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin val nbtArguments = object : JavaPlugin() { // #region hookNbtAPIExample override fun onLoad() { - CommandAPI.onLoad(CommandAPIBukkitConfig(this) + CommandAPI.onLoad(CommandAPIPaperConfig(this) .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) ) } diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt similarity index 61% rename from reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt rename to reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt index 15f1d117a..331b7ae07 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt +++ b/reference-code/paper/src/main/kotlin/createcommands/arguments/types/chat/AdventureChatArguments.kt @@ -1,34 +1,22 @@ package createcommands.arguments.types.chat import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.arguments.AdventureChatArgument -import dev.jorel.commandapi.arguments.AdventureChatColorArgument -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument -import dev.jorel.commandapi.arguments.PlayerArgument -import dev.jorel.commandapi.arguments.StringArgument -import dev.jorel.commandapi.arguments.TextArgument +import dev.jorel.commandapi.arguments.* import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.executors.PlayerCommandExecutor -import dev.jorel.commandapi.kotlindsl.adventureChatArgument -import dev.jorel.commandapi.kotlindsl.adventureChatComponentArgument -import dev.jorel.commandapi.kotlindsl.anyExecutor -import dev.jorel.commandapi.kotlindsl.chatColorArgument -import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.playerArgument -import dev.jorel.commandapi.kotlindsl.playerExecutor -import dev.jorel.commandapi.kotlindsl.stringArgument -import dev.jorel.commandapi.kotlindsl.textArgument +import dev.jorel.commandapi.kotlindsl.* +import net.kyori.adventure.chat.ChatType +import net.kyori.adventure.chat.SignedMessage import net.kyori.adventure.inventory.Book import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.Bukkit -import org.bukkit.Server import org.bukkit.entity.Player fun adventureChatArguments() { // #region namedTextColorExample CommandAPICommand("namecolor") - .withArguments(AdventureChatColorArgument("chatcolor")) + .withArguments(ChatColorArgument("chatcolor")) .executesPlayer(PlayerCommandExecutor { player, args -> val color = args["chatcolor"] as NamedTextColor player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) @@ -38,10 +26,10 @@ fun adventureChatArguments() { // #region componentExample CommandAPICommand("showbook") - .withArguments(PlayerArgument("target")) + .withArguments(EntitySelectorArgument.OnePlayer("target")) .withArguments(TextArgument("title")) .withArguments(StringArgument("author")) - .withArguments(AdventureChatComponentArgument("contents")) + .withArguments(ChatComponentArgument("contents")) .executes(CommandExecutor { _, args -> val target = args["target"] as Player val title = args["title"] as String @@ -57,13 +45,12 @@ fun adventureChatArguments() { // #region chatArgumentExample CommandAPICommand("pbroadcast") - .withArguments(AdventureChatArgument("message")) - .executes(CommandExecutor { _, args -> - val message = args["message"] as Component + .withArguments(ChatArgument("message")) + .executesPlayer(PlayerCommandExecutor { sender, args -> + val message = args["message"] as SignedMessage - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) - Bukkit.getServer().broadcast(message) + // Sends the message as if it was sent by a player + Bukkit.getServer().sendMessage(message, ChatType.CHAT.bind(Component.text(sender.name))) }) .register() // #endregion chatArgumentExample @@ -82,10 +69,10 @@ fun adventureChatArgumentsDSL() { // #region componentExampleDSL commandAPICommand("showbook") { - playerArgument("target") + entitySelectorArgumentOnePlayer("target") textArgument("title") stringArgument("author") - adventureChatComponentArgument("contents") + chatComponentArgument("contents") anyExecutor { _, args -> val target = args["target"] as Player val title = args["title"] as String @@ -101,13 +88,12 @@ fun adventureChatArgumentsDSL() { // #region chatArgumentExampleDSL commandAPICommand("pbroadcast") { - adventureChatArgument("message") - anyExecutor { _, args -> + chatArgument("message") + playerExecutor { sender, args -> val message = args["message"] as Component - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) - Bukkit.getServer().broadcast(message) + // Sends the message as if it was sent by a player + Bukkit.getServer().sendMessage(message, ChatType.CHAT.bind(Component.text(sender.name))) } } // #endregion chatArgumentExampleDSL diff --git a/reference-code/paper/src/main/kotlin/createcommands/functionsandtags/Functions.kt b/reference-code/paper/src/main/kotlin/createcommands/functionsandtags/Functions.kt new file mode 100644 index 000000000..8d59c198d --- /dev/null +++ b/reference-code/paper/src/main/kotlin/createcommands/functionsandtags/Functions.kt @@ -0,0 +1,23 @@ +package createcommands.functionsandtags + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.executors.CommandExecutor +import io.papermc.paper.plugin.bootstrap.BootstrapContext +import io.papermc.paper.plugin.bootstrap.PluginBootstrap +import org.bukkit.Bukkit +import org.bukkit.plugin.java.JavaPlugin + +// #region functionsExample +class MainBootstrap : PluginBootstrap { + override fun bootstrap(context: BootstrapContext) { + // Commands which will be used in Minecraft functions are registered here + + CommandAPICommand("killall") + .executes(CommandExecutor { _, _ -> + // Kills all enemies in all worlds + Bukkit.getWorlds().forEach { world -> world.livingEntities.forEach { entity -> entity.health = 0.0 } } + }) + .register() + } +} +// #endregion functionsExample \ No newline at end of file diff --git a/reference-code/paper/src/main/kotlin/devsetup/Shading.kt b/reference-code/paper/src/main/kotlin/devsetup/Shading.kt new file mode 100644 index 000000000..d81636f96 --- /dev/null +++ b/reference-code/paper/src/main/kotlin/devsetup/Shading.kt @@ -0,0 +1,39 @@ +package devsetup + +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPIBukkitConfig +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPIPaperConfig +import dev.jorel.commandapi.executors.CommandExecutor +import org.bukkit.plugin.java.JavaPlugin + +class KotlinShadingPlugin : JavaPlugin() +fun shading() { + val plugin: JavaPlugin = KotlinShadingPlugin() + // #region bukkitConfigExample + CommandAPI.onLoad(CommandAPIPaperConfig(plugin).silentLogs(true)) + // #endregion bukkitConfigExample +} + +// #region shadingExample +class MyPlugin : JavaPlugin() { + override fun onLoad() { + CommandAPI.onLoad(CommandAPIPaperConfig(this).verboseOutput(true)) // Load with verbose output + + CommandAPICommand("ping") + .executes(CommandExecutor { sender, _ -> + sender.sendMessage("pong!") + }) + .register() + } + + override fun onEnable() { + CommandAPI.onEnable() + // Register commands, listeners etc. + } + + override fun onDisable() { + CommandAPI.onDisable() + } +} +// #endregion shadingExample \ No newline at end of file diff --git a/reference-code/src/test/java/test/LoadMockCommandAPI.java b/reference-code/paper/src/test/java/test/LoadMockCommandAPI.java similarity index 62% rename from reference-code/src/test/java/test/LoadMockCommandAPI.java rename to reference-code/paper/src/test/java/test/LoadMockCommandAPI.java index d0eea185b..4b7da39bb 100644 --- a/reference-code/src/test/java/test/LoadMockCommandAPI.java +++ b/reference-code/paper/src/test/java/test/LoadMockCommandAPI.java @@ -1,15 +1,24 @@ package test; -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; -import createcommands.functionsandtags.Main; -import dev.jorel.commandapi.CommandAPI; +import com.mojang.brigadier.CommandDispatcher; import dev.jorel.commandapi.CommandAPIVersionHandler; -import dev.jorel.commandapi.MockCommandAPIBukkit; +import dev.jorel.commandapi.MockCommandAPIPaper; import dev.jorel.commandapi.MockCommandAPIPlugin; +import dev.jorel.commandapi.MockCommandSource; +import dev.jorel.commandapi.nms.MockPaperNMS; +import org.bukkit.plugin.java.JavaPlugin; import org.junit.jupiter.api.BeforeEach; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; + +import java.io.File; +import java.io.IOException; class LoadMockCommandAPI { + class Main extends JavaPlugin { + + } + // #region loadMockCommandAPIExample @BeforeEach public void setUp() { @@ -34,12 +43,11 @@ public void tearDown() { class CustomExample { // #region loadCustomCommandAPIPlatformImplementationExample - public class CustomMockCommandAPIBukkit extends MockCommandAPIBukkit { + public class CustomMockPaperNMS extends MockPaperNMS { // Implement a method that usually throws `UnimplementedMethodException` @Override - public void reloadDataPacks() { - CommandAPI.logInfo("Simulating data pack reload"); - // Further logic + public void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException { + // Whatever logic you need } } @@ -49,7 +57,9 @@ public void setUp() { MockBukkit.mock(); // Tell the CommandAPI to use your custom platform implementation - CommandAPIVersionHandler.usePlatformImplementation(new CustomMockCommandAPIBukkit()); + CommandAPIVersionHandler.usePlatformImplementation( + config -> new MockCommandAPIPaper(config, new CustomMockPaperNMS()) + ); // Load CommandAPI and your plugin as mentioned above... } diff --git a/reference-code/settings.gradle.kts b/reference-code/settings.gradle.kts index dd893de42..a434001ff 100644 --- a/reference-code/settings.gradle.kts +++ b/reference-code/settings.gradle.kts @@ -3,3 +3,7 @@ */ rootProject.name = "reference-code" +include("bukkit") +include("paper") +include("spigot") +include("velocity") diff --git a/reference-code/spigot/build.gradle.kts b/reference-code/spigot/build.gradle.kts new file mode 100644 index 000000000..da4ac8853 --- /dev/null +++ b/reference-code/spigot/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + common +} + +group = "dev.jorel.commandapi" +version = "1.0-SNAPSHOT" +description = "reference-code-spigot" + +val commandApiVersion: String by project +val spigotVersion: String by project + +dependencies { + implementation("dev.jorel:commandapi-spigot-core:$commandApiVersion") + implementation("dev.jorel:commandapi-kotlin-spigot:$commandApiVersion") + implementation("org.spigotmc:spigot-api:$spigotVersion") + + testImplementation("dev.jorel:commandapi-spigot-test-toolkit:${commandApiVersion}") +} \ No newline at end of file diff --git a/reference-code/src/main/java/createcommands/Unregistration.java b/reference-code/spigot/src/main/java/createcommands/Unregistration.java similarity index 100% rename from reference-code/src/main/java/createcommands/Unregistration.java rename to reference-code/spigot/src/main/java/createcommands/Unregistration.java diff --git a/reference-code/spigot/src/main/java/createcommands/arguments/types/CustomArguments.java b/reference-code/spigot/src/main/java/createcommands/arguments/types/CustomArguments.java new file mode 100644 index 000000000..5cbfe4102 --- /dev/null +++ b/reference-code/spigot/src/main/java/createcommands/arguments/types/CustomArguments.java @@ -0,0 +1,44 @@ +package createcommands.arguments.types; + +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.CustomArgument; +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; +import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder; +import dev.jorel.commandapi.arguments.StringArgument; +import org.bukkit.Bukkit; +import org.bukkit.World; + +class CustomArguments { + // #region declareCustomArgumentsExample + // Function that returns our custom argument + public Argument customWorldArgument(String nodeName) { + // Construct our CustomArgument that takes in a String input and returns a World object + return new CustomArgument(new StringArgument(nodeName), info -> { + // Parse the world from our input + World world = Bukkit.getWorld(info.input()); + + if (world == null) { + throw CustomArgumentException.fromMessageBuilder(new MessageBuilder("Unknown world: ").appendArgInput()); + } else { + return world; + } + }).replaceSuggestions(ArgumentSuggestions.strings(info -> + // List of world names on the server + Bukkit.getWorlds().stream().map(World::getName).toArray(String[]::new)) + ); + } + // #endregion declareCustomArgumentsExample + + { + // #region useCustomArgumentsExample + new CommandAPICommand("tpworld") + .withArguments(customWorldArgument("world")) + .executesPlayer((player, args) -> { + player.teleport(((World) args.get("world")).getSpawnLocation()); + }) + .register(); + // #endregion useCustomArgumentsExample + } +} diff --git a/reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java b/reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java similarity index 83% rename from reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java rename to reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java index e7c828c6a..5e5b9ce1d 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/EntitiesArguments.java +++ b/reference-code/spigot/src/main/java/createcommands/arguments/types/EntitiesArguments.java @@ -2,20 +2,21 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.AsyncOfflinePlayerArgument; +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument; import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.EntityTypeArgument; import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; import dev.jorel.commandapi.arguments.SafeSuggestions; import dev.jorel.commandapi.executors.CommandArguments; import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.profile.PlayerProfile; import java.util.Collection; +import java.util.List; import java.util.concurrent.CompletableFuture; class EntitiesArguments { @@ -38,9 +39,9 @@ class EntitiesArguments { // #endregion entitySelectorArgumentExample // #region buildNoSelectorSuggestions - Argument noSelectorSuggestions = new PlayerArgument("target") + Argument noSelectorSuggestions = new PlayerProfileArgument("target") .replaceSafeSuggestions(SafeSuggestions.suggest(info -> - Bukkit.getOnlinePlayers().toArray(new Player[0]) + Bukkit.getOnlinePlayers().stream().map(Player::getPlayerProfile).toArray(PlayerProfile[]::new) )); // #endregion buildNoSelectorSuggestions @@ -56,15 +57,15 @@ class EntitiesArguments { // #region playedBeforeArgumentExample new CommandAPICommand("playedbefore") - .withArguments(new AsyncOfflinePlayerArgument("player")) + .withArguments(new AsyncPlayerProfileArgument("player")) .executes((sender, args) -> { - CompletableFuture player = (CompletableFuture) args.get("player"); + CompletableFuture> profiles = (CompletableFuture>) args.get("player"); // Directly sends a message to the sender, indicating that the command is running to prevent confusion sender.sendMessage("Checking if the player has played before..."); - player.thenAccept(offlinePlayer -> { - if (offlinePlayer.hasPlayedBefore()) { + profiles.thenAccept(profileList -> { + if (Bukkit.getOfflinePlayer(profileList.getFirst().getUniqueId()).hasPlayedBefore()) { sender.sendMessage("Player has played before"); } else { sender.sendMessage("Player has never played before"); diff --git a/reference-code/spigot/src/main/java/createcommands/arguments/types/NBTArguments.java b/reference-code/spigot/src/main/java/createcommands/arguments/types/NBTArguments.java new file mode 100644 index 000000000..2ab08bd92 --- /dev/null +++ b/reference-code/spigot/src/main/java/createcommands/arguments/types/NBTArguments.java @@ -0,0 +1,33 @@ +package createcommands.arguments.types; + +import de.tr7zw.changeme.nbtapi.NBTContainer; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPISpigotConfig; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import org.bukkit.plugin.java.JavaPlugin; + +class NBTArguments { + { + new JavaPlugin() { + // #region hookNbtAPIExample + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPISpigotConfig(this) + .initializeNBTAPI(NBTContainer.class, NBTContainer::new) + ); + } + // #endregion hookNbtAPIExample + }; + + // #region nbtCompoundArgumentsExample + new CommandAPICommand("award") + .withArguments(new NBTCompoundArgument("nbt")) + .executes((sender, args) -> { + NBTContainer nbt = (NBTContainer) args.get("nbt"); + // Do something with "nbt" here... + }) + .register(); + // #endregion nbtCompoundArgumentsExample + } +} diff --git a/reference-code/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java b/reference-code/spigot/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java similarity index 94% rename from reference-code/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java rename to reference-code/spigot/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java index 04e52427f..a9d136e38 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java +++ b/reference-code/spigot/src/main/java/createcommands/arguments/types/chat/SpigotChatArguments.java @@ -4,7 +4,7 @@ import dev.jorel.commandapi.arguments.ChatArgument; import dev.jorel.commandapi.arguments.ChatColorArgument; import dev.jorel.commandapi.arguments.ChatComponentArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -27,7 +27,7 @@ class SpigotChatArguments { // #region setPagesExample new CommandAPICommand("makebook") - .withArguments(new PlayerArgument("player")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) .withArguments(new ChatComponentArgument("contents")) .executes((sender, args) -> { Player player = (Player) args.get("player"); diff --git a/reference-code/src/main/java/createcommands/functionsandtags/Functions.java b/reference-code/spigot/src/main/java/createcommands/functionsandtags/Functions.java similarity index 76% rename from reference-code/src/main/java/createcommands/functionsandtags/Functions.java rename to reference-code/spigot/src/main/java/createcommands/functionsandtags/Functions.java index 729f93e89..3adb13875 100644 --- a/reference-code/src/main/java/createcommands/functionsandtags/Functions.java +++ b/reference-code/spigot/src/main/java/createcommands/functionsandtags/Functions.java @@ -9,8 +9,6 @@ class Functions { public class Main extends JavaPlugin { @Override public void onLoad() { - // Commands which will be used in Minecraft functions are registered here - new CommandAPICommand("killall") .executes((sender, args) -> { // Kills all enemies in all worlds @@ -18,11 +16,6 @@ public void onLoad() { }) .register(); } - - @Override - public void onEnable() { - // Register all other commands here - } } // #endregion functionsExample } diff --git a/reference-code/src/main/java/devsetup/Shading.java b/reference-code/spigot/src/main/java/devsetup/Shading.java similarity index 84% rename from reference-code/src/main/java/devsetup/Shading.java rename to reference-code/spigot/src/main/java/devsetup/Shading.java index 734ff0200..270ce435e 100644 --- a/reference-code/src/main/java/devsetup/Shading.java +++ b/reference-code/spigot/src/main/java/devsetup/Shading.java @@ -3,13 +3,14 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIBukkitConfig; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPISpigotConfig; import org.bukkit.plugin.java.JavaPlugin; class Shading { static { JavaPlugin plugin = null; // #region bukkitConfigExample - CommandAPI.onLoad(new CommandAPIBukkitConfig(plugin).silentLogs(true)); + CommandAPI.onLoad(new CommandAPISpigotConfig(plugin).silentLogs(true)); // #endregion bukkitConfigExample } @@ -17,7 +18,7 @@ class Shading { class MyPlugin extends JavaPlugin { @Override public void onLoad() { - CommandAPI.onLoad(new CommandAPIBukkitConfig(this).verboseOutput(true)); // Load with verbose output + CommandAPI.onLoad(new CommandAPISpigotConfig(this).verboseOutput(true)); // Load with verbose output new CommandAPICommand("ping") .executes((sender, args) -> { diff --git a/reference-code/src/main/kotlin/createcommands/Unregistration.kt b/reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt similarity index 100% rename from reference-code/src/main/kotlin/createcommands/Unregistration.kt rename to reference-code/spigot/src/main/kotlin/createcommands/Unregistration.kt diff --git a/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt new file mode 100644 index 000000000..15dd32460 --- /dev/null +++ b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/CustomArguments.kt @@ -0,0 +1,57 @@ +package createcommands.arguments.types + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.Argument +import dev.jorel.commandapi.arguments.ArgumentSuggestions +import dev.jorel.commandapi.arguments.CustomArgument +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException +import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder +import dev.jorel.commandapi.arguments.StringArgument +import dev.jorel.commandapi.executors.PlayerCommandExecutor +import dev.jorel.commandapi.kotlindsl.commandAPICommand +import dev.jorel.commandapi.kotlindsl.playerExecutor +import org.bukkit.Bukkit +import org.bukkit.World + +// #region declareCustomArgumentsExample +// Function that returns our custom argument +fun worldArgument(nodeName: String): Argument { + // Construct our CustomArgument that takes in a String input and returns a World object + return CustomArgument(StringArgument(nodeName)) { info -> + // Parse the world from our input + val world = Bukkit.getWorld(info.input()) + + if (world == null) { + throw CustomArgumentException.fromMessageBuilder(MessageBuilder("Unknown world: ").appendArgInput()) + } else { + world + } + }.replaceSuggestions(ArgumentSuggestions.strings { _ -> + // List of world names on the server + Bukkit.getWorlds().map{ it.name }.toTypedArray() + }) +} +// #endregion declareCustomArgumentsExample + + +fun customArguments() { + // #region useCustomArgumentsExample + CommandAPICommand("tpworld") + .withArguments(worldArgument("world")) + .executesPlayer(PlayerCommandExecutor { player, args -> + player.teleport((args["world"] as World).spawnLocation) + }) + .register() + // #endregion useCustomArgumentsExample +} + +fun customArgumentsDSL() { + // #region useCustomArgumentsExampleDSL + commandAPICommand("tpworld") { + worldArgument("world") // This method is actually also built into the Kotlin DSL + playerExecutor { player, args -> + player.teleport((args["world"] as World).spawnLocation) + } + } + // #endregion useCustomArgumentsExampleDSL +} \ No newline at end of file diff --git a/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt new file mode 100644 index 000000000..468fc3d9f --- /dev/null +++ b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/EntitiesArguments.kt @@ -0,0 +1,144 @@ +package createcommands.arguments.types + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.* +import dev.jorel.commandapi.executors.CommandExecutor +import dev.jorel.commandapi.executors.PlayerCommandExecutor +import dev.jorel.commandapi.kotlindsl.* +import org.bukkit.Bukkit +import org.bukkit.entity.Entity +import org.bukkit.entity.EntityType +import org.bukkit.entity.Player +import org.bukkit.profile.PlayerProfile +import java.util.concurrent.CompletableFuture + +fun entitiesArguments() { + // #region entitySelectorArgumentExample + CommandAPICommand("remove") + // Using a collective entity selector to select multiple entities + .withArguments(EntitySelectorArgument.ManyEntities("entities")) + .executes(CommandExecutor { sender, args -> + // Parse the argument as a collection of entities (as stated above in the documentation) + val entities = args["entities"] as Collection + + sender.sendMessage("Removed ${entities.size} entities") + for (e in entities) { + e.remove() + } + }) + .register() + // #endregion entitySelectorArgumentExample + + // #region buildNoSelectorSuggestions + val noSelectorSuggestions = PlayerProfileArgument("target") + .replaceSafeSuggestions(SafeSuggestions.suggest { info -> + Bukkit.getOnlinePlayers().map { player -> player.playerProfile }.toTypedArray() + }) + // #endregion buildNoSelectorSuggestions + + // #region noSelectorSuggestionsExample + CommandAPICommand("warp") + .withArguments(noSelectorSuggestions) + .executesPlayer(PlayerCommandExecutor { player, args -> + val target = args["target"] as Player + player.teleport(target) + }) + .register() + // #endregion noSelectorSuggestionsExample + + // #region playedBeforeArgumentExample + CommandAPICommand("playedbefore") + .withArguments(AsyncPlayerProfileArgument("player")) + .executes(CommandExecutor { sender, args -> + val profiles = args["player"] as CompletableFuture> + + // Directly sends a message to the sender, indicating that the command is running to prevent confusion + sender.sendMessage("Checking if the player has played before...") + + profiles.thenAccept { profileList -> + if (Bukkit.getPlayer(profileList.first().uniqueId!!)!!.hasPlayedBefore()) { + sender.sendMessage("Player has played before") + } else { + sender.sendMessage("Player has never played before") + } + }.exceptionally { throwable -> + // We have to partly handle exceptions ourselves, since we are using a CompletableFuture + val cause = throwable.cause + val rootCause = if (cause is RuntimeException) cause.cause else cause + + sender.sendMessage(rootCause?.message ?: "An error occurred") + null + } + }) + .register() + // #endregion playedBeforeArgumentExample + + // #region entityTypeArgumentExample + CommandAPICommand("spawnmob") + .withArguments(EntityTypeArgument("entity")) + .withArguments(IntegerArgument("amount", 1, 100)) // Prevent spawning too many entities + .executesPlayer(PlayerCommandExecutor { player, args -> + for (i in 0 until args["amount"] as Int) { + player.world.spawnEntity(player.location, args["entity"] as EntityType) + } + }) + .register() + // #endregion entityTypeArgumentExample +} + +fun entitiesArgumentsDSL() { + // #region entitySelectorArgumentExampleDSL + commandAPICommand("remove") { + // Using a collective entity selector to select multiple entities + entitySelectorArgumentManyEntities("entities") + anyExecutor { sender, args -> + // Parse the argument as a collection of entities (as stated above in the documentation) + val entities = args["entities"] as Collection + + sender.sendMessage("Removed ${entities.size} entities") + for (e in entities) { + e.remove() + } + } + } + // #endregion entitySelectorArgumentExampleDSL + + // #region playedBeforeArgumentExampleDSL + commandAPICommand("playedbefore") { + asyncPlayerProfileArgument("player") + anyExecutor { sender, args -> + val profiles = args["player"] as CompletableFuture> + + // Directly sends a message to the sender, indicating that the command is running to prevent confusion + sender.sendMessage("Checking if the player has played before...") + + profiles.thenAccept { profileList -> + if (Bukkit.getPlayer(profileList.first().uniqueId!!)!!.hasPlayedBefore()) { + sender.sendMessage("Player has played before") + } else { + sender.sendMessage("Player has never played before") + } + }.exceptionally { throwable -> + // We have to partly handle exceptions ourselves, since we are using a CompletableFuture + val cause = throwable.cause + val rootCause = if (cause is RuntimeException) cause.cause else cause + + sender.sendMessage(rootCause?.message ?: "An error occurred") + null + } + } + } + // #endregion playedBeforeArgumentExampleDSL + + // #region entityTypeArgumentExampleDSL + commandAPICommand("spawnmob") { + entityTypeArgument("entity") + integerArgument("amount", 1, 100) // Prevent spawning too many entities + playerExecutor { player, args -> + for (i in 0 until args["amount"] as Int) { + player.world.spawnEntity(player.location, args["entity"] as EntityType) + } + } + } + // #endregion entityTypeArgumentExampleDSL +} \ No newline at end of file diff --git a/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt new file mode 100644 index 000000000..b7ca1deb9 --- /dev/null +++ b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt @@ -0,0 +1,46 @@ +package createcommands.arguments.types + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPISpigotConfig +import dev.jorel.commandapi.arguments.NBTCompoundArgument +import dev.jorel.commandapi.executors.CommandExecutor +import dev.jorel.commandapi.kotlindsl.anyExecutor +import dev.jorel.commandapi.kotlindsl.commandAPICommand +import dev.jorel.commandapi.kotlindsl.nbtCompoundArgument +import org.bukkit.plugin.java.JavaPlugin + +val nbtArguments = object : JavaPlugin() { + // #region hookNbtAPIExample + override fun onLoad() { + CommandAPI.onLoad(CommandAPISpigotConfig(this) + .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) + ) + } + // #endregion hookNbtAPIExample +} + +fun nbtArguments() { + // #region nbtCompoundArgumentsExample + CommandAPICommand("award") + .withArguments(NBTCompoundArgument("nbt")) + .executes(CommandExecutor { _, args -> + val nbt = args["nbt"] as NBTContainer + // Do something with "nbt" here... + }) + .register() + // #endregion nbtCompoundArgumentsExample +} + +fun nbtArgumentsDSL() { + // #region nbtCompoundArgumentsExampleDSL + commandAPICommand("award") { + nbtCompoundArgument("nbt") + anyExecutor { _, args -> + val nbt = args["nbt"] as NBTContainer + // Do something with "nbt" here... + } + } + // #endregion nbtCompoundArgumentsExampleDSL +} \ No newline at end of file diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt similarity index 87% rename from reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt rename to reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt index ec5ea83c2..93065bf0d 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt +++ b/reference-code/spigot/src/main/kotlin/createcommands/arguments/types/chat/SpigotChatArguments.kt @@ -4,16 +4,10 @@ import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.arguments.ChatArgument import dev.jorel.commandapi.arguments.ChatColorArgument import dev.jorel.commandapi.arguments.ChatComponentArgument -import dev.jorel.commandapi.arguments.PlayerArgument +import dev.jorel.commandapi.arguments.EntitySelectorArgument import dev.jorel.commandapi.executors.CommandExecutor import dev.jorel.commandapi.executors.PlayerCommandExecutor -import dev.jorel.commandapi.kotlindsl.anyExecutor -import dev.jorel.commandapi.kotlindsl.chatArgument -import dev.jorel.commandapi.kotlindsl.chatColorArgument -import dev.jorel.commandapi.kotlindsl.chatComponentArgument -import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.playerArgument -import dev.jorel.commandapi.kotlindsl.playerExecutor +import dev.jorel.commandapi.kotlindsl.* import net.md_5.bungee.api.chat.BaseComponent import org.bukkit.Bukkit import org.bukkit.ChatColor @@ -35,7 +29,7 @@ fun spigotChatArguments() { // #region setPagesExample CommandAPICommand("makebook") - .withArguments(PlayerArgument("player")) + .withArguments(EntitySelectorArgument.OnePlayer("player")) .withArguments(ChatComponentArgument("contents")) .executes(CommandExecutor { _, args -> val player = args["player"] as Player @@ -81,7 +75,7 @@ fun spigotChatArgumentsDSL() { // #region setPagesExampleDSL commandAPICommand("makebook") { - playerArgument("player") + entitySelectorArgumentOnePlayer("player") chatComponentArgument("contents") anyExecutor { _, args -> val player = args["player"] as Player diff --git a/reference-code/src/main/kotlin/createcommands/functionsandtags/Functions.kt b/reference-code/spigot/src/main/kotlin/createcommands/functionsandtags/Functions.kt similarity index 79% rename from reference-code/src/main/kotlin/createcommands/functionsandtags/Functions.kt rename to reference-code/spigot/src/main/kotlin/createcommands/functionsandtags/Functions.kt index 3265a0aa4..5952cc0b1 100644 --- a/reference-code/src/main/kotlin/createcommands/functionsandtags/Functions.kt +++ b/reference-code/spigot/src/main/kotlin/createcommands/functionsandtags/Functions.kt @@ -8,8 +8,6 @@ import org.bukkit.plugin.java.JavaPlugin // #region functionsExample class Main : JavaPlugin() { override fun onLoad() { - // Commands which will be used in Minecraft functions are registered here - CommandAPICommand("killall") .executes(CommandExecutor { _, _ -> // Kills all enemies in all worlds @@ -17,9 +15,5 @@ class Main : JavaPlugin() { }) .register() } - - override fun onEnable() { - // Register all other commands here - } } // #endregion functionsExample \ No newline at end of file diff --git a/reference-code/src/main/kotlin/devsetup/Shading.kt b/reference-code/spigot/src/main/kotlin/devsetup/Shading.kt similarity index 83% rename from reference-code/src/main/kotlin/devsetup/Shading.kt rename to reference-code/spigot/src/main/kotlin/devsetup/Shading.kt index 3f37a5f9d..712c2f0d1 100644 --- a/reference-code/src/main/kotlin/devsetup/Shading.kt +++ b/reference-code/spigot/src/main/kotlin/devsetup/Shading.kt @@ -3,20 +3,21 @@ package devsetup import dev.jorel.commandapi.CommandAPI import dev.jorel.commandapi.CommandAPIBukkitConfig import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPISpigotConfig import dev.jorel.commandapi.executors.CommandExecutor import org.bukkit.plugin.java.JavaPlugin fun shading() { val plugin: JavaPlugin? = null // #region bukkitConfigExample - CommandAPI.onLoad(CommandAPIBukkitConfig(plugin).silentLogs(true)) + CommandAPI.onLoad(CommandAPISpigotConfig(plugin).silentLogs(true)) // #endregion bukkitConfigExample } // #region shadingExample class MyPlugin : JavaPlugin() { override fun onLoad() { - CommandAPI.onLoad(CommandAPIBukkitConfig(this).verboseOutput(true)) // Load with verbose output + CommandAPI.onLoad(CommandAPISpigotConfig(this).verboseOutput(true)) // Load with verbose output CommandAPICommand("ping") .executes(CommandExecutor { sender, _ -> diff --git a/reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java b/reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java new file mode 100644 index 000000000..550c94fd2 --- /dev/null +++ b/reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java @@ -0,0 +1,71 @@ +package test; + + +import com.mojang.brigadier.CommandDispatcher; +import dev.jorel.commandapi.CommandAPIVersionHandler; +import dev.jorel.commandapi.InternalSpigotConfig; +import dev.jorel.commandapi.MockCommandAPIPlugin; +import dev.jorel.commandapi.MockCommandAPISpigot; +import dev.jorel.commandapi.MockCommandSource; +import org.bukkit.plugin.java.JavaPlugin; +import org.junit.jupiter.api.BeforeEach; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; + +import java.io.File; +import java.io.IOException; + +class LoadMockCommandAPI { + class Main extends JavaPlugin { + + } + + // #region loadMockCommandAPIExample + @BeforeEach + public void setUp() { + // Set up MockBukkit server + ServerMock server = MockBukkit.mock(); + + // Load the CommandAPI plugin + MockCommandAPIPlugin.load(config -> config + .missingExecutorImplementationMessage("This command cannot be run by %S") + ); + + // Load our plugin + MockBukkit.load(Main.class); + } + + @org.junit.jupiter.api.AfterEach + public void tearDown() { + // Reset for a clean slate next test + MockBukkit.unmock(); + } + // #endregion loadMockCommandAPIExample + + class CustomExample { + // #region loadCustomCommandAPIPlatformImplementationExample + public class CustomMockCommandAPISpigot extends MockCommandAPISpigot { + public CustomMockCommandAPISpigot(InternalSpigotConfig config) { + super(config); + } + + // Implement a method that usually throws `UnimplementedMethodException` + @Override + public void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException { + // Whatever logic you need + } + } + + @BeforeEach + public void setUp() { + // Set up MockBukkit server + MockBukkit.mock(); + + // Tell the CommandAPI to use your custom platform implementation + CommandAPIVersionHandler.usePlatformImplementation(CustomMockCommandAPISpigot::new); + + // Load CommandAPI and your plugin as mentioned above... + } + // #endregion loadCustomCommandAPIPlatformImplementationExample + } +} diff --git a/reference-code/src/main/java/annotations/SubcommandMethodExample.java b/reference-code/src/main/java/annotations/SubcommandMethodExample.java deleted file mode 100644 index de658408f..000000000 --- a/reference-code/src/main/java/annotations/SubcommandMethodExample.java +++ /dev/null @@ -1,22 +0,0 @@ -package annotations; - -import static annotations.WarpCommand.warps; - -class SubcommandMethodExample { - // #region subcommandMethodExample - @dev.jorel.commandapi.annotations.Subcommand("create") - @dev.jorel.commandapi.annotations.Permission("warps.create") - public static void createWarp(org.bukkit.entity.Player player, @dev.jorel.commandapi.annotations.arguments.AStringArgument String warpName) { - warps.put(warpName, player.getLocation()); - } - // #endregion subcommandMethodExample - - // #region subcommandAliasesMethodExample - @dev.jorel.commandapi.annotations.Subcommand({"teleport", "tp"}) - public static void teleport(org.bukkit.entity.Player player, @dev.jorel.commandapi.annotations.arguments.APlayerArgument org.bukkit.OfflinePlayer target) { - if (target.isOnline() && target instanceof org.bukkit.entity.Player onlineTarget) { - player.teleport(onlineTarget); - } - } - // #endregion subcommandAliasesMethodExample -} diff --git a/reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java b/reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java deleted file mode 100644 index 320908c56..000000000 --- a/reference-code/src/main/java/createcommands/arguments/types/chat/ChatPreview.java +++ /dev/null @@ -1,82 +0,0 @@ -package createcommands.arguments.types.chat; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.AdventureChatArgument; -import dev.jorel.commandapi.arguments.ChatArgument; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; - -class ChatPreview { - static { - // #region chatPreviewAdventureExample - new CommandAPICommand("broadcast") - .withArguments(new AdventureChatArgument("message").withPreview(info -> { - // Convert parsed Component to plain text - String plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput()); - - // Translate the & in plain text and generate a new Component - return LegacyComponentSerializer.legacyAmpersand().deserialize(plainText); - })) - .executesPlayer((player, args) -> { - // The user still entered a legacy text. We need to properly convert this - // to a Component by converting to plain text then to Component - String plainText = PlainTextComponentSerializer.plainText().serialize((Component) args.get("broadcast")); - Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(plainText)); - }) - .register(); - // #endregion chatPreviewAdventureExample - - // #region chatPreviewLegacyExample - new CommandAPICommand("broadcast") - .withArguments(new ChatArgument("message").withPreview(info -> { - // Convert parsed BaseComponent[] to plain text - String plainText = BaseComponent.toPlainText(info.parsedInput()); - - // Translate the & in plain text and generate a new BaseComponent[] - return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)); - })) - .executesPlayer((player, args) -> { - // The user still entered a legacy text. We need to properly convert this - // to a BaseComponent[] by converting to plain text then to BaseComponent[] - String plainText = BaseComponent.toPlainText((BaseComponent[]) args.get("message")); - Bukkit.spigot().broadcast(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText))); - }) - .register(); - // #endregion chatPreviewLegacyExample - - // #region usePreviewAdventureExample - new CommandAPICommand("broadcast") - .withArguments(new AdventureChatArgument("message").usePreview(true).withPreview(info -> { - // Convert parsed Component to plain text - String plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput()); - - // Translate the & in plain text and generate a new Component - return LegacyComponentSerializer.legacyAmpersand().deserialize(plainText); - })) - .executesPlayer((player, args) -> { - Bukkit.broadcast((Component) args.get("message")); - }) - .register(); - // #endregion usePreviewAdventureExample - - // #region usePreviewLegacyExample - new CommandAPICommand("broadcast") - .withArguments(new ChatArgument("message").usePreview(true).withPreview(info -> { - // Convert parsed BaseComponent[] to plain text - String plainText = BaseComponent.toPlainText(info.parsedInput()); - - // Translate the & in plain text and generate a new BaseComponent[] - return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)); - })) - .executesPlayer((player, args) -> { - Bukkit.spigot().broadcast((BaseComponent[]) args.get("message")); - }) - .register(); - // #endregion usePreviewLegacyExample - } -} diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt b/reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt deleted file mode 100644 index 1143a0828..000000000 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt +++ /dev/null @@ -1,82 +0,0 @@ -package createcommands.arguments.types.chat - -import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.arguments.AdventureChatArgument -import dev.jorel.commandapi.arguments.ChatArgument -import dev.jorel.commandapi.executors.PlayerCommandExecutor -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer -import net.md_5.bungee.api.chat.BaseComponent -import net.md_5.bungee.api.chat.TextComponent -import org.bukkit.Bukkit -import org.bukkit.ChatColor - -fun chatPreview() { - // #region chatPreviewAdventureExample - CommandAPICommand("broadcast") - .withArguments(AdventureChatArgument("message").withPreview { info -> - // Convert parsed Component to plain text - val plainText: String = PlainTextComponentSerializer.plainText().serialize(info.parsedInput() as Component) - - // Translate the & in plain text and generate a new Component - LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - // The user still entered a legacy text. We need to properly convert this - // to a Component by converting to plain text then to Component - val plainText: String = PlainTextComponentSerializer.plainText().serialize(args["message"] as Component) - Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(plainText)) - }) - .register() - // #endregion chatPreviewAdventureExample - - // #region chatPreviewLegacyExample - CommandAPICommand("broadcast") - .withArguments(ChatArgument("message").withPreview { info -> - // Convert parsed BaseComponent[] to plain text - val plainText: String = BaseComponent.toPlainText(*info.parsedInput() as Array) - - // Translate the & in plain text and generate a new BaseComponent[] - TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - // The user still entered a legacy text. We need to properly convert this - // to a BaseComponent[] by converting to plain text then to BaseComponent[] - val plainText: String = BaseComponent.toPlainText(*args["message"] as Array) - val baseComponents: Array = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) - Bukkit.spigot().broadcast(*baseComponents) - }) - .register() - // #endregion chatPreviewLegacyExample - - // #region usePreviewAdventureExample - CommandAPICommand("broadcast") - .withArguments(AdventureChatArgument("message").usePreview(true).withPreview { info -> - // Convert parsed Component to plain text - val plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput() as Component) - - // Translate the & in plain text and generate a new Component - LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - Bukkit.broadcast(args["message"] as Component) - }) - .register() - // #endregion usePreviewAdventureExample - - // #region usePreviewLegacyExample - CommandAPICommand("broadcast") - .withArguments(ChatArgument("message").usePreview(true).withPreview { info -> - // Convert parsed BaseComponent[] to plain text - val plainText = BaseComponent.toPlainText(*info.parsedInput() as Array) - - // Translate the & in plain text and generate a new BaseComponent[] - TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - Bukkit.spigot().broadcast(*args["message"] as Array) - }) - .register() - // #endregion usePreviewLegacyExample -} \ No newline at end of file diff --git a/reference-code/velocity/build.gradle.kts b/reference-code/velocity/build.gradle.kts new file mode 100644 index 000000000..8f9238966 --- /dev/null +++ b/reference-code/velocity/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + common +} + +group = "dev.jorel.commandapi" +version = "1.0-SNAPSHOT" +description = "reference-code-velocity" + +val commandApiVersion: String by project +val velocityVersion: String by project + +dependencies { + compileOnly("dev.jorel:commandapi-velocity-core:$commandApiVersion") + compileOnly("com.velocitypowered:velocity-api:$velocityVersion") +} \ No newline at end of file diff --git a/reference-code/src/main/java/velocity/Intro.java b/reference-code/velocity/src/main/java/velocity/Intro.java similarity index 100% rename from reference-code/src/main/java/velocity/Intro.java rename to reference-code/velocity/src/main/java/velocity/Intro.java diff --git a/reference-code/src/main/kotlin/velocity/Intro.kt b/reference-code/velocity/src/main/kotlin/velocity/Intro.kt similarity index 100% rename from reference-code/src/main/kotlin/velocity/Intro.kt rename to reference-code/velocity/src/main/kotlin/velocity/Intro.kt diff --git a/update.sh b/update.sh index c32d67fec..4fb466dc1 100644 --- a/update.sh +++ b/update.sh @@ -5,11 +5,7 @@ echo "New version:" read -r newVer # Update CommandAPI dependency versions -sed -i "s/dev-jorel-commandapi-annotations = \"$oldVer\"/dev-jorel-commandapi-annotations = \"$newVer\"/" reference-code/gradle/libs.versions.toml -sed -i "s/dev-jorel-commandapi-bukkit-core = \"$oldVer\"/dev-jorel-commandapi-bukkit-core = \"$newVer\"/" reference-code/gradle/libs.versions.toml -sed -i "s/dev-jorel-commandapi-bukkit-kotlin = \"$oldVer\"/dev-jorel-commandapi-bukkit-kotlin = \"$newVer\"/" reference-code/gradle/libs.versions.toml -sed -i "s/dev-jorel-commandapi-bukkit-test-toolkit = \"$oldVer\"/dev-jorel-commandapi-bukkit-test-toolkit = \"$newVer\"/" reference-code/gradle/libs.versions.toml -sed -i "s/dev-jorel-commandapi-velocity-shade = \"$oldVer\"/dev-jorel-commandapi-velocity-shade = \"$newVer\"/" reference-code/gradle/libs.versions.toml +sed -i "s/commandApiVersion=$oldVer/commandApiVersion=$newVer/" reference-code/gradle.properties # Update CommandAPI version in documentation files (Maven) sed -i "s/$oldVer<\/version>/$newVer<\/version>/" docs/en/dev-setup/annotations.md @@ -21,12 +17,16 @@ sed -i "s/$oldVer<\/version>/$newVer<\/version>/" docs/en/velo # Update CommandAPI version in documentation files (Gradle) sed -i "s/dev.jorel:commandapi-annotations:$oldVer/dev.jorel:commandapi-annotations:$newVer/" docs/en/dev-setup/annotations.md -sed -i "s/dev.jorel:commandapi-bukkit-core:$oldVer/dev.jorel:commandapi-bukkit-core:$newVer/" docs/en/dev-setup/setup.md -sed -i "s/dev.jorel:commandapi-bukkit-shade:$oldVer/dev.jorel:commandapi-bukkit-shade:$newVer/" docs/en/dev-setup/shading.md -sed -i "s/dev.jorel:commandapi-bukkit-shade-mojang-mapped:$oldVer/dev.jorel:commandapi-bukkit-shade-mojang-mapped:$newVer/" docs/en/dev-setup/shading.md -sed -i "s/dev.jorel:commandapi-bukkit-kotlin:$oldVer/dev.jorel:commandapi-bukkit-kotlin:$newVer/" docs/en/kotlin-dsl/intro.md -sed -i "s/dev.jorel:commandapi-bukkit-test-toolkit:$oldVer/dev.jorel:commandapi-bukkit-test-toolkit:$newVer/" docs/en/test/setup.md -sed -i "s/dev.jorel:commandapi-bukkit-core:$oldVer/dev.jorel:commandapi-bukkit-core:$newVer/" docs/en/test/setup.md +sed -i "s/dev.jorel:commandapi-paper-core:$oldVer/dev.jorel:commandapi-paper-core:$newVer/" docs/en/dev-setup/setup.md +sed -i "s/dev.jorel:commandapi-spigot-core:$oldVer/dev.jorel:commandapi-spigot-core:$newVer/" docs/en/dev-setup/setup.md +sed -i "s/dev.jorel:commandapi-paper-shade:$oldVer/dev.jorel:commandapi-paper-shade:$newVer/" docs/en/dev-setup/shading.md +sed -i "s/dev.jorel:commandapi-spigot-shade:$oldVer/dev.jorel:commandapi-spigot-shade:$newVer/" docs/en/dev-setup/shading.md +sed -i "s/dev.jorel:commandapi-kotlin-paper:$oldVer/dev.jorel:commandapi-kotlin-paper:$newVer/" docs/en/kotlin-dsl/intro.md +sed -i "s/dev.jorel:commandapi-kotlin-spigot:$oldVer/dev.jorel:commandapi-kotlin-spigot:$newVer/" docs/en/kotlin-dsl/intro.md +sed -i "s/dev.jorel:commandapi-paper-core:$oldVer/dev.jorel:commandapi-paper-core:$newVer/" docs/en/test/setup.md +sed -i "s/dev.jorel:commandapi-paper-test-toolkit:$oldVer/dev.jorel:commandapi-paper-test-toolkit:$newVer/" docs/en/test/setup.md +sed -i "s/dev.jorel:commandapi-spigot-core:$oldVer/dev.jorel:commandapi-spigot-core:$newVer/" docs/en/test/setup.md +sed -i "s/dev.jorel:commandapi-spigot-test-toolkit:$oldVer/dev.jorel:commandapi-spigot-test-toolkit:$newVer/" docs/en/test/setup.md sed -i "s/dev.jorel:commandapi-velocity-shade:$oldVer/dev.jorel:commandapi-velocity-shade:$newVer/" docs/en/velocity/intro.md # Possible manual updates