File tree Expand file tree Collapse file tree 10 files changed +40
-24
lines changed
src/main/java/dev/loat/command Expand file tree Collapse file tree 10 files changed +40
-24
lines changed Original file line number Diff line number Diff line change 11package dev .loat .command ;
22
3+ import java .util .function .Supplier ;
4+
35import com .mojang .brigadier .context .CommandContext ;
46
57import net .minecraft .commands .CommandSourceStack ;
8+ import net .minecraft .network .chat .Component ;
9+ import net .minecraft .world .entity .player .Player ;
610
711public class Command {
812 protected static boolean hasArgument (
@@ -11,4 +15,14 @@ protected static boolean hasArgument(
1115 ) {
1216 return context .getNodes ().stream ().anyMatch (node -> node .getNode ().getName ().equals (argument ));
1317 }
18+
19+ @ SuppressWarnings ("null" )
20+ protected static void sendSuccess (
21+ CommandContext <CommandSourceStack > context ,
22+ Supplier <Component > supplier
23+ ) {
24+ if (context .getSource ().getEntity () instanceof Player ) {
25+ context .getSource ().sendSuccess (supplier , false );
26+ }
27+ }
1428}
Original file line number Diff line number Diff line change 22
33import com .mojang .brigadier .context .CommandContext ;
44
5+ import dev .loat .command .Command ;
56import dev .loat .logging .Logger ;
67import net .minecraft .commands .CommandSourceStack ;
78import net .minecraft .network .chat .Component ;
8- import net .minecraft .world .entity .player .Player ;
99
1010
11- public final class Abort {
11+ public final class Abort extends Command {
1212 public static final String COMMAND = "abort" ;
1313
1414 public static int execute (CommandContext <CommandSourceStack > context ) {
15- String playerName ;
16-
17- if (context .getSource ().getEntity () instanceof Player ) {
18- playerName = context .getSource ().getPlayer ().getName ().getString ();
19- } else {
20- playerName = "Console" ;
21- }
15+ String playerName = context .getSource ().getTextName ();
2216
2317 Logger .info ("[%s] Aborting current action" .formatted (playerName ));
2418
25- context .getSource ().sendSuccess (() -> Component .literal ("/backup abort" ), false );
19+ Abort .sendSuccess (context , () -> Component .literal ("/backup abort" ));
20+
2621 return 1 ;
2722 }
2823}
Original file line number Diff line number Diff line change 22
33import com .mojang .brigadier .context .CommandContext ;
44
5+ import dev .loat .command .Command ;
56import dev .loat .logging .Logger ;
67import net .minecraft .commands .CommandSourceStack ;
78import net .minecraft .network .chat .Component ;
89
910
10- public final class Cleanup {
11+ public final class Cleanup extends Command {
1112 public static final String COMMAND = "cleanup" ;
1213
1314 public static int execute (CommandContext <CommandSourceStack > context ) {
1415 Logger .info ("Running cleanup process" );
1516
16- context .getSource ().sendSuccess (() -> Component .literal ("/backup cleanup" ), false );
17+ Cleanup .sendSuccess (context , () -> Component .literal ("/backup cleanup" ));
18+
1719 return 1 ;
1820 }
1921}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public static int execute(CommandContext<CommandSourceStack> context) {
2626 Logger .info ("[%s] Creating new backup" .formatted (playerName ));
2727 }
2828
29- context . getSource (). sendSuccess (() -> Component .literal ("/backup create \" %s\" " .formatted (comment )), false );
29+ Create . sendSuccess (context , () -> Component .literal ("/backup create \" %s\" " .formatted (comment )));
3030 return 1 ;
3131 }
3232}
Original file line number Diff line number Diff line change 33import com .mojang .brigadier .arguments .StringArgumentType ;
44import com .mojang .brigadier .context .CommandContext ;
55
6+ import dev .loat .command .Command ;
67import dev .loat .logging .Logger ;
78import net .minecraft .commands .CommandSourceStack ;
89import net .minecraft .network .chat .Component ;
910
1011
11- public final class Delete {
12+ public final class Delete extends Command {
1213 public static final String COMMAND = "delete" ;
1314 public static final String ARGUMENT = "name" ;
1415
@@ -19,7 +20,7 @@ public static int execute(CommandContext<CommandSourceStack> context) {
1920
2021 Logger .info ("Deleting existing backup \" %s\" " .formatted (name ));
2122
22- context . getSource (). sendSuccess (() -> Component .literal ("/backup delete \" %s\" " .formatted (name )), false );
23+ Delete . sendSuccess (context , () -> Component .literal ("/backup delete \" %s\" " .formatted (name )));
2324 return 1 ;
2425 }
2526}
Original file line number Diff line number Diff line change 22
33import com .mojang .brigadier .context .CommandContext ;
44
5+ import dev .loat .command .Command ;
56import dev .loat .logging .Logger ;
67import net .minecraft .commands .CommandSourceStack ;
78import net .minecraft .network .chat .Component ;
89
910
10- public final class Help {
11+ public final class Help extends Command {
1112 public static final String COMMAND = "help" ;
1213
1314 public static int execute (CommandContext <CommandSourceStack > context ) {
1415 Logger .info ("Getting help" );
1516
16- context . getSource (). sendSuccess (() -> Component .literal ("/backup help" ), false );
17+ Help . sendSuccess (context , () -> Component .literal ("/backup help" ));
1718 return 1 ;
1819 }
1920}
Original file line number Diff line number Diff line change 33import com .mojang .brigadier .arguments .StringArgumentType ;
44import com .mojang .brigadier .context .CommandContext ;
55
6+ import dev .loat .command .Command ;
67import dev .loat .logging .Logger ;
78import net .minecraft .commands .CommandSourceStack ;
89import net .minecraft .network .chat .Component ;
910
1011
11- public final class Info {
12+ public final class Info extends Command {
1213 public static final String COMMAND = "info" ;
1314 public static final String ARGUMENT = "name" ;
1415
@@ -18,7 +19,7 @@ public static int execute(CommandContext<CommandSourceStack> context) {
1819
1920 Logger .info ("Getting info about existing backup \" %s\" " .formatted (name ));
2021
21- context . getSource (). sendSuccess (() -> Component .literal ("/backup info \" %s\" " .formatted (name )), false );
22+ Info . sendSuccess (context , () -> Component .literal ("/backup info \" %s\" " .formatted (name )));
2223 return 1 ;
2324 }
2425}
Original file line number Diff line number Diff line change 22
33import com .mojang .brigadier .context .CommandContext ;
44
5+ import dev .loat .command .Command ;
56import dev .loat .logging .Logger ;
67import net .minecraft .commands .CommandSourceStack ;
78import net .minecraft .network .chat .Component ;
89
910
10- public final class List {
11+ public final class List extends Command {
1112 public static final String COMMAND = "list" ;
1213
1314 public static int execute (CommandContext <CommandSourceStack > context ) {
1415 Logger .info ("Listing all backups" );
1516
16- context . getSource (). sendSuccess (() -> Component .literal ("/backup list" ), false );
17+ List . sendSuccess (context , () -> Component .literal ("/backup list" ));
1718 return 1 ;
1819 }
1920}
Original file line number Diff line number Diff line change 22
33import com .mojang .brigadier .context .CommandContext ;
44
5+ import dev .loat .command .Command ;
56import dev .loat .logging .Logger ;
67import net .minecraft .commands .CommandSourceStack ;
78import net .minecraft .network .chat .Component ;
89
910
10- public final class Reload {
11+ public final class Reload extends Command {
1112 public static final String COMMAND = "reload" ;
1213
1314 public static int execute (CommandContext <CommandSourceStack > context ) {
1415 Logger .info ("Reloading config" );
1516
16- context . getSource (). sendSuccess (() -> Component .literal ("/backup reload" ), false );
17+ Reload . sendSuccess (context , () -> Component .literal ("/backup reload" ));
1718 return 1 ;
1819 }
1920}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public static int execute(CommandContext<CommandSourceStack> context) {
2929
3030 Logger .info ("Restoring existing backup \" %s\" " .formatted (name ));
3131
32- context . getSource (). sendSuccess (() -> Component .literal ("/backup restore \" %s\" " .formatted (name )), false );
32+ Restore . sendSuccess (context , () -> Component .literal ("/backup restore \" %s\" " .formatted (name )));
3333 return 1 ;
3434 }
3535}
You can’t perform that action at this time.
0 commit comments