@@ -62,7 +62,6 @@ Argument type, but there are many others:
62
62
| ---------------------| -----------------------| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
63
63
| GAME_EVENT | GameEvent | [ Game events] ( https://minecraft.wiki/w/Sculk_Sensor#Vibration_frequencies ) |
64
64
| STRUCTURE_TYPE | StructureType | [ Structure types] ( https://minecraft.wiki/w/Structure#Overworld ) |
65
- | INSTRUMENT | MusicInstrument | [ Goat horns] ( https://minecraft.wiki/w/Goat_Horn#Playing ) |
66
65
| MOB_EFFECT | PotionEffectType | [ Potion effect] ( https://minecraft.wiki/w/Effect#List ) |
67
66
| BLOCK | BlockType | [ Block type] ( https://minecraft.wiki/w/Block#List_of_blocks ) |
68
67
| ITEM | ItemType | [ Item type] ( https://minecraft.wiki/w/Item#List_of_items ) |
@@ -72,23 +71,24 @@ Argument type, but there are many others:
72
71
| VILLAGER_TYPE | Villager.Type | [ Villager biome specific type] ( https://minecraft.wiki/w/Villager#Professions ) |
73
72
| MAP_DECORATION_TYPE | MapCursor.Type | [ Types of sprites displayed on a map] ( https://minecraft.wiki/w/Map#Map_icons ) |
74
73
| MENU | MenuType | [ Menu type] ( https://wiki.vg/Inventory ) |
74
+ | ATTRIBUTE | Attribute | [ Entity attribute] ( https://minecraft.wiki/w/Attribute ) |
75
+ | FLUID | Fluid | [ Fluid types] ( https://minecraft.wiki/w/Fluid ) |
76
+ | SOUND_EVENT | Sound | [ Events that trigger sound effects] ( https://minecraft.wiki/w/Sounds.json#Sound_events ) |
77
+ | BIOME | Biome | [ Biome type] ( https://minecraft.wiki/w/Biome#Biome_types ) |
75
78
| STRUCTURE | Structure | [ Structures] ( https://minecraft.wiki/w/Structure#Overworld ) |
76
79
| TRIM_MATERIAL | TrimMaterial | [ Materials used to trim armor] ( https://minecraft.wiki/w/Smithing#Material ) |
77
80
| TRIM_PATTERN | TrimPattern | [ Trim patterns] ( https://minecraft.wiki/w/Smithing#Trimming ) |
78
81
| DAMAGE_TYPE | DamageType | [ All types of damage dealt to an entity] ( https://minecraft.wiki/w/Damage_type ) |
82
+ | WOLF_VARIANT | Wolf.Variant | [ Wolf variants] ( https://minecraft.wiki/w/Wolf#Variants ) |
79
83
| ENCHANTMENT | Enchantment | [ Enchantment type] ( https://minecraft.wiki/w/Enchanting#Summary_of_enchantments ) |
80
84
| JUKEBOX_SONG | JukeboxSong | Music disc songs |
81
- | WOLF_VARIANT | Wolf.Variant | [ Wolf variants] ( https://minecraft.wiki/w/Wolf#Variants ) |
82
85
| BANNER_PATTERN | PatternType | [ Banner patterns] ( https://minecraft.wiki/w/Banner_Pattern#Variants ) |
83
- | BIOME | Biome | [ Biome type] ( https://minecraft.wiki/w/Biome#Biome_types ) |
84
86
| PAINTING_VARIANT | Art | [ Painting variants] ( https://minecraft.wiki/w/Painting#Canvases ) |
85
- | ATTRIBUTE | Attribute | [ Entity attribute ] ( https://minecraft.wiki/w/Attribute ) |
87
+ | INSTRUMENT | MusicInstrument | [ Goat horns ] ( https://minecraft.wiki/w/Goat_Horn#Playing ) |
86
88
| ENTITY_TYPE | EntityType | [ Every entity type] ( https://minecraft.wiki/w/Entity#Types_of_entities ) |
87
89
| PARTICLE_TYPE | Particle | [ Every particle type] ( https://minecraft.wiki/w/Particles_(Java_Edition)#Types_of_particles ) |
88
90
| POTION | PotionType | [ Every potion type] ( https://minecraft.wiki/w/Potion#Effect_potions ) |
89
- | SOUND_EVENT | Sound | [ Events that trigger sound effects] ( https://minecraft.wiki/w/Sounds.json#Sound_events ) |
90
91
| MEMORY_MODULE_TYPE | MemoryKey | Keys for saving per-entity data |
91
- | FLUID | Fluid | [ Fluid types] ( https://minecraft.wiki/w/Fluid ) |
92
92
93
93
Paper specifies many more argument types. For more information on them, see <Javadoc name = { " io.papermc.paper.command.brigadier.argument.ArgumentTypes" } >ArgumentTypes</Javadoc >
94
94
@@ -100,7 +100,7 @@ interface.
100
100
Now, let's say that we want to implement a command which lets you order ice cream. For that,
101
101
we add an enum that specifies all available values for our custom type.
102
102
103
- ``` java
103
+ ``` java title="IceCreamType.java"
104
104
public enum IceCreamType {
105
105
VANILLA ,
106
106
CHOCOLATE ,
@@ -111,11 +111,11 @@ public enum IceCreamType {
111
111
```
112
112
Now, we have to define the argument itself. We do this by implementing the <Javadoc name = { " io.papermc.paper.command.brigadier.argument.CustomArgumentType$Converted" } >CustomArgumentType.Converted</Javadoc > interface:
113
113
114
- ``` java
114
+ ``` java title="IceCreamTypeArgument.java"
115
115
public class IceCreamTypeArgument implements CustomArgumentType .Converted<IceCreamType , String > {
116
116
117
117
@Override
118
- public @ NotNull IceCreamType convert (String nativeType ) throws CommandSyntaxException {
118
+ public IceCreamType convert (String nativeType ) throws CommandSyntaxException {
119
119
try {
120
120
return IceCreamType . valueOf(nativeType. toUpperCase(Locale . ENGLISH ));
121
121
} catch (IllegalArgumentException ignored) {
@@ -126,7 +126,7 @@ public class IceCreamTypeArgument implements CustomArgumentType.Converted<IceCre
126
126
}
127
127
128
128
@Override
129
- public @ NotNull ArgumentType<String > getNativeType () {
129
+ public ArgumentType<String > getNativeType () {
130
130
return StringArgumentType . word();
131
131
}
132
132
@@ -154,7 +154,8 @@ detail.
154
154
155
155
We then need to register the command:
156
156
157
- ``` java
157
+ ``` java title="TestPlugin.java"
158
+ @Override
158
159
public void onEnable() {
159
160
final LifecycleEventManager<Plugin > manager = this . getLifecycleManager();
160
161
manager. registerEventHandler(LifecycleEvents . COMMANDS , event - > {
0 commit comments