Temp file converter

This commit is contained in:
Norbi Peti 2016-08-22 15:29:10 +02:00
parent 495e5b17d8
commit 761071d941

View file

@ -1,67 +1,51 @@
package buttondevteam.serverrunner; package buttondevteam.serverrunner;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
public class ServerRunner { public class ServerRunner {
private static final String SERVER_VERSION = "1.9.2"; private static final String SERVER_VERSION = "1.9.2";
private static boolean stop = false; private static boolean stop = false;
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("Starting server..."); YamlConfiguration yc = YamlConfiguration.loadConfiguration(new File("thebuttonmc.yml"));
Process p = Runtime.getRuntime().exec(new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M", ConfigurationSection cs = yc.getConfigurationSection("players");
"-jar", "spigot-" + SERVER_VERSION + ".jar" }); for (String key : cs.getKeys(false)) {
final Thread it = new Thread() { ConfigurationSection cs2 = cs.getConfigurationSection(key);
@Override String uuid = cs2.getString("uuid");
public void run() { YamlConfiguration pyc = new YamlConfiguration();
PrintWriter output = new PrintWriter(p.getOutputStream()); copy(pyc, cs2, "playername");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); copy(pyc, cs2, "username");
try { copy(pyc, cs2, "flairtime");
while (!stop) { copy(pyc, cs2, "flairstate");
String readLine = br.readLine(); copy(pyc, cs2, "uuid");
output.println(readLine); copy(pyc, cs2, "usernames");
output.flush(); copy(pyc, cs2, "fcount");
if (readLine.contains("stop")) copy(pyc, cs2, "fdeaths");
stop = true; copy(pyc, cs2, "flaircheater");
} pyc.save(new File(uuid + ".yml"));
} catch (IOException e) {
e.printStackTrace();
}
stop = true;
System.out.println("Stopped " + Thread.currentThread().getName());
}
};
it.setName("InputThread");
it.start();
final Thread ot = new Thread() {
@Override
public void run() {
try {
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null && !stop) {
System.out.println(line);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
stop = true;
System.out.println("Stopped " + Thread.currentThread().getName());
}
};
ot.setName("OutputThread");
ot.start();
Thread.currentThread().setName("RestarterThread");
while (!stop) {
Thread.sleep(10000);
System.out.println("RESTART");
} }
System.out.println("Stopped " + Thread.currentThread().getName()); /*
* System.out.println("Starting server..."); Process p = Runtime.getRuntime().exec(new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M", "-jar", "spigot-" + SERVER_VERSION +
* ".jar" }); final Thread it = new Thread() {
* @Override public void run() { PrintWriter output = new PrintWriter(p.getOutputStream()); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { while (!stop) {
* String readLine = br.readLine(); output.println(readLine); output.flush(); if (readLine.contains("stop")) stop = true; } } catch (IOException e) { e.printStackTrace(); } stop = true;
* System.out.println("Stopped " + Thread.currentThread().getName()); } }; it.setName("InputThread"); it.start(); final Thread ot = new Thread() {
* @Override public void run() { try { BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null && !stop) {
* System.out.println(line); } input.close(); } catch (IOException e) { e.printStackTrace(); } stop = true; System.out.println("Stopped " + Thread.currentThread().getName()); } };
* ot.setName("OutputThread"); ot.start(); Thread.currentThread().setName("RestarterThread"); while (!stop) { Thread.sleep(10000); System.out.println("RESTART"); }
* System.out.println("Stopped " + Thread.currentThread().getName());
*/
}
private static void copy(YamlConfiguration pyc, ConfigurationSection cs2, String name) {
pyc.set(name, cs2.get(name));
} }
} }