Skip to content

Commit 4d54cbc

Browse files
committed
optimized workflow
1 parent c48e620 commit 4d54cbc

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

servermanager-node/src/main/java/com/nexoscript/servermanager/node/ServerManagerNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ public void shutdownHook() {
2525
}));
2626
}
2727

28-
public Console getConsole() {
28+
public Console console() {
2929
return this.console;
3030
}
3131

32-
public ServerActionRunner getActionRunner() {
32+
public ServerActionRunner actionRunner() {
3333
return this.actionRunner;
3434
}
3535

36-
public TemplateManager getTemplateManager() {
36+
public TemplateManager templateManager() {
3737
return templateManager;
3838
}
3939

servermanager-node/src/main/java/com/nexoscript/servermanager/node/config/JsonConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Object get(String key) {
7777
public void save() {
7878
File file = new File(this.configFile.toString());
7979
try (FileWriter fileWriter = new FileWriter(file)) {
80-
fileWriter.write(this.jsonObject.toString());
80+
fileWriter.write(this.jsonObject.toString(4));
8181
fileWriter.flush();
8282
} catch (IOException e) {
8383
throw new RuntimeException(e);

servermanager-node/src/main/java/com/nexoscript/servermanager/node/console/Console.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public void start() {
8888
System.out.println("Template " + commandParts[2] + " gelöscht.");
8989
}
9090
case "list" -> {
91-
if (this.templateManager.getTemplates().isEmpty()) {
91+
if (this.templateManager.templates().isEmpty()) {
9292
System.out.println("Keine Templates gefunden.");
9393
continue;
9494
}
95-
this.templateManager.getTemplates().forEach((name, path) -> System.out.printf("- %s -> %s%n", name, path.toString()));
95+
this.templateManager.templates().forEach((name, path) -> System.out.printf("- %s -> %s%n", name, path.toString()));
9696
}
9797
}
9898
}

servermanager-node/src/main/java/com/nexoscript/servermanager/node/server/MinecraftServerProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void start() {
5353
} catch (IOException e) {
5454
e.printStackTrace();
5555
} finally {
56-
this.node.getActionRunner().getServers().remove(name);
56+
this.node.actionRunner().servers().remove(name);
5757
insideConsole = false;
5858
}
5959
});

servermanager-node/src/main/java/com/nexoscript/servermanager/node/server/ServerActionRunner.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import java.nio.file.Files;
77
import java.nio.file.Path;
88
import java.nio.file.StandardCopyOption;
9-
import java.util.ArrayList;
10-
import java.util.HashMap;
11-
import java.util.Map;
12-
import java.util.Scanner;
9+
import java.util.*;
10+
import java.util.stream.Stream;
1311

1412
public class ServerActionRunner {
1513
private final ServerManagerNode node;
@@ -23,33 +21,31 @@ public ServerActionRunner(ServerManagerNode node, TemplateManager templateManage
2321
}
2422

2523
public void createServer(Path path, String templateName) {
26-
try {
2724
if (!path.toFile().mkdirs()) {
2825
System.out.println("Konnte Pfad nicht erstellen.");
2926
return;
3027
}
31-
Path templatePath = this.templateManager.getTemplate(templateName);
28+
Path templatePath = this.templateManager.templatePath(templateName);
3229
if (templatePath == null) {
3330
System.out.println("Template Pfad konnte nicht gefunden werden.");
3431
return;
3532
}
3633
System.out.println("[SERVER] Template-Path: " + templatePath);
37-
Files.walk(templatePath).forEach(source -> {
34+
try (Stream<Path> files = Files.walk(templatePath)) {
35+
files.forEach(source -> {
3836
try {
3937
Path destination = path.resolve(templatePath.relativize(source));
40-
4138
if (Files.isDirectory(source)) {
4239
Files.createDirectories(destination);
4340
return;
4441
}
45-
4642
Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
4743
} catch (Exception e) {
4844
System.out.println("Fehler beim Erstellen des Servers mit Pfad '" + path + "': " + e.getMessage());
4945
}
5046
});
5147
} catch (Exception e) {
52-
System.out.println("Fehler beim Erstellen des Servers mit Pfad '" + path.toString() + "': " + e.getMessage());
48+
System.out.println("Fehler beim Erstellen des Servers mit Pfad '" + path + "': " + e.getMessage());
5349
}
5450
}
5551

@@ -98,7 +94,7 @@ public void shutdownAllServers() {
9894
System.out.println("Alle Server gestoppt.");
9995
}
10096

101-
public Map<String, MinecraftServerProcess> getServers() {
97+
public Map<String, MinecraftServerProcess> servers() {
10298
return servers;
10399
}
104100
}

servermanager-node/src/main/java/com/nexoscript/servermanager/node/template/TemplateManager.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.nio.file.attribute.BasicFileAttributes;
1111
import java.util.HashMap;
1212
import java.util.Map;
13-
import java.util.Objects;
1413

1514
public class TemplateManager {
1615
private final String templatesPath;
@@ -36,7 +35,7 @@ public TemplateManager() {
3635
}
3736

3837
public void createTemplate(String name) {
39-
if (this.getTemplate(name) != null) {
38+
if (this.templatePath(name) != null) {
4039
System.out.println("Template " + name + " already exists");
4140
return;
4241
}
@@ -64,15 +63,15 @@ public void createTemplate(String name) {
6463
}
6564

6665
public void renameTemplate(String name, String newName) {
67-
if (this.getTemplate(name) == null) {
66+
if (this.templatePath(name) == null) {
6867
System.out.println("Template " + name + " does not exist");
6968
return;
7069
}
7170
try {
7271
this.createTemplate(newName);
73-
System.out.println(this.getTemplate(name).toString());
74-
System.out.println(this.getTemplate(newName).toString());
75-
Files.move(this.getTemplate(name), this.getTemplate(newName), StandardCopyOption.ATOMIC_MOVE);
72+
System.out.println(this.templatePath(name).toString());
73+
System.out.println(this.templatePath(newName).toString());
74+
Files.move(this.templatePath(name), this.templatePath(newName), StandardCopyOption.ATOMIC_MOVE);
7675
JSONArray templatesArray = (JSONArray) this.templatesConfig.get("templates");
7776
for (int i = 0; i < templatesArray.length(); i++) {
7877
JSONObject object = templatesArray.getJSONObject(i);
@@ -95,11 +94,11 @@ public void renameTemplate(String name, String newName) {
9594

9695
public void deleteTemplate(String name) {
9796
try {
98-
if (this.getTemplate(name) == null) {
97+
if (this.templatePath(name) == null) {
9998
System.out.println("Template " + name + " does not exist");
10099
return;
101100
}
102-
Files.walkFileTree(this.getTemplate(name), new SimpleFileVisitor<>() {
101+
Files.walkFileTree(this.templatePath(name), new SimpleFileVisitor<>() {
103102
@Override
104103
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
105104
Files.delete(file);
@@ -131,7 +130,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
131130
}
132131
}
133132

134-
public Path getTemplate(String name) {
133+
public Path templatePath(String name) {
135134
JSONArray templatesArray = (JSONArray) this.templatesConfig.get("templates");
136135
for (int i = 0; i < templatesArray.length(); i++) {
137136
JSONObject object = templatesArray.getJSONObject(i);
@@ -142,7 +141,7 @@ public Path getTemplate(String name) {
142141
return null;
143142
}
144143

145-
public Map<String, Path> getTemplates() {
144+
public Map<String, Path> templates() {
146145
return templates;
147146
}
148147
}

0 commit comments

Comments
 (0)