You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/creating-your-first-command.md
+47-7Lines changed: 47 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ sidebar_label: Creating Your First Command
5
5
---
6
6
## Prerequisites
7
7
8
-
This guide assumes that you have a [plugin environment](/docs/development/creating-first-plugin) setup.
8
+
This guide assumes that you have a [plugin environment](creating-a-first-plugin.md) setup.
9
9
If you have not already, follow that guide first.
10
10
11
11
## Writing a ```Command``` type
@@ -82,6 +82,39 @@ public class CommandVelocity extends Command {
82
82
}
83
83
```
84
84
85
+
## World check and grab Plugin main class
86
+
Due to GoMints plugin world restriction ideas, we should not allow the plugin to run in worlds it should not be active in. We use the [```@InjectPlugin```](https://janmm14.de/static/gomint/index.html?gomint.api/io/gomint/plugin/injection/InjectPlugin.html) annotation here to get our plugin instance into our command; this only works in annotation-defined commands. Commands by players are executed in the world thread of the player, so we do not need to care about this for now.
87
+
88
+
```java
89
+
@Name("velocity")
90
+
@Description("Give custom velocity to the player who runs it")
Adding permissions to a command is as simple as adding the permission annotation.
87
120
Supposing that we want to only allow players to use the velocity command if they have the ```velocityplugin.command.velocity```, we can append the annotation to the classdeclaration:
@@ -120,7 +153,7 @@ The parameter annotation accepts the following fields:
120
153
```
121
154
122
155
### Arguments Passed
123
-
The arguments passed when a command is executed by the player/console are passed to ```execute``` in the Map object ```arguments```. For our velocity command example, we will allow a ```ConsoleCommandSender``` to specify a player's name to apply the velocity to.
156
+
The arguments passed when a command is executed by the player/console are passed to ```execute``` in the Map object ```arguments```. For our velocity command example, we will allow a ```ConsoleCommandSender``` to specify a player's name to apply the velocity to.We also have to schedule our work to the target player's world here, as console commands are running in a different thread.
124
157
125
158
```java
126
159
// Continued from above
@@ -130,12 +163,19 @@ The arguments passed when a command is executed by the player/console are passed
0 commit comments