Skip to content

Commit e05c3ba

Browse files
committed
feat: add more arguments
1 parent a3a60d0 commit e05c3ba

20 files changed

+672
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
order: 2
3+
authors:
4+
- DerEchtePilz
5+
- willkroboth
6+
- JorelAli
7+
---
8+
9+
# Advancement arguments
10+
11+
![An advancement argument suggesting a list of Minecraft advancements](/images/arguments/advancement.png)
12+
13+
The `AdvancementArgument` class represents in-game advancements. As expected, the `AdvancementArgument` can be casted to Bukkit's `Advancement` class.
14+
15+
::::tip Example – Awarding a player an advancement
16+
17+
Say we want to award a player an advancement. First, we need the syntax that our command will use:
18+
19+
```mccmd
20+
/award <player> <advancement>
21+
```
22+
23+
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.
24+
25+
:::tabs
26+
===Java
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/AdvancementArguments.java#advancementArgumentsExample
28+
===Kotlin
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt#advancementArgumentsExample
30+
===Kotlin DSL
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/AdvancementArguments.kt#advancementArgumentsExampleDSL
32+
:::
33+
34+
::::
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
order: 1
3+
authors:
4+
- JorelAli
5+
---
6+
7+
# Angle arguments
8+
9+
The angle argument is used to represent the _yaw_ (horizontal) angle in degrees. The value returned from this argument range from -180.0 (inclusive) to 180 (exclusive), with -180.0 being due north:
10+
11+
$$
12+
\begin{align}
13+
-1&80.0 \\\\
14+
&\hspace{0.1em}N \\\\
15+
&\uparrow \\\\
16+
90.0\ W \leftarrow &\hspace{0.75em}\rightarrow E\ -90.0 \\\\
17+
&\downarrow \\\\
18+
&\hspace{0.2em}S \\\\
19+
&0.0 \\\\
20+
\end{align}
21+
$$
22+
23+
The `~` notation can be used to specify a rotation relative to the executor's yaw angle.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
order: 3
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# Biome arguments
10+
11+
![A biome argument suggesting a list of Minecraft biomes](/images/arguments/biome.png)
12+
13+
In Minecraft 1.16, they added the ability to refer to in-game biomes. The CommandAPI implements this using the `BiomeArgument`. As expected, this returns Bukkit's `Biome` enum when used.
14+
15+
:::warning
16+
17+
When using the `Biome` object, the CommandAPI will return `null` if the specified `Biome` could not be found, for example if a player submitted a biome from a client-side resourcepack. The CommandAPI does **not** return `Biome.CUSTOM` from the `BiomeArgument`.
18+
19+
:::
20+
21+
::::tip Example – Setting the biome of a chunk
22+
23+
Say you want to set the biome of the current chunk that a player is in. We can do this using the `World.setBiome(x, y, z, biome)` method for a given world. We will use this command syntax to set the biome of our current chunk:
24+
25+
```mccmd
26+
/setbiome <biome>
27+
```
28+
29+
And we can set the biome of the current chunk as expected:
30+
31+
:::tabs
32+
===Java
33+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/BiomeArguments.java#biomeArgumentsExample
34+
===Kotlin
35+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt#biomeArgumentsExample
36+
===Kotlin DSL
37+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BiomeArguments.kt#biomeArgumentsExampleDSL
38+
:::
39+
40+
::::
41+
42+
The `BiomeArgument` also supports returning a `NamespacedKey` for custom biomes. This can be done by using the `BiomeArgument.NamespacedKey` constructor instead of the normal `BiomeArgument` constructor:
43+
44+
```java
45+
// Makes a BiomeArgument that returns a Biome
46+
new BiomeArgument("biome");
47+
48+
// Makes a BiomeArgument that returns a NamespacedKey
49+
new BiomeArgument.NamespacedKey("biome");
50+
```
51+
52+
:::info
53+
54+
Spigot's support for custom biomes is really limited! If you have an example that lets you use custom biomes with namespaced keys, please open a GitHub issue, or reach out to us on Discord!
55+
56+
:::
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
order: 4
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# BlockState arguments
10+
11+
![A block state argument with suggestions for Minecraft items](/images/arguments/blockstate.png)
12+
13+
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.
14+
15+
:::info
16+
17+
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`**.
18+
19+
:::
20+
21+
::::tip Example – Setting a block
22+
23+
Say we want a simple command to set the block that you're looking at. We'll use the following command syntax:
24+
25+
```mccmd
26+
/set <block>
27+
```
28+
29+
And then we can simply set our block using `setBlockData()`:
30+
31+
:::tabs
32+
===Java
33+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/BlockStateArguments.java#blockStateArgumentsExample
34+
===Kotlin
35+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt#blockStateArgumentsExample
36+
===Kotlin DSL
37+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/BlockStateArguments.kt#blockStateArgumentsExampleDSL
38+
:::
39+
40+
::::
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
order: 5
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# Enchantment arguments
10+
11+
![An enchantment argument suggesting a list of Minecraft enchantments](/images/arguments/enchantment.png)
12+
13+
The `EnchantmentArgument` class lets users input a specific enchantment. As you would expect, the cast type is Bukkit's `Enchantment` class.
14+
15+
::::tip Example – Giving a player an enchantment on their current item
16+
17+
Say we want to give a player an enchantment on the item that the player is currently holding. We will use the following command syntax:
18+
19+
```mccmd
20+
/enchantitem <enchantment> <level>
21+
```
22+
23+
Since most enchantment levels range between 1 and 5, we will also make use of the `IntegerArgument` to restrict the level of the enchantment by using its range constructor.
24+
25+
:::tabs
26+
===Java
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/EnchantmentArguments.java#enchantmentArgumentsExample
28+
===Kotlin
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt#enchantmentArgumentsExample
30+
===Kotlin DSL
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/EnchantmentArguments.kt#enchantmentArgumentsExampleDSL
32+
:::
33+
34+
::::
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
order: 9
3+
title: Misc arguments
4+
---
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
order: 6
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# ItemStack arguments
10+
11+
![An item stack argument with suggestions for Minecraft items](/images/arguments/itemstack.png)
12+
13+
The `ItemStackArgument` class represents in-game items. As expected, this should be casted to Bukkit's `ItemStack` object. The `ItemStack` which is returned by the `ItemStackArgument` always has a size of 1.
14+
15+
::::tip Example – Giving a player an itemstack
16+
17+
Say we want to create a command that gives you items. For this command, we will use the following syntax:
18+
19+
```mccmd
20+
/item <itemstack>
21+
```
22+
23+
With this syntax, we can easily create our command:
24+
25+
:::tabs
26+
===Java
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/ItemStackArguments.java#itemStackArgumentsExample
28+
===Kotlin
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt#itemStackArgumentsExample
30+
===Kotlin DSL
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/ItemStackArguments.kt#itemStackArgumentsExampleDSL
32+
:::
33+
34+
::::
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
order: 7
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# LootTable argument
10+
11+
![A loot table argument showing a list of Minecraft loot tables as suggestions](/images/arguments/loottable.png)
12+
13+
The `LootTableArgument` class can be used to get a Bukkit `LootTable` object.
14+
15+
::::tip Example – Filling a chest with loot table contents
16+
17+
Say we wanted to write a command that populates a chest with some loot table contents. For this example, we'll use the following command:
18+
19+
```mccmd
20+
/giveloottable <loottable> <location>
21+
```
22+
23+
We ensure that the location provided is a container (such as a chest or shulkerbox) and then update the contents of that container:
24+
25+
:::tabs
26+
===Java
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/LootTableArguments.java#lootTableArgumentsExample
28+
===Kotlin
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt#lootTableArgumentsExample
30+
===Kotlin DSL
31+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/LootTableArguments.kt#lootTableArgumentsExampleDSL
32+
:::
33+
34+
::::
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package createcommands.arguments.types.misc;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.AdvancementArgument;
5+
import dev.jorel.commandapi.arguments.PlayerArgument;
6+
import org.bukkit.advancement.Advancement;
7+
import org.bukkit.advancement.AdvancementProgress;
8+
import org.bukkit.entity.Player;
9+
10+
class AdvancementArguments {
11+
{
12+
// #region advancementArgumentsExample
13+
new CommandAPICommand("award")
14+
.withArguments(new PlayerArgument("player"))
15+
.withArguments(new AdvancementArgument("advancement"))
16+
.executes((sender, args) -> {
17+
Player target = (Player) args.get("player");
18+
Advancement advancement = (Advancement) args.get("advancement");
19+
20+
// Award all criteria for the advancement
21+
AdvancementProgress progress = target.getAdvancementProgress(advancement);
22+
for (String criteria : advancement.getCriteria()) {
23+
progress.awardCriteria(criteria);
24+
}
25+
})
26+
.register();
27+
// #endregion advancementArgumentsExample
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package createcommands.arguments.types.misc;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.BiomeArgument;
5+
import org.bukkit.Chunk;
6+
import org.bukkit.block.Biome;
7+
8+
class BiomeArguments {
9+
{
10+
// #region biomeArgumentsExample
11+
new CommandAPICommand("setbiome")
12+
.withArguments(new BiomeArgument("biome"))
13+
.executesPlayer((player, args) -> {
14+
Biome biome = (Biome) args.get("biome");
15+
16+
Chunk chunk = player.getLocation().getChunk();
17+
player.getWorld().setBiome(chunk.getX(), player.getLocation().getBlockY(), chunk.getZ(), biome);
18+
})
19+
.register();
20+
// #endregion biomeArgumentsExample
21+
}
22+
}

0 commit comments

Comments
 (0)