Skip to content

Commit

Permalink
Add ability to cancel server rename
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed May 13, 2024
1 parent c930e5d commit 3565bc2
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/main/java/net/kyrptonaught/ToolBox/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,23 @@ public static void existingMenu(BufferedReader input) {
System.out.println();
checkEula(input, serverInfo);
} else if (selectedAction == 6) {
String newName = askServerName(input, serverInfo.getName());

System.out.println();
System.out.println("Renaming to " + newName);
FileHelper.renameDirectory(serverInfo.getPath(), Path.of("installs/" + newName));
serverInfo.setName(newName);
serverInfo.setPath();
Installer.saveInstalledServerInfo(serverInfo);
System.out.println("Complete");
String newName = askServerName(input, serverInfo.getName(), true);
System.out.println();

if (newName.equals(serverInfo.getName())) {
System.out.println("Same name entered, canceling");
System.out.println();
pressEnterToCont(input);
} else {
System.out.println("Renaming to " + newName);
FileHelper.renameDirectory(serverInfo.getPath(), Path.of("installs/" + newName));
serverInfo.setName(newName);
serverInfo.setPath();
Installer.saveInstalledServerInfo(serverInfo);
System.out.println("Complete");
System.out.println();
pressEnterToCont(input);
}
} else if (selectedAction == 7) {
System.out.println("This server and all data associated with it will be permanently deleted before being reinstalled.");
System.out.println("This is irreversible.");
Expand Down Expand Up @@ -343,7 +350,7 @@ public static void installMenu(BufferedReader input) {
System.out.println("Configuring server");
System.out.println();

String enteredServerName = askServerName(input, branch.name);
String enteredServerName = askServerName(input, branch.name, false);
System.out.println();

System.out.println("How much RAM do you want to allocate to the server?");
Expand Down Expand Up @@ -451,19 +458,23 @@ public static void importMenu(BufferedReader input) {
}
}

public static String askServerName(BufferedReader input, String defaultName) {
public static String askServerName(BufferedReader input, String defaultName, boolean renaming) {
System.out.println("Please enter a name for this server, or leave blank for default (" + defaultName + "): ");
System.out.println();
System.out.print("Server Name: ");
String enteredServerName = readLine(input);
if (enteredServerName.isBlank()) enteredServerName = defaultName;
enteredServerName = FileNameCleaner.cleanFileName(enteredServerName);

if (renaming && enteredServerName.equals(defaultName))
return enteredServerName;

if (getServerFromName(enteredServerName) != null) {
System.out.println("A server with that name already exists.");
System.out.println();
return askServerName(input, defaultName);
return askServerName(input, defaultName, renaming);
}

return enteredServerName;
}

Expand Down

0 comments on commit 3565bc2

Please sign in to comment.