1
1
package com .thepinkhacker .commandsplus ;
2
2
3
+ import com .mojang .brigadier .CommandDispatcher ;
3
4
import com .thepinkhacker .commandsplus .command .argument .ArgumentTypeManager ;
4
5
import com .thepinkhacker .commandsplus .server .command .*;
5
6
import com .thepinkhacker .commandsplus .server .dedicated .command .CPStopCommand ;
7
+ import com .thepinkhacker .commandsplus .server .dedicated .command .CommandRegistrationCallbackDedicated ;
6
8
import com .thepinkhacker .commandsplus .util .command .AliasUtils ;
7
9
import com .thepinkhacker .commandsplus .world .GameRuleManager ;
8
10
import net .fabricmc .api .ModInitializer ;
9
11
import net .fabricmc .fabric .api .command .v2 .CommandRegistrationCallback ;
12
+ import net .minecraft .command .CommandRegistryAccess ;
13
+ import net .minecraft .server .command .CommandManager ;
14
+ import net .minecraft .util .Identifier ;
10
15
import org .apache .logging .log4j .LogManager ;
11
16
import org .apache .logging .log4j .Logger ;
12
17
@@ -20,28 +25,49 @@ public void onInitialize() {
20
25
GameRuleManager .register ();
21
26
22
27
CommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess , environment ) -> {
23
- // Commands
24
- ClearSpawnPointCommand .register (dispatcher );
25
- DayLockCommand .register (dispatcher );
26
- GameRulePresetCommand .register (dispatcher );
27
- HeadCommand .register (dispatcher );
28
- HealthCommand .register (dispatcher );
29
- HungerCommand .register (dispatcher );
30
- NameCommand .register (dispatcher );
31
- RideCommand .register (dispatcher , registryAccess );
32
- SetOwnerCommand .register (dispatcher );
33
- ToggleDownfallCommand .register (dispatcher );
34
-
35
- // Dedicated server
36
- if (environment .dedicated ) {
37
- CPStopCommand .register (dispatcher );
38
- }
28
+ registerCommands (
29
+ dispatcher ,
30
+ registryAccess ,
31
+ environment ,
32
+ new CommandRegistrationCallback [] {
33
+ new ClearSpawnPointCommand (),
34
+ new DayLockCommand (),
35
+ new GameRulePresetCommand (),
36
+ new HeadCommand (),
37
+ new HealthCommand (),
38
+ new HungerCommand (),
39
+ new NameCommand (),
40
+ new RideCommand (),
41
+ new SetOwnerCommand (),
42
+ new ToggleDownfallCommand (),
43
+ new CPStopCommand (),
44
+ }
45
+ );
39
46
40
47
// Aliases
41
48
AliasUtils .createAlias (dispatcher , "gamemode" , "gm" );
42
49
AliasUtils .createAlias (dispatcher , "help" , "?" );
43
50
44
- LOGGER .info ("Registered commands" );
51
+ LOGGER .info ("Registered commands+. " );
45
52
});
46
53
}
54
+
55
+ private static void registerCommands (
56
+ CommandDispatcher <net .minecraft .server .command .ServerCommandSource > dispatcher ,
57
+ CommandRegistryAccess registryAccess ,
58
+ CommandManager .RegistrationEnvironment environment ,
59
+ CommandRegistrationCallback [] commands
60
+ ) {
61
+ for (CommandRegistrationCallback command : commands ) {
62
+ if (command instanceof CommandRegistrationCallbackDedicated ) {
63
+ if (environment .dedicated ) command .register (dispatcher , registryAccess , environment );
64
+ } else {
65
+ command .register (dispatcher , registryAccess , environment );
66
+ }
67
+ }
68
+ }
69
+
70
+ public static Identifier identifier (String id ) {
71
+ return new Identifier (MOD_ID , id );
72
+ }
47
73
}
0 commit comments