Don't rewrite files with no placeholders

This commit is contained in:
ME1312 2020-12-20 22:30:33 -05:00
parent fe4f19e713
commit 08b56fc823
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
3 changed files with 29 additions and 9 deletions

View File

@ -156,10 +156,20 @@ public class ReplacementScanner {
String string = Util.readAll(new InputStreamReader(stream));
stream.close();
for (Map.Entry<String, String> replacement : replacements.entrySet()) string = string.replace("SubServers::" + replacement.getKey(), replacement.getValue());
FileWriter writer = new FileWriter(file, false);
writer.write(string);
writer.close();
boolean update = false;
for (Map.Entry<String, String> replacement : replacements.entrySet()) {
String placeholder = "SubServers::" + replacement.getKey();
if (string.contains(placeholder)) {
string = string.replace(placeholder, replacement.getValue());
update = true;
}
}
if (update) {
FileWriter writer = new FileWriter(file, false);
writer.write(string);
writer.close();
}
}

View File

@ -128,6 +128,7 @@ public final class SubCommand extends CommandX {
case "system":
case "bungee":
case "bungeecord":
case "subdata":
case "network":
plugin.getPluginManager().dispatchCommand(ConsoleCommandSender.getInstance(), "greload");
break;
@ -137,7 +138,6 @@ public final class SubCommand extends CommandX {
case "servers":
case "subserver":
case "subservers":
case "subdata":
case "config":
case "configs":
try {

View File

@ -156,10 +156,20 @@ public class ReplacementScanner {
String string = Util.readAll(new InputStreamReader(stream));
stream.close();
for (Map.Entry<String, String> replacement : replacements.entrySet()) string = string.replace("SubServers::" + replacement.getKey(), replacement.getValue());
FileWriter writer = new FileWriter(file, false);
writer.write(string);
writer.close();
boolean update = false;
for (Map.Entry<String, String> replacement : replacements.entrySet()) {
String placeholder = "SubServers::" + replacement.getKey();
if (string.contains(placeholder)) {
string = string.replace(placeholder, replacement.getValue());
update = true;
}
}
if (update) {
FileWriter writer = new FileWriter(file, false);
writer.write(string);
writer.close();
}
}