3
3
import com .mojang .brigadier .arguments .IntegerArgumentType ;
4
4
import com .mojang .brigadier .arguments .StringArgumentType ;
5
5
import com .mojang .brigadier .context .CommandContext ;
6
+ import lombok .AccessLevel ;
7
+ import lombok .NoArgsConstructor ;
6
8
import net .fabricmc .fabric .api .client .command .v2 .ClientCommandRegistrationCallback ;
7
9
import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
8
10
import net .jasper .mod .gui .PlayerAutomaMenuScreen ;
17
19
18
20
import static net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager .literal ;
19
21
import static net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager .argument ;
20
- import static net .jasper .mod .PlayerAutomaClient .LOGGER ;
21
22
import static net .jasper .mod .PlayerAutomaClient .PLAYERAUTOMA_RECORDING_PATH ;
22
23
23
24
/**
24
25
* Class to register all commands associated with playerautoma
25
26
*/
27
+ @ NoArgsConstructor (access = AccessLevel .PRIVATE )
26
28
public class Commands {
29
+
30
+ private static final String START = "start" ;
31
+ private static final String STOP = "stop" ;
32
+ private static final String CLEAR = "clear" ;
33
+ private static final String RECORD = "record" ;
34
+ private static final String QUICKSLOT = "quickslot" ;
35
+ private static final String LOAD = "load" ;
36
+ private static final String STORE = "store" ;
37
+ private static final String SLOT = "slot" ;
38
+ private static final String NAME = "name" ;
39
+ private static final String PLAYERAUTOMA = "playerautoma" ;
40
+ private static final String OPEN = "open" ;
41
+ private static final String LOADSCREEN = "loadscreen" ;
42
+ private static final String STORESCREEN = "storescreen" ;
43
+ private static final String MENU = "menu" ;
44
+ private static final String JSON = "json" ;
45
+ private static final String REC = "rec" ;
46
+ private static final String TOGGLEPAUSE = "togglepause" ;
47
+ private static final String REPLAY = "replay" ;
48
+ private static final String LOOP = "loop" ;
49
+
50
+
27
51
public static void register () {
28
52
// Register /record <start|stop|clear>
29
53
// /record quickslot <load|store> <slot>
30
54
ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) ->
31
55
dispatcher .register (
32
- literal ("record" )
33
- .then (literal ("start" )
56
+ literal (RECORD )
57
+ .then (literal (START )
34
58
.executes (context -> {
35
59
PlayerAutomaExceptionHandler .callSafe (PlayerRecorder ::startRecord );
36
60
return 1 ;
37
61
})
38
62
)
39
- .then (literal ("stop" )
63
+ .then (literal (STOP )
40
64
.executes (context -> {
41
65
PlayerAutomaExceptionHandler .callSafe (PlayerRecorder ::stopRecord );
42
66
return 1 ;
43
67
})
44
68
)
45
- .then (literal ("clear" )
69
+ .then (literal (CLEAR )
46
70
.executes (context -> {
47
71
PlayerAutomaExceptionHandler .callSafe (PlayerRecorder ::clearRecord );
48
72
return 1 ;
49
73
})
50
74
)
51
- .then (literal ("quickslot" )
52
- .then (literal ("load" )
53
- .then (argument ("slot" , IntegerArgumentType .integer ())
54
- .executes (context -> handleQuickSlotCommand (context , "load" ))
75
+ .then (literal (QUICKSLOT )
76
+ .then (literal (LOAD )
77
+ .then (argument (SLOT , IntegerArgumentType .integer ())
78
+ .executes (context -> handleQuickSlotCommand (context , LOAD ))
55
79
)
56
80
)
57
- .then (literal ("store" )
58
- .then (argument ("slot" , IntegerArgumentType .integer ())
59
- .executes (context -> handleQuickSlotCommand (context , "store" ))
81
+ .then (literal (STORE )
82
+ .then (argument (SLOT , IntegerArgumentType .integer ())
83
+ .executes (context -> handleQuickSlotCommand (context , STORE ))
60
84
)
61
85
)
62
- .then (literal ("clear" )
86
+ .then (literal (CLEAR )
63
87
.executes (context -> { QuickSlots .clearQuickSlot (); return 1 ; })
64
- .then (argument ("slot" , IntegerArgumentType .integer ())
65
- .executes (context -> handleQuickSlotCommand (context , "clear" )))
88
+ .then (argument (SLOT , IntegerArgumentType .integer ())
89
+ .executes (context -> handleQuickSlotCommand (context , CLEAR )))
66
90
)
67
91
)
68
- .then (literal ("store" )
69
- .then (argument ("name" , StringArgumentType .string ())
70
- .then (literal ("json" )
71
- .executes (context -> handleStoreFileCommand (context , "json" ))
92
+ .then (literal (STORE )
93
+ .then (argument (NAME , StringArgumentType .string ())
94
+ .then (literal (JSON )
95
+ .executes (context -> handleStoreFileCommand (context , JSON ))
72
96
)
73
- .then (literal ("rec" )
74
- .executes (context -> handleStoreFileCommand (context , "rec" ))
97
+ .then (literal (REC )
98
+ .executes (context -> handleStoreFileCommand (context , REC ))
75
99
)
76
100
)
77
101
)
78
- .then (literal ("load" )
79
- .then (argument ("name" , StringArgumentType .string ())
102
+ .then (literal (LOAD )
103
+ .then (argument (NAME , StringArgumentType .string ())
80
104
.suggests ((context , builder ) -> {
81
105
String current = "" ;
82
106
try {
83
- current = StringArgumentType .getString (context , "name" );
107
+ current = StringArgumentType .getString (context , NAME );
84
108
} catch (IllegalArgumentException e ) {
85
109
// Empty argument therefore keep startsWith as ""
86
110
}
@@ -98,7 +122,7 @@ public static void register() {
98
122
return builder .buildFuture ();
99
123
})
100
124
.executes (context -> {
101
- String name = StringArgumentType .getString (context , "name" );
125
+ String name = StringArgumentType .getString (context , NAME );
102
126
PlayerAutomaExceptionHandler .callSafe (() -> PlayerRecorder .loadRecord (name ));
103
127
return 1 ;
104
128
})
@@ -109,25 +133,25 @@ public static void register() {
109
133
110
134
// Register /replay <start|stop|loop|togglepause>
111
135
ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) ->
112
- dispatcher .register (literal ("replay" )
113
- .then (literal ("start" )
136
+ dispatcher .register (literal (REPLAY )
137
+ .then (literal (START )
114
138
.executes (context -> {
115
139
PlayerAutomaExceptionHandler .callSafe (() -> PlayerRecorder .startReplay (false ));
116
140
return 1 ;
117
141
})
118
142
)
119
- .then (literal ("stop" )
143
+ .then (literal (STOP )
120
144
.executes (context -> {
121
145
PlayerAutomaExceptionHandler .callSafe (PlayerRecorder ::stopReplay );
122
146
return 1 ;
123
147
})
124
148
)
125
- .then (literal ("togglepause" )
149
+ .then (literal (TOGGLEPAUSE )
126
150
.executes (context -> {
127
151
PlayerAutomaExceptionHandler .callSafe (PlayerRecorder ::togglePauseReplay );
128
152
return 1 ;
129
153
})
130
- ).then (literal ("loop" )
154
+ ).then (literal (LOOP )
131
155
.executes (context -> {
132
156
PlayerAutomaExceptionHandler .callSafe (PlayerRecorder ::startReplay );
133
157
return 1 ;
@@ -138,20 +162,17 @@ public static void register() {
138
162
139
163
// Register /playerautoma open <loadscreen|storescreen|menu>
140
164
ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) ->
141
- dispatcher .register (literal ("playerautoma" )
142
- .then (literal ("open" )
143
- .then (literal ("loadscreen" ).executes (context -> {
144
- LOGGER .info ("12341234" );
165
+ dispatcher .register (literal (PLAYERAUTOMA )
166
+ .then (literal (OPEN )
167
+ .then (literal (LOADSCREEN ).executes (context -> {
145
168
MinecraftClient .getInstance ().execute (RecordingSelectorScreen ::open );
146
169
return 1 ;
147
170
})
148
- ).then (literal ("storescreen" ).executes (context -> {
149
- LOGGER .info ("qwerqwer" );
171
+ ).then (literal (STORESCREEN ).executes (context -> {
150
172
MinecraftClient .getInstance ().execute (RecordingStorerScreen ::open );
151
173
return 1 ;
152
174
})
153
- ).then (literal ("menu" ).executes (context -> {
154
- LOGGER .info ("asdfasdf" );
175
+ ).then (literal (MENU ).executes (context -> {
155
176
MinecraftClient .getInstance ().execute (PlayerAutomaMenuScreen ::open );
156
177
return 1 ;
157
178
}))
@@ -161,9 +182,9 @@ public static void register() {
161
182
}
162
183
163
184
private static int handleStoreFileCommand (CommandContext <FabricClientCommandSource > context , String fileType ) {
164
- String fileName = StringArgumentType .getString (context , "name" );
185
+ String fileName = StringArgumentType .getString (context , NAME );
165
186
166
- boolean callNext = RecordingStorerScreen .useJSON .getValue () && fileType .equals ("rec" ) || !RecordingStorerScreen .useJSON .getValue () && fileType .equals ("json" );
187
+ boolean callNext = RecordingStorerScreen .useJSON .getValue () && fileType .equals (REC ) || !RecordingStorerScreen .useJSON .getValue () && fileType .equals (JSON );
167
188
168
189
// Initialize button element to allow calling next
169
190
Screen currentScreen = RecordingStorerScreen .open ();
@@ -185,19 +206,19 @@ private static int handleStoreFileCommand(CommandContext<FabricClientCommandSour
185
206
}
186
207
187
208
private static int handleQuickSlotCommand (CommandContext <FabricClientCommandSource > context , String command ) {
188
- final int slot = IntegerArgumentType .getInteger (context , "slot" );
209
+ final int slot = IntegerArgumentType .getInteger (context , SLOT );
189
210
if (slot < 1 || 9 < slot ) {
190
211
context .getSource ().sendFeedback (Text .literal ("Slot Index out of range" ));
191
212
return 0 ;
192
213
}
193
214
switch (command ) {
194
- case "load" :
215
+ case LOAD :
195
216
QuickSlots .loadRecording (slot - 1 );
196
217
break ;
197
- case "store" :
218
+ case STORE :
198
219
QuickSlots .storeRecording (slot - 1 );
199
220
break ;
200
- case "clear" :
221
+ case CLEAR :
201
222
QuickSlots .clearQuickSlot (slot - 1 );
202
223
}
203
224
return 1 ;
0 commit comments