|
| 1 | +--- |
| 2 | +order: 1 |
| 3 | +preferences: ['build-system'] |
| 4 | +authors: |
| 5 | + - JorelAli |
| 6 | + - DerEchtePilz |
| 7 | +--- |
| 8 | + |
| 9 | +# Velocity |
| 10 | + |
| 11 | +:::warning Developer's Note: |
| 12 | + |
| 13 | +The CommandAPI hasn't been released for Velocity yet. |
| 14 | +We do, however, offer snapshot builds. This small section on Velocity will outline how to get the snapshot builds and what limitations the CommandAPI currently has on Velocity. |
| 15 | + |
| 16 | +This page focuses on outlining how to set up the CommandAPI for Velocity. It expects that you are already familiar with how to set up a Velocity plugin. |
| 17 | + |
| 18 | +::: |
| 19 | + |
| 20 | +## Adding the snapshot repository with Maven or Gradle |
| 21 | + |
| 22 | +Because we do not have an official release yet, the snapshot builds are not published in the Maven Central repository. Instead you need to add our snapshot repository: |
| 23 | + |
| 24 | +<div class="maven"> |
| 25 | + |
| 26 | +```xml |
| 27 | +<repositories> |
| 28 | + <repository> |
| 29 | + <id>oss.sonatype.org-snapshot</id> |
| 30 | + <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> |
| 31 | + </repository> |
| 32 | +</repositories> |
| 33 | +``` |
| 34 | + |
| 35 | +</div> |
| 36 | +<div class="gradle"> |
| 37 | + |
| 38 | +<div class="groovy"> |
| 39 | + |
| 40 | +```groovy |
| 41 | +repositories { |
| 42 | + maven { |
| 43 | + url = "https://s01.oss.sonatype.org/content/repositories/snapshots" |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +</div> |
| 49 | +<div class="kts"> |
| 50 | + |
| 51 | +```kotlin |
| 52 | +repositories { |
| 53 | + maven { |
| 54 | + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +</div> |
| 60 | + |
| 61 | +</div> |
| 62 | + |
| 63 | +## Adding the dependency |
| 64 | + |
| 65 | +As mentioned, Velocity can only be accessed with snapshot builds. These snapshot build version are following standard semantic versioning and thus have the `-SNAPSHOT` suffix: |
| 66 | + |
| 67 | +<div class="maven"> |
| 68 | + |
| 69 | +```xml |
| 70 | +<dependencies> |
| 71 | + <dependency> |
| 72 | + <groupId>dev.jorel</groupId> |
| 73 | + <artifactId>commandapi-velocity-shade</artifactId> |
| 74 | + <version>9.7.1-SNAPSHOT</version> |
| 75 | + </dependency> |
| 76 | +</dependencies> |
| 77 | +``` |
| 78 | + |
| 79 | +</div> |
| 80 | +<div class="gradle"> |
| 81 | + |
| 82 | +<div class="groovy"> |
| 83 | + |
| 84 | +```groovy |
| 85 | +dependencies { |
| 86 | + implementation "dev.jorel:commandapi-velocity-shade:9.7.1-SNAPSHOT" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +</div> |
| 91 | +<div class="kts"> |
| 92 | + |
| 93 | +```kotlin |
| 94 | +dependencies { |
| 95 | + implementation("dev.jorel:commandapi-velocity-shade:9.7.1-SNAPSHOT") |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +</div> |
| 100 | + |
| 101 | +</div> |
| 102 | + |
| 103 | +## Setting up the CommandAPI |
| 104 | + |
| 105 | +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). |
| 106 | +We will perform the CommandAPI's loading step in the construction phase first: |
| 107 | + |
| 108 | +<<< @/../reference-code/src/main/java/velocity/Intro.java#loadCommandAPIExample |
| 109 | + |
| 110 | +Next, we want to utilize Velocity's `ProxyInitializeEvent` to perform the CommandAPI's enabling step: |
| 111 | + |
| 112 | + |
| 113 | +<<< @/../reference-code/src/main/java/velocity/Intro.java#enableCommandAPIExample |
| 114 | + |
| 115 | +## Current limitations |
| 116 | + |
| 117 | +The CommandAPI currently only offers support for a very limited amount of arguments on Velocity. This is because arguments are primarily implemented on the backend servers. |
| 118 | +However, the CommandAPI offers access for the primitive type arguments: |
| 119 | + |
| 120 | +- [`IntegerArgument`](../create-commands/arguments/types/primitive-arguments#numerical-arguments) |
| 121 | +- [`LongArgument`](../create-commands/arguments/types/primitive-arguments#numerical-arguments) |
| 122 | +- [`FloatArgument`](../create-commands/arguments/types/primitive-arguments#numerical-arguments) |
| 123 | +- [`DoubleArgument`](../create-commands/arguments/types/primitive-arguments#numerical-arguments) |
| 124 | +- [`BooleanArgument`](../create-commands/arguments/types/primitive-arguments#boolean-arguments) |
| 125 | +- [`StringArgument`](../create-commands/arguments/types/string-arguments#string-argument) |
| 126 | +- [`TextArgument`](../create-commands/arguments/types/string-arguments#text-argument) |
| 127 | +- [`GreedyStringArgument`](../create-commands/arguments/types/string-arguments#greedy-string-argument) |
| 128 | +- [`LiteralArgument`](../create-commands/arguments/types/literal/literal-arguments) |
| 129 | +- [`MultiLiteralArgument`](../create-commands/arguments/types/literal/multiliteral-arguments) |
| 130 | + |
| 131 | +## Registering a simple command |
| 132 | + |
| 133 | +Command registration works the same way as it does in Bukkit. To visualize this, we want to register a simple command that generates a random number between a chosen minimum and a chosen maximum value: |
| 134 | + |
| 135 | +::::tip Example – Registering a simple command |
| 136 | + |
| 137 | +We want to register the command `/randomnumber` with the following syntax: |
| 138 | + |
| 139 | +```mccmd |
| 140 | +/randomnumber <min> <max> |
| 141 | +``` |
| 142 | + |
| 143 | +To accomplish that, we register the command like this: |
| 144 | + |
| 145 | +:::tabs |
| 146 | +===Java |
| 147 | +<<< @/../reference-code/src/main/java/velocity/Intro.java#registerCommandExample |
| 148 | +===Kotlin |
| 149 | +<<< @/../reference-code/src/main/kotlin/velocity/Intro.kt#registerCommandExample |
| 150 | +::: |
| 151 | + |
| 152 | +:::: |
0 commit comments