22
22
import de .themoep .minedown .adventure .MineDown ;
23
23
import net .kyori .adventure .text .Component ;
24
24
import net .kyori .adventure .text .JoinConfiguration ;
25
+ import net .kyori .adventure .text .event .ClickEvent ;
25
26
import net .kyori .adventure .text .format .NamedTextColor ;
26
27
import net .kyori .adventure .text .format .TextColor ;
28
+ import net .kyori .adventure .text .format .TextDecoration ;
27
29
import net .william278 .desertwell .about .AboutMenu ;
28
30
import net .william278 .desertwell .util .UpdateChecker ;
29
31
import net .william278 .husktowns .HuskTowns ;
30
32
import net .william278 .husktowns .migrator .LegacyMigrator ;
31
33
import net .william278 .husktowns .migrator .Migrator ;
32
34
import net .william278 .husktowns .user .CommandUser ;
33
- import org . apache . commons . text . WordUtils ;
35
+ import net . william278 . husktowns . util . StatusLine ;
34
36
import org .jetbrains .annotations .NotNull ;
35
37
import org .jetbrains .annotations .Nullable ;
36
38
37
39
import java .util .ArrayList ;
38
40
import java .util .Arrays ;
39
41
import java .util .List ;
40
42
import java .util .Optional ;
41
- import java .util .function .Function ;
42
43
43
44
public final class HuskTownsCommand extends Command {
44
45
@@ -50,6 +51,7 @@ public HuskTownsCommand(@NotNull HuskTowns plugin) {
50
51
new ReloadCommand (this , plugin ),
51
52
new UpdateCommand (this , plugin ),
52
53
new StatusCommand (this , plugin ),
54
+ new DumpCommand (this , plugin ),
53
55
new MigrateCommand (this , plugin ),
54
56
getHelpCommand (),
55
57
(ChildCommand ) getDefaultExecutor ()
@@ -149,6 +151,31 @@ public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
149
151
}
150
152
}
151
153
154
+ private static class DumpCommand extends ChildCommand {
155
+
156
+ protected DumpCommand (@ NotNull Command parent , @ NotNull HuskTowns plugin ) {
157
+ super ("dump" , List .of (), parent , "<confirm>" , plugin );
158
+ this .setConsoleExecutable (true );
159
+ this .setOperatorCommand (true );
160
+ }
161
+
162
+ @ Override
163
+ public void execute (@ NotNull CommandUser executor , @ NotNull String [] args ) {
164
+ if (!parseStringArg (args , 0 ).map (s -> s .equals ("confirm" )).orElse (false )) {
165
+ plugin .getLocales ().getLocale ("system_dump_confirm" ).ifPresent (executor ::sendMessage );
166
+ return ;
167
+ }
168
+
169
+ plugin .getLocales ().getLocale ("system_dump_started" ).ifPresent (executor ::sendMessage );
170
+ plugin .runAsync (() -> {
171
+ final String url = plugin .createDump (executor );
172
+ plugin .getLocales ().getLocale ("system_dump_ready" ).ifPresent (executor ::sendMessage );
173
+ executor .sendMessage (Component .text (url ).clickEvent (ClickEvent .openUrl (url ))
174
+ .decorate (TextDecoration .UNDERLINED ).color (NamedTextColor .GRAY ));
175
+ });
176
+ }
177
+ }
178
+
152
179
private static class MigrateCommand extends ChildCommand implements TabProvider {
153
180
private final List <Migrator > migrators = new ArrayList <>();
154
181
@@ -236,64 +263,4 @@ public List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
236
263
}
237
264
}
238
265
239
- private enum StatusLine {
240
- PLUGIN_VERSION (plugin -> Component .text ("v" + plugin .getPluginVersion ().toStringWithoutMetadata ())
241
- .appendSpace ().append (plugin .getPluginVersion ().getMetadata ().isBlank () ? Component .empty ()
242
- : Component .text ("(build " + plugin .getPluginVersion ().getMetadata () + ")" ))),
243
- SERVER_VERSION (plugin -> Component .text (plugin .getServerType ())),
244
- LANGUAGE (plugin -> Component .text (plugin .getSettings ().getLanguage ())),
245
- MINECRAFT_VERSION (plugin -> Component .text (plugin .getMinecraftVersion ().toString ())),
246
- JAVA_VERSION (plugin -> Component .text (System .getProperty ("java.version" ))),
247
- JAVA_VENDOR (plugin -> Component .text (System .getProperty ("java.vendor" ))),
248
- SERVER_NAME (plugin -> Component .text (plugin .getServerName ())),
249
- DATABASE_TYPE (plugin -> Component .text (plugin .getSettings ().getDatabase ().getType ().getDisplayName ())),
250
- IS_DATABASE_LOCAL (plugin -> getLocalhostBoolean (plugin .getSettings ().getDatabase ().getCredentials ().getHost ())),
251
- USING_REDIS_SENTINEL (plugin -> getBoolean (!plugin .getSettings ().getCrossServer ().getRedis ().getSentinel ()
252
- .getMasterName ().isBlank ())),
253
- USING_REDIS_PASSWORD (plugin -> getBoolean (!plugin .getSettings ().getCrossServer ().getRedis ().getPassword ()
254
- .isBlank ())),
255
- REDIS_USING_SSL (plugin -> getBoolean (!plugin .getSettings ().getCrossServer ().getRedis ().isUseSsl ())),
256
- IS_REDIS_LOCAL (plugin -> getLocalhostBoolean (plugin .getSettings ().getCrossServer ().getRedis ().getHost ())),
257
- REGISTERED_CUSTOM_OPERATION_TYPES (plugin -> Component .join (
258
- JoinConfiguration .commas (true ),
259
- plugin .getOperationListener ().getRegisteredOperationTypes ().stream ()
260
- .filter (t -> !t .getKey ().namespace ().equals ("cloplib" ))
261
- .map (tag -> Component .text (tag .getKey ().asString ())).toList ()
262
- )),
263
- LOADED_HOOKS (plugin -> Component .join (
264
- JoinConfiguration .commas (true ),
265
- plugin .getHookManager ().getHooks ().stream ()
266
- .map (hook -> Component .text (hook .getHookInfo ().id ())).toList ()
267
- ));
268
-
269
- private final Function <HuskTowns , Component > supplier ;
270
-
271
- StatusLine (@ NotNull Function <HuskTowns , Component > supplier ) {
272
- this .supplier = supplier ;
273
- }
274
-
275
- @ NotNull
276
- private Component get (@ NotNull HuskTowns plugin ) {
277
- return Component
278
- .text ("•" ).appendSpace ()
279
- .append (Component .text (
280
- WordUtils .capitalizeFully (name ().replaceAll ("_" , " " )),
281
- TextColor .color (0x848484 )
282
- ))
283
- .append (Component .text (':' )).append (Component .space ().color (NamedTextColor .WHITE ))
284
- .append (supplier .apply (plugin ));
285
- }
286
-
287
- @ NotNull
288
- private static Component getBoolean (boolean value ) {
289
- return Component .text (value ? "Yes" : "No" , value ? NamedTextColor .GREEN : NamedTextColor .RED );
290
- }
291
-
292
- @ NotNull
293
- private static Component getLocalhostBoolean (@ NotNull String value ) {
294
- return getBoolean (value .equals ("127.0.0.1" ) || value .equals ("0.0.0.0" )
295
- || value .equals ("localhost" ) || value .equals ("::1" ));
296
- }
297
- }
298
-
299
266
}
0 commit comments