24
24
import de .themoep .minedown .adventure .MineDown ;
25
25
import net .kyori .adventure .text .Component ;
26
26
import net .kyori .adventure .text .JoinConfiguration ;
27
- import net .kyori .adventure .text .event .HoverEvent ;
27
+ import net .kyori .adventure .text .event .ClickEvent ;
28
28
import net .kyori .adventure .text .format .NamedTextColor ;
29
29
import net .kyori .adventure .text .format .TextColor ;
30
+ import net .kyori .adventure .text .format .TextDecoration ;
30
31
import net .william278 .desertwell .about .AboutMenu ;
31
32
import net .william278 .desertwell .util .UpdateChecker ;
32
33
import net .william278 .husksync .HuskSync ;
35
36
import net .william278 .husksync .migrator .Migrator ;
36
37
import net .william278 .husksync .user .CommandUser ;
37
38
import net .william278 .husksync .util .LegacyConverter ;
39
+ import net .william278 .husksync .util .StatusLine ;
38
40
import net .william278 .uniform .BaseCommand ;
39
41
import net .william278 .uniform .CommandProvider ;
40
42
import net .william278 .uniform .Permission ;
41
43
import net .william278 .uniform .element .ArgumentElement ;
42
- import org .apache .commons .text .WordUtils ;
43
44
import org .jetbrains .annotations .NotNull ;
44
45
45
46
import java .time .OffsetDateTime ;
46
47
import java .util .Arrays ;
47
48
import java .util .List ;
48
49
import java .util .UUID ;
49
- import java .util .function .Function ;
50
50
import java .util .logging .Level ;
51
51
import java .util .stream .Collectors ;
52
52
@@ -98,6 +98,7 @@ public void provide(@NotNull BaseCommand<?> command) {
98
98
command .setDefaultExecutor ((ctx ) -> about (command , ctx ));
99
99
command .addSubCommand ("about" , (sub ) -> sub .setDefaultExecutor ((ctx ) -> about (command , ctx )));
100
100
command .addSubCommand ("status" , needsOp ("status" ), status ());
101
+ command .addSubCommand ("dump" , needsOp ("dump" ), dump ());
101
102
command .addSubCommand ("reload" , needsOp ("reload" ), reload ());
102
103
command .addSubCommand ("update" , needsOp ("update" ), update ());
103
104
command .addSubCommand ("forceupgrade" , forceUpgrade ());
@@ -120,6 +121,26 @@ private CommandProvider status() {
120
121
});
121
122
}
122
123
124
+ @ NotNull
125
+ private CommandProvider dump () {
126
+ return (sub ) -> {
127
+ sub .setDefaultExecutor ((ctx ) -> {
128
+ final CommandUser user = user (sub , ctx );
129
+ plugin .getLocales ().getLocale ("system_dump_confirm" ).ifPresent (user ::sendMessage );
130
+ });
131
+ sub .addSubCommand ("confirm" , (con ) -> con .setDefaultExecutor ((ctx ) -> {
132
+ final CommandUser user = user (sub , ctx );
133
+ plugin .getLocales ().getLocale ("system_dump_started" ).ifPresent (user ::sendMessage );
134
+ plugin .runAsync (() -> {
135
+ final String url = plugin .createDump (user );
136
+ plugin .getLocales ().getLocale ("system_dump_ready" ).ifPresent (user ::sendMessage );
137
+ user .sendMessage (Component .text (url ).clickEvent (ClickEvent .openUrl (url ))
138
+ .decorate (TextDecoration .UNDERLINED ).color (NamedTextColor .GRAY ));
139
+ });
140
+ }));
141
+ };
142
+ }
143
+
123
144
@ NotNull
124
145
private CommandProvider reload () {
125
146
return (sub ) -> sub .setDefaultExecutor ((ctx ) -> {
@@ -234,86 +255,4 @@ private <S> ArgumentElement<S, Migrator> migrator() {
234
255
});
235
256
}
236
257
237
- private enum StatusLine {
238
- PLUGIN_VERSION (plugin -> Component .text ("v" + plugin .getPluginVersion ().toStringWithoutMetadata ())
239
- .appendSpace ().append (plugin .getPluginVersion ().getMetadata ().isBlank () ? Component .empty ()
240
- : Component .text ("(build " + plugin .getPluginVersion ().getMetadata () + ")" ))),
241
- SERVER_VERSION (plugin -> Component .text (plugin .getServerVersion ())),
242
- LANGUAGE (plugin -> Component .text (plugin .getSettings ().getLanguage ())),
243
- MINECRAFT_VERSION (plugin -> Component .text (plugin .getMinecraftVersion ().toString ())),
244
- JAVA_VERSION (plugin -> Component .text (System .getProperty ("java.version" ))),
245
- JAVA_VENDOR (plugin -> Component .text (System .getProperty ("java.vendor" ))),
246
- SERVER_NAME (plugin -> Component .text (plugin .getServerName ())),
247
- CLUSTER_ID (plugin -> Component .text (plugin .getSettings ().getClusterId ().isBlank () ? "None" : plugin .getSettings ().getClusterId ())),
248
- SYNC_MODE (plugin -> Component .text (WordUtils .capitalizeFully (
249
- plugin .getSettings ().getSynchronization ().getMode ().toString ()
250
- ))),
251
- DELAY_LATENCY (plugin -> Component .text (
252
- plugin .getSettings ().getSynchronization ().getNetworkLatencyMilliseconds () + "ms"
253
- )),
254
- DATABASE_TYPE (plugin ->
255
- Component .text (plugin .getSettings ().getDatabase ().getType ().getDisplayName () +
256
- (plugin .getSettings ().getDatabase ().getType () == Database .Type .MONGO ?
257
- (plugin .getSettings ().getDatabase ().getMongoSettings ().isUsingAtlas () ? " Atlas" : "" ) : "" ))
258
- ),
259
- IS_DATABASE_LOCAL (plugin -> getLocalhostBoolean (plugin .getSettings ().getDatabase ().getCredentials ().getHost ())),
260
- USING_REDIS_SENTINEL (plugin -> getBoolean (
261
- !plugin .getSettings ().getRedis ().getSentinel ().getMaster ().isBlank ()
262
- )),
263
- USING_REDIS_PASSWORD (plugin -> getBoolean (
264
- !plugin .getSettings ().getRedis ().getCredentials ().getPassword ().isBlank ()
265
- )),
266
- REDIS_USING_SSL (plugin -> getBoolean (
267
- plugin .getSettings ().getRedis ().getCredentials ().isUseSsl ()
268
- )),
269
- IS_REDIS_LOCAL (plugin -> getLocalhostBoolean (
270
- plugin .getSettings ().getRedis ().getCredentials ().getHost ()
271
- )),
272
- DATA_TYPES (plugin -> Component .join (
273
- JoinConfiguration .commas (true ),
274
- plugin .getRegisteredDataTypes ().stream ().map (i -> Component .textOfChildren (Component .text (i .toString ())
275
- .appendSpace ().append (Component .text (i .isEnabled () ? '✔' : '❌' )))
276
- .color (i .isEnabled () ? NamedTextColor .GREEN : NamedTextColor .RED )
277
- .hoverEvent (HoverEvent .showText (
278
- Component .text (i .isEnabled () ? "Enabled" : "Disabled" )
279
- .append (Component .newline ())
280
- .append (Component .text ("Dependencies: %s" .formatted (i .getDependencies ()
281
- .isEmpty () ? "(None)" : i .getDependencies ().stream ()
282
- .map (d -> "%s (%s)" .formatted (
283
- d .getKey ().value (), d .isRequired () ? "Required" : "Optional"
284
- )).collect (Collectors .joining (", " )))
285
- ).color (NamedTextColor .GRAY ))
286
- ))).toList ()
287
- ));
288
-
289
- private final Function <HuskSync , Component > supplier ;
290
-
291
- StatusLine (@ NotNull Function <HuskSync , Component > supplier ) {
292
- this .supplier = supplier ;
293
- }
294
-
295
- @ NotNull
296
- private Component get (@ NotNull HuskSync plugin ) {
297
- return Component
298
- .text ("•" ).appendSpace ()
299
- .append (Component .text (
300
- WordUtils .capitalizeFully (name ().replaceAll ("_" , " " )),
301
- TextColor .color (0x848484 )
302
- ))
303
- .append (Component .text (':' )).append (Component .space ().color (NamedTextColor .WHITE ))
304
- .append (supplier .apply (plugin ));
305
- }
306
-
307
- @ NotNull
308
- private static Component getBoolean (boolean value ) {
309
- return Component .text (value ? "Yes" : "No" , value ? NamedTextColor .GREEN : NamedTextColor .RED );
310
- }
311
-
312
- @ NotNull
313
- private static Component getLocalhostBoolean (@ NotNull String value ) {
314
- return getBoolean (value .equals ("127.0.0.1" ) || value .equals ("0.0.0.0" )
315
- || value .equals ("localhost" ) || value .equals ("::1" ));
316
- }
317
- }
318
-
319
258
}
0 commit comments