Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.Panakotta00.BedWars;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.InetAddress;
- import java.net.ServerSocket;
- import java.net.Socket;
- import org.bukkit.Bukkit;
- import org.bukkit.configuration.file.YamlConfiguration;
- import de.Panakotta00.BedWars.Arena.ArenaTemplate;
- public class SocketSystem implements Runnable {
- BedWars main;
- Thread thread;
- boolean loop = true;
- ServerSocket socket;
- public Socket lobby;
- Socket bungee;
- int port;
- public SocketSystem(BedWars main, int port, String bungeehost, int bungeeport) {
- this.main = main;
- this.port = port;
- try {
- socket = new ServerSocket(port, 0, InetAddress.getByName("localhost"));;
- thread = new Thread(this);
- thread.start();
- System.out.println("ServerSocket auf Port " + port + " und IP " + socket.getInetAddress() + " gestartet!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- bungee = new Socket(InetAddress.getByName(bungeehost.intern()), bungeeport);
- PrintStream out = new PrintStream(bungee.getOutputStream());
- out.println("arena");
- out.println(main.id);
- out.flush();
- System.out.println("BungeeSocket gestartet!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void run() {
- while (loop) {
- try {
- Socket socket = this.socket.accept();
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String cmd = String.valueOf(in.readLine()).intern();
- if (cmd.equals("servercontroller")) {
- lobby = socket;
- main.id = Integer.valueOf(in.readLine());
- String s = in.readLine();
- while (s != null) {
- main.arenas.put(s.intern(), loadTemplate(s.intern()));
- s = in.readLine();
- }
- }
- main.nextArena();
- } catch (IOException e) {
- e.printStackTrace();
- if (socket.isClosed()) {
- this.stop();
- }
- }
- }
- this.stop();
- }
- @SuppressWarnings("deprecation")
- public void stop() {
- if (loop) {
- loop = false;
- }
- if (!socket.isClosed()) {
- try {
- socket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (thread.isAlive()) {
- thread.stop();
- }
- }
- private ArenaTemplate loadTemplate(String name) {
- String path = main.config.cfg.getString("World_Dictonary");
- File dir = new File(path);
- if (dir.isDirectory()) {
- for (final File world : dir.listFiles()) {
- if (world.isDirectory() && world.getName().intern() == name.intern()) {
- try {
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(new File(world.getAbsolutePath() + "\\Arena.enabled.yml"));
- return new ArenaTemplate(main, world.getAbsolutePath(), world, cfg);
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("[BedWars] Cant load World \"" + world.getName() + "\" to ArenaTemplate!");
- }
- }
- }
- return null;
- } else {
- return null;
- }
- }
- public void signUpdate(Socket socket, int id, String[] lines) {
- try {
- PrintStream out = new PrintStream(socket.getOutputStream());
- out.print("werfjhgdtwzio\n");
- out.println("test");
- out.flush();
- out = new PrintStream(socket.getOutputStream());
- out.println("updateSign".intern());
- out.println(id);
- out.println(lines[0].intern());
- out.println(lines[1].intern());
- out.println(lines[2].intern());
- out.println(lines[3].intern());
- out.flush();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment