Skip to content

Commit 3196860

Browse files
committed
feat: finish all misc arguments
1 parent f1735ce commit 3196860

File tree

17 files changed

+705
-2
lines changed

17 files changed

+705
-2
lines changed

docs/en/create-commands/arguments/types/chat/chat-preview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Because the `ChatArgument` and `AdventureChatArgument` can support entity select
105105

106106
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.
107107

108-
**Using Adventure Chat API**
108+
#### Use Adventure Chat API
109109

110110
:::tabs
111111
===Java
@@ -114,7 +114,7 @@ For execution, we do the same procedure, because the text that the user enters s
114114
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/chat/ChatPreview.kt#chatPreviewAdventureExample
115115
:::
116116

117-
**Using Legacy Chat API**
117+
#### Use Legacy Chat API
118118

119119
:::tabs
120120
===Java
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
order: 11
3+
authors:
4+
- DerEchtePilz
5+
- JorelAli
6+
- willkroboth
7+
---
8+
9+
# Potion effect arguments
10+
11+
![An image of a potion argument with a list of potion effect suggestions](/images/arguments/potion.png)
12+
13+
The `PotionEffectArgument` class represents Minecraft potion effects. When used, this argument is casted to Bukkit's `PotionEffectType` class, or alternatively a `NamespacedKey` object if the `PotionEffectArgument.NamespacedKey` argument is used to create a `PotionEffectArgument`.
14+
15+
::::tip Example - Giving a player a potion effect
16+
17+
Say we wanted to have a command that gives a player a potion effect. For this command, we'll use the following syntax:
18+
19+
```mccmd
20+
/potion <target> <potion> <duration> <strength>
21+
```
22+
23+
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.
24+
25+
#### Use `PotionEffectArgument`
26+
27+
:::tabs
28+
===Java
29+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java#potionEffectArgumentsExample
30+
===Kotlin
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsExample
32+
===Kotlin DSL
33+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsExampleDSL
34+
:::
35+
36+
#### Use `PotionEffectArgument.NamespacedKey`
37+
38+
:::tabs
39+
===Java
40+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/PotionArguments.java#potionEffectArgumentsNamespacedKeyExample
41+
===Kotlin
42+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsNamespacedKeyExample
43+
===Kotlin DSL
44+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/PotionArguments.kt#potionEffectArgumentsNamespacedKeyExampleDSL
45+
:::
46+
47+
::::
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
order: 12
3+
authors:
4+
- DerEchtePilz
5+
- JorelAli
6+
- willkroboth
7+
---
8+
9+
# Recipe arguments
10+
11+
![A recipe argument command with the suggestions for Minecraft items](/images/arguments/recipe.png)
12+
13+
The `RecipeArgument` class lets you retrieve Bukkit's `ComplexRecipe` object.
14+
15+
::::tip Example - Giving a player the result of a recipe
16+
17+
Say we want to give yourself the result of a specific recipe. Since Bukkit's `Recipe` class contains the `getResult()` method, we will use that in our example. We want to create the following command:
18+
19+
```mccmd
20+
/giverecipe <recipe>
21+
```
22+
23+
As such, we easily implement it by specifying the `RecipeArgument`, casting it and adding it to the player's inventory:
24+
25+
:::tabs
26+
===Java
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java#getResultExample
28+
===Kotlin
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getResultExample
30+
===Kotlin DSL
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getResultExampleDSL
32+
:::
33+
34+
::::
35+
36+
::::tip Example - Unlocking a recipe for a player
37+
38+
In this example, we'll use the `ComplexRecipe`'s `getKey()` method to write an example to to unlock a recipe for a player. For this command, we'll use the following syntax:
39+
40+
```mccmd
41+
/unlockrecipe <player> <recipe>
42+
```
43+
44+
This is then implemented trivially as follows:
45+
46+
:::tabs
47+
===Java
48+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/RecipeArguments.java#getKeyExample
49+
===Kotlin
50+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getKeyExample
51+
===Kotlin DSL
52+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/RecipeArguments.kt#getKeyExampleDSL
53+
:::
54+
55+
::::
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
order: 13
3+
authors:
4+
- DerEchtePilz
5+
- JorelAli
6+
- willkroboth
7+
---
8+
9+
# Sound arguments
10+
11+
![A sound argument command with a list of Minecraft sounds as suggestions](/images/arguments/sound.png)
12+
13+
The `SoundArgument` class allows a command sender to retrieve the Bukkit `Sound` or `NamespacedKey` object to represent in-game sound effects (such as mob sounds or ambient sound effects), as well as in-game music.
14+
15+
The `SoundArgument` can return a `Sound` or `NamespacedKey` object. To return a `Sound` object, simply use the `SoundArgument` as normal. To return a `NamespacedKey` object, use the `SoundArgument.NamespacedKey` constructor instead:
16+
17+
```java
18+
// Makes a SoundArgument that returns a Sound
19+
new SoundArgument("sound");
20+
21+
// Makes a SoundArgument that returns a NamespacedKey
22+
new SoundArgument.NamespacedKey("sound");
23+
```
24+
25+
:::warning
26+
27+
When using the `Sound` object, the CommandAPI will return `null` if the specified `Sound` could not be found. For this reason, it's recommended to use the `NamespacedKey` object for optimal compatibility with client-side resourcepacks.
28+
29+
:::
30+
31+
::::tip Example - Playing sound to yourself
32+
33+
Say we want a simple command that plays a specific sound at your location. To do this, we will make the following command:
34+
35+
```mccmd
36+
/sound <sound>
37+
```
38+
39+
This command simply plays the provided sound to the current player:
40+
41+
#### Use `SoundArgument`
42+
43+
:::tabs
44+
===Java
45+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/SoundArguments.java#soundArgumentsExample
46+
===Kotlin
47+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsExample
48+
===Kotlin DSL
49+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsExampleDSL
50+
:::
51+
52+
#### Use `SoundArgument.NamespacedKey`
53+
54+
:::tabs
55+
===Java
56+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/SoundArguments.java#soundArgumentsNamespacedKeyExample
57+
===Kotlin
58+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsNamespacedKeyExample
59+
===Kotlin DSL
60+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/SoundArguments.kt#soundArgumentsNamespacedKeyExampleDSL
61+
:::
62+
63+
::::
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
order: 14
3+
authors:
4+
- DerEchtePilz
5+
- JorelAli
6+
- willkroboth
7+
---
8+
9+
# Time arguments
10+
11+
![A time argument with Minecraft suggestions 'd', 's' and 't'](/images/arguments/time.png)
12+
13+
The `TimeArgument` class represents in-game time, _in the number of in-game ticks_. This allows command senders to specify a certain number of ticks in a simpler way, by including the characters `d` to specify the numbers of days, `s` to specify the number of seconds or `t` to specify a number of ticks.
14+
15+
The CommandAPI converts the inputs provided by the command sender into a number of ticks as an integer.
16+
17+
:::info
18+
19+
The `TimeArgument` provides inputs such as `2d` (2 in-game days), `10s` (10 seconds) and `20t` (20 ticks), but does **not** let you combine them, such as `2d10s`.
20+
21+
:::
22+
23+
::::tip Example - Displaying a server-wide announcement
24+
25+
Say we have a command `bigmsg` that displays a title message to all players for a certain duration:
26+
27+
```mccmd
28+
/bigmsg <duration> <message>
29+
```
30+
31+
:::tabs
32+
===Java
33+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/TimeArguments.java#timeArgumentsExample
34+
===Kotlin
35+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt#timeArgumentsExample
36+
===Kotlin DSL
37+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/TimeArguments.kt#timeArgumentsExampleDSL
38+
:::
39+
40+
::::
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
order: 15
3+
authors:
4+
- JorelAli
5+
---
6+
7+
# UUID arguments
8+
9+
The UUID argument is used to uniquely identify players, entities and attribute modifiers. As a result, its cast type is Java's `UUID`.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
order: 16
3+
authors:
4+
- DerEchtePilz
5+
- JorelAli
6+
- willkroboth
7+
---
8+
9+
# World arguments
10+
11+
![A picture of world arguments in action](/images/arguments/worldargument.png)
12+
13+
The `WorldArgument` class allows a command sender to refer to a loaded Bukkit `World`.
14+
15+
::::tip Example - Unloading world
16+
17+
Say we want to unload a world on our Minecraft server. We want to create a command with the following syntax:
18+
19+
```mccmd
20+
/unloadworld <world>
21+
```
22+
23+
Using the world from the `WorldArgument`, we can then unload the world safely using `Bukkit.getServer().unloadWorld()` and passing `true` (to save chunks):
24+
25+
:::tabs
26+
===Java
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/WorldArguments.java#worldArgumentsExample
28+
===Kotlin
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt#worldArgumentsExample
30+
===Kotlin DSL
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/WorldArguments.kt#worldArgumentsExampleDSL
32+
:::
33+
34+
::::
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package createcommands.arguments.types.misc;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.IntegerArgument;
5+
import dev.jorel.commandapi.arguments.PlayerArgument;
6+
import dev.jorel.commandapi.arguments.PotionEffectArgument;
7+
import dev.jorel.commandapi.arguments.TimeArgument;
8+
import org.bukkit.NamespacedKey;
9+
import org.bukkit.entity.Player;
10+
import org.bukkit.potion.PotionEffect;
11+
import org.bukkit.potion.PotionEffectType;
12+
13+
class PotionArguments {
14+
{
15+
// #region potionEffectArgumentsExample
16+
new CommandAPICommand("potion")
17+
.withArguments(new PlayerArgument("target"))
18+
.withArguments(new PotionEffectArgument("potion"))
19+
.withArguments(new TimeArgument("duration"))
20+
.withArguments(new IntegerArgument("strength"))
21+
.executes((sender, args) -> {
22+
Player target = (Player) args.get("target");
23+
PotionEffectType potion = (PotionEffectType) args.get("potion");
24+
int duration = (int) args.get("duration");
25+
int strength = (int) args.get("strength");
26+
27+
// Add the potion effect to the target player
28+
target.addPotionEffect(new PotionEffect(potion, duration, strength));
29+
})
30+
.register();
31+
// #endregion potionEffectArgumentsExample
32+
33+
// #region potionEffectArgumentsNamespacedKeyExample
34+
new CommandAPICommand("potion")
35+
.withArguments(new PlayerArgument("target"))
36+
.withArguments(new PotionEffectArgument.NamespacedKey("potion"))
37+
.withArguments(new TimeArgument("duration"))
38+
.withArguments(new IntegerArgument("strength"))
39+
.executes((sender, args) -> {
40+
Player target = (Player) args.get("target");
41+
NamespacedKey potionKey = (NamespacedKey) args.get("potion");
42+
int duration = (int) args.get("duration");
43+
int strength = (int) args.get("strength");
44+
45+
PotionEffectType potion = PotionEffectType.getByKey(potionKey);
46+
47+
// Add the potion effect to the target player
48+
target.addPotionEffect(new PotionEffect(potion, duration, strength));
49+
})
50+
.register();
51+
// #endregion potionEffectArgumentsNamespacedKeyExample
52+
}
53+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package createcommands.arguments.types.misc;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.PlayerArgument;
5+
import dev.jorel.commandapi.arguments.RecipeArgument;
6+
import org.bukkit.entity.Player;
7+
import org.bukkit.inventory.ComplexRecipe;
8+
9+
class RecipeArguments {
10+
{
11+
// #region getResultExample
12+
new CommandAPICommand("giverecipe")
13+
.withArguments(new RecipeArgument("recipe"))
14+
.executesPlayer((player, args) -> {
15+
ComplexRecipe recipe = (ComplexRecipe) args.get("recipe");
16+
player.getInventory().addItem(recipe.getResult());
17+
})
18+
.register();
19+
// #endregion getResultExample
20+
21+
// #region getKeyExample
22+
new CommandAPICommand("unlockrecipe")
23+
.withArguments(new PlayerArgument("player"))
24+
.withArguments(new RecipeArgument("recipe"))
25+
.executes((sender, args) -> {
26+
Player target = (Player) args.get("player");
27+
ComplexRecipe recipe = (ComplexRecipe) args.get("recipe");
28+
29+
target.discoverRecipe(recipe.getKey());
30+
})
31+
.register();
32+
// #endregion getKeyExample
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package createcommands.arguments.types.misc;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.SoundArgument;
5+
import org.bukkit.NamespacedKey;
6+
import org.bukkit.Sound;
7+
8+
class SoundArguments {
9+
{
10+
// #region soundArgumentsExample
11+
new CommandAPICommand("sound")
12+
.withArguments(new SoundArgument("sound"))
13+
.executesPlayer((player, args) -> {
14+
player.getWorld().playSound(player.getLocation(), (Sound) args.get("sound"), 100.0f, 1.0f);
15+
})
16+
.register();
17+
// #endregion soundArgumentsExample
18+
19+
// #region soundArgumentsNamespacedKeyExample
20+
new CommandAPICommand("sound")
21+
.withArguments(new SoundArgument.NamespacedKey("sound"))
22+
.executesPlayer((player, args) -> {
23+
player.getWorld().playSound(player.getLocation(), ((NamespacedKey) args.get("sound")).asString(), 100.0f, 1.0f);
24+
})
25+
.register();
26+
// #endregion soundArgumentsNamespacedKeyExample
27+
}
28+
}

0 commit comments

Comments
 (0)