11package com .nexoscript .servermanager .node .console ;
22
3+ import java .nio .file .Path ;
34import java .util .Scanner ;
45
56import com .nexoscript .servermanager .node .server .ServerActionRunner ;
@@ -9,7 +10,6 @@ public class Console {
910 private final TemplateManager templateManager ;
1011 private final ServerActionRunner actionRunner ;
1112 private final Scanner scanner ;
12-
1313 private boolean running ;
1414
1515 public Console (TemplateManager templateManager , ServerActionRunner actionRunner ) {
@@ -20,58 +20,81 @@ public Console(TemplateManager templateManager, ServerActionRunner actionRunner)
2020 }
2121
2222 public void start () {
23- System .out .println ("Multi- Server Manager gestartet. Verwenden Sie 'start', 'stop', 'console', oder 'exit'." );
23+ System .out .println ("Server- Manager gestartet. Verwenden Sie 'start', 'stop', 'console', 'template ', oder 'exit'." );
2424 while (this .running ) {
2525 String input = this .scanner .nextLine ();
2626 String [] commandParts = input .split (" " , 4 );
27- if (commandParts .length < 1 )
27+ if (commandParts .length < 1 ) {
2828 continue ;
29+ }
2930 String command = commandParts [0 ].toLowerCase ();
3031 switch (command ) {
32+ case "create" -> {
33+ if (commandParts .length < 3 || commandParts [1 ].isBlank () || commandParts [2 ].isBlank ()) {
34+ System .out .println ("Verwendung: create <path> <template>" );
35+ continue ;
36+ }
37+ this .actionRunner .createServer (Path .of (commandParts [1 ]), commandParts [2 ]);
38+ }
3139 case "start" -> {
3240 if (commandParts .length < 4 ) {
3341 System .out .println ("Verwendung: start <servername> <path> <jar>" );
34- break ;
42+ continue ;
3543 }
3644 this .actionRunner .startServer (commandParts [1 ], commandParts [2 ], commandParts [3 ]);
3745 }
3846 case "stop" -> {
3947 if (commandParts .length < 2 ) {
4048 System .out .println ("Verwendung: stop <servername>" );
41- break ;
49+ continue ;
4250 }
4351 this .actionRunner .stopServer (commandParts [1 ]);
4452 }
4553 case "console" -> {
4654 if (commandParts .length < 2 ) {
4755 System .out .println ("Verwendung: console <servername>" );
48- break ;
56+ continue ;
4957 }
5058 this .actionRunner .openConsole (this .scanner , commandParts [1 ]);
5159 }
52- case "create- template" -> {
60+ case "template" -> {
5361 if (commandParts .length < 2 ) {
54- System .out .println ("Verwendung: create-template <name> " );
55- break ;
62+ System .out .println ("Verwendung: ' create', 'rename', 'delete' oder 'list' " );
63+ continue ;
5664 }
57- this .templateManager .createTemplate (commandParts [1 ]);
58- System .out .println ("Template " + commandParts [1 ] + " erstellt." );
59- }
60- case "rename-template" -> {
61- if (commandParts .length < 3 ) {
62- System .out .println ("Verwendung: rename-template <name> <newName>" );
63- break ;
64- }
65- this .templateManager .renameTemplate (commandParts [1 ], commandParts [2 ]);
66- System .out .println ("Template " + commandParts [1 ] + " zu " + commandParts [2 ] + " umbenannt." );
67- }
68- case "delete-template" -> {
69- if (commandParts .length < 2 ) {
70- System .out .println ("Verwendung: delete-template <name>" );
71- break ;
65+ switch (commandParts [1 ].toLowerCase ()) {
66+ case "create" -> {
67+ if (commandParts .length < 3 || commandParts [2 ].isBlank ()) {
68+ System .out .println ("Verwendung: template create <name>" );
69+ continue ;
70+ }
71+ this .templateManager .createTemplate (commandParts [2 ]);
72+ System .out .println ("Template " + commandParts [2 ] + " erstellt." );
73+ }
74+ case "rename" -> {
75+ if (commandParts .length < 4 || commandParts [2 ].isBlank () || commandParts [3 ].isBlank ()) {
76+ System .out .println ("Verwendung: template rename <name> <newName>" );
77+ continue ;
78+ }
79+ this .templateManager .renameTemplate (commandParts [2 ], commandParts [3 ]);
80+ System .out .println ("Template " + commandParts [2 ] + " zu " + commandParts [3 ] + " umbenannt." );
81+ }
82+ case "delete" -> {
83+ if (commandParts .length < 3 || commandParts [2 ].isBlank ()) {
84+ System .out .println ("Verwendung: template delete <name>" );
85+ continue ;
86+ }
87+ this .templateManager .deleteTemplate (commandParts [2 ]);
88+ System .out .println ("Template " + commandParts [2 ] + " gelöscht." );
89+ }
90+ case "list" -> {
91+ if (this .templateManager .getTemplates ().isEmpty ()) {
92+ System .out .println ("Keine Templates gefunden." );
93+ continue ;
94+ }
95+ this .templateManager .getTemplates ().forEach ((name , path ) -> System .out .printf ("- %s -> %s%n" , name , path .toString ()));
96+ }
7297 }
73- this .templateManager .deleteTemplate (commandParts [1 ]);
74- System .out .println ("Template " + commandParts [1 ] + " gelöscht." );
7598 }
7699 case "exit" -> this .running = false ;
77100 default -> System .out .println ("Unbekannter Befehl: " + command );
0 commit comments