forked from upstream/ProAntiTab
Add AutoConfigUpdater
This commit is contained in:
1 parent
9bbbb06163
commit
912e00dba8
2 files changed
+33
-7
No files matched your search
@@ -7,11 +7,10 @@ import java.util.*;
|
||||
|
||||
public class ConfigSection {
|
||||
|
||||
private final File oldConfigFile, newConfigFile;
|
||||
private final File oldConfigFile;
|
||||
|
||||
public ConfigSection(File oldConfigFile, File newConfigFile) {
|
||||
public ConfigSection(File oldConfigFile) {
|
||||
this.oldConfigFile = oldConfigFile;
|
||||
this.newConfigFile = newConfigFile;
|
||||
}
|
||||
|
||||
public List<String> createAndGetNewFileInput(int interceptLine, int from, int to) {
|
||||
@@ -19,12 +18,12 @@ public class ConfigSection {
|
||||
originalFileInput = new ArrayList<>();
|
||||
|
||||
try {
|
||||
|
||||
originalFileInput = Files.readAllLines(oldConfigFile.toPath());
|
||||
|
||||
while(!originalFileInput.get(interceptLine).isEmpty()) interceptLine++;
|
||||
originalFileInput.addAll(interceptLine, interceptedInput);
|
||||
|
||||
} catch (Exception exception) {
|
||||
Logger.warning("Failed to read file input!");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ public class ConfigSection {
|
||||
|
||||
try {
|
||||
|
||||
lines = Files.readAllLines(newConfigFile.toPath());
|
||||
lines = ConfigUpdater.getNewestConfigInput();
|
||||
String targetString = lines.get(from);
|
||||
boolean foundLine = false;
|
||||
int line = from;
|
||||
|
||||
@@ -1,8 +1,35 @@
|
||||
package de.rayzs.pat.utils.configuration.updater;
|
||||
|
||||
import de.rayzs.pat.utils.configuration.ConfigurationBuilder;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class ConfigUpdater {
|
||||
|
||||
public static void method() {
|
||||
private static List<String> NEWEST_CONFIG_INPUT = new ArrayList<>();
|
||||
|
||||
public static void initialize() {
|
||||
NEWEST_CONFIG_INPUT = new ConnectionBuilder().setUrl("https://raw.githubusercontent.com/RayzsYT/ProAntiTab/main/src/main/resources/files/"
|
||||
+ (Reflection.isProxyServer() ? " proxy" : "bukkit")
|
||||
+ "-config.yml").connect().getResponseList();
|
||||
}
|
||||
|
||||
public static void updateConfigFile(ConfigurationBuilder configurationBuilder, int atLine, int from, int to) {
|
||||
File file = configurationBuilder.getFile();
|
||||
ConfigSection configSection = new ConfigSection(file);
|
||||
String sectionAsString = StringUtils.buildStringList(configSection.createAndGetNewFileInput(atLine, from, to));
|
||||
|
||||
try {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file, false));
|
||||
writer.write(sectionAsString);
|
||||
writer.close();
|
||||
}catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getNewestConfigInput() {
|
||||
return NEWEST_CONFIG_INPUT;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user