From 31ff23f1c1c57e52766fdda3e36b6bc04e1a18ab Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 22 Jun 2019 23:38:01 +0200 Subject: [PATCH] Reintegrating with PersistentBungeeCore --- .gitignore | 1 - pom.xml | 11 ++ .../{arenasystem => }/ArenaMode.java | 2 +- src/de/steamwar/bungeecore/BungeeCore.java | 13 +- .../steamwar/bungeecore/PlayerListener.java | 26 +-- .../steamwar/bungeecore/SubserverSystem.java | 85 +++++++++ .../bungeecore/arenasystem/Arena.java | 158 ---------------- .../bungeecore/arenasystem/ArenaSystem.java | 63 ------- .../bungeecore/bausystem/BauServer.java | 174 ------------------ .../bungeecore/bausystem/BauSystem.java | 75 -------- .../bungeecore/commands/BauCommand.java | 33 ++-- .../bungeecore/commands/FightCommand.java | 27 ++- .../bungeecore/commands/JoinmeCommand.java | 31 ++-- src/plugin.yml | 3 +- 14 files changed, 158 insertions(+), 544 deletions(-) rename src/de/steamwar/bungeecore/{arenasystem => }/ArenaMode.java (65%) create mode 100644 src/de/steamwar/bungeecore/SubserverSystem.java delete mode 100644 src/de/steamwar/bungeecore/arenasystem/Arena.java delete mode 100644 src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java delete mode 100644 src/de/steamwar/bungeecore/bausystem/BauServer.java delete mode 100644 src/de/steamwar/bungeecore/bausystem/BauSystem.java diff --git a/.gitignore b/.gitignore index 7eae63f6..ee44a963 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea target -dependency-reduced-pom.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6615f8fa..03afb00d 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,10 @@ bungeecord-repo https://oss.sonatype.org/content/repositories/snapshots + + steamwar + https://steamwar.de:81/maven + @@ -51,5 +55,12 @@ jar provided + + steamwar + PersistentBungeeCore + 1.0 + jar + provided + \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/arenasystem/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java similarity index 65% rename from src/de/steamwar/bungeecore/arenasystem/ArenaMode.java rename to src/de/steamwar/bungeecore/ArenaMode.java index 0fbfab4b..e96627e7 100644 --- a/src/de/steamwar/bungeecore/arenasystem/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -1,4 +1,4 @@ -package de.steamwar.bungeecore.arenasystem; +package de.steamwar.bungeecore; public enum ArenaMode { AirShip, diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 186e76bb..7fa23fc4 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -1,8 +1,5 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.arenasystem.ArenaMode; -import de.steamwar.bungeecore.arenasystem.ArenaSystem; -import de.steamwar.bungeecore.bausystem.BauSystem; import de.steamwar.bungeecore.commands.*; import de.steamwar.bungeecore.sql.WarkingUser; import de.steamwar.bungeecore.sql.sql; @@ -31,8 +28,8 @@ public class BungeeCore extends Plugin { public static final String TeamchatPrefix = "§4T§7c§r §e"; public static final DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy"); public static String LobbyServer; - public static String [] BroadCastMsgs; - public static int LastBroadCast = 0; + private static String [] BroadCastMsgs; + private static int LastBroadCast = 0; public static final Map serverPermissions = new HashMap<>(); public static final Map commands = new HashMap<>(); public static final Map> arenaMaps = new HashMap<>(); @@ -123,16 +120,14 @@ public class BungeeCore extends Plugin { } }, 10, 10, TimeUnit.MINUTES); + Persistent.setChatPrefix(ChatPrefix); + Persistent.setLobbyServer(LobbyServer); getProxy().getScheduler().schedule(this, WarkingUser::clearCache, 1, 1, TimeUnit.HOURS); } @Override public void onDisable(){ - ArenaSystem.shutdown(); - BauSystem.shutdown(); sql.close(); - getProxy().getPluginManager().unregisterCommands(this); - getProxy().getPluginManager().unregisterListeners(this); } static void log(final String message, final ServerInfo server){ diff --git a/src/de/steamwar/bungeecore/PlayerListener.java b/src/de/steamwar/bungeecore/PlayerListener.java index a24ce858..c52ea1c0 100644 --- a/src/de/steamwar/bungeecore/PlayerListener.java +++ b/src/de/steamwar/bungeecore/PlayerListener.java @@ -1,9 +1,5 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.arenasystem.Arena; -import de.steamwar.bungeecore.arenasystem.ArenaSystem; -import de.steamwar.bungeecore.bausystem.BauServer; -import de.steamwar.bungeecore.bausystem.BauSystem; import de.steamwar.bungeecore.commands.BauCommand; import de.steamwar.bungeecore.sql.BannedUserIPs; import de.steamwar.bungeecore.sql.WarkingUser; @@ -149,21 +145,6 @@ public class PlayerListener implements Listener { ev.setCancelServer(kickTo); } - @EventHandler - public void onServerSwitchEvent(ServerSwitchEvent e){ - ProxiedPlayer p = e.getPlayer(); - Arena a = ArenaSystem.getArena(p); - if(a != null && !p.getServer().getInfo().equals(a.server)){ - a.removePlayer(p); - return; - } - - BauServer bau = BauSystem.getBau(p); - if(bau != null && !p.getServer().getInfo().equals(bau.getServer())){ - bau.removePlayer(p); - } - } - @EventHandler public void onChatEvent(ChatEvent e){ if(e.getMessage().startsWith("/")){ @@ -185,7 +166,9 @@ public class PlayerListener implements Listener { e.setCancelled(true); return; } - if(ArenaSystem.inArena(sender)) + + Subserver subserver = Subserver.getSubserver(sender); + if(subserver != null && subserver.getType() == Servertype.ARENA) return; String name = sender.getDisplayName(); @@ -210,7 +193,8 @@ public class PlayerListener implements Listener { String msg = name + chatsuffix + message; for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ - if(target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN && !ArenaSystem.inArena(target)){ + Subserver targetServer = Subserver.getSubserver(target); + if(target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN && (targetServer == null || targetServer.getType() != Servertype.ARENA)){ target.sendMessage(msg); } } diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java new file mode 100644 index 00000000..8e69e242 --- /dev/null +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -0,0 +1,85 @@ +package de.steamwar.bungeecore; + +import de.steamwar.bungeecore.sql.Bauwelt; +import de.steamwar.bungeecore.sql.WarkingUser; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +public class SubserverSystem { + private SubserverSystem(){} + + public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){ + ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); + if(o == null) + return; + + o.sendMessage(BungeeCore.ChatPrefix + "§e" + p.getName() + " §7möchte auf deine Bauwelt."); + TextComponent tc = new TextComponent("§7Klicke §ehier§7, wenn du das erlauben möchtest."); + tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e/bau addmember " + p.getName()).create())); + tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); + o.sendMessage(tc); + } + + public static Subserver startArena(ArenaMode modus, String map){ + int port = freePort(2500); + String serverName = modus.name() + (port - 2500); + return new Subserver(Servertype.ARENA, serverName, port, + "/home/minecraft/mc", "-a", modus.name(), serverName, Integer.toString(port), map); + } + + public static void sendToBauServer(ProxiedPlayer p, UUID owner){ + for(Subserver subserver : Subserver.getServerList()){ + if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(owner)){ + subserver.sendPlayer(p); + return; + } + } + + File w = new File(BungeeCore.WorldFolder + owner); + if (!w.exists() || !w.isDirectory()){ + try { + Process pr; + ProcessBuilder pb = new ProcessBuilder( + "cp", "-r", BungeeCore.BauweltPrototyp, BungeeCore.WorldFolder + owner); + pr = pb.start(); + pr.waitFor(); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + p.sendMessage(BungeeCore.ChatPrefix + "§cDas Erstellen der Welt ist fehlgeschlagen."); + return; + } + if(Bauwelt.getBauwelt(owner) == null) + new Bauwelt(owner, false, false); + } + + WarkingUser user = WarkingUser.get(owner); + int port = freePort(4000); + + new Bauserver(user.getUserName() + "s Bau", owner, port, + "/home/minecraft/mc", "-b", owner.toString(), Integer.toString(port)).sendPlayer(p); + } + + private static int freePort(int start){ + int port = start; + boolean isFree = false; + while(!isFree){ + port++; + isFree = true; + for(Subserver server : Subserver.getServerList()){ + if(server.getServer().getAddress().getPort() == port){ + isFree = false; + break; + } + } + } + return port; + } +} diff --git a/src/de/steamwar/bungeecore/arenasystem/Arena.java b/src/de/steamwar/bungeecore/arenasystem/Arena.java deleted file mode 100644 index c2599df8..00000000 --- a/src/de/steamwar/bungeecore/arenasystem/Arena.java +++ /dev/null @@ -1,158 +0,0 @@ -package de.steamwar.bungeecore.arenasystem; - -import de.steamwar.bungeecore.BungeeCore; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class Arena implements Runnable{ - - final String serverName; - final int arenenNummer; - public final ArenaMode spielModus; - - private Process p; - private PrintWriter writer; - public ServerInfo server; - private boolean started = false; - - private final List cachedPlayers = new ArrayList<>(); - private final List players = new ArrayList<>(); - - - Arena(ArenaMode modus, int id, String map){ - spielModus = modus; - arenenNummer = id; - serverName = modus.name() + id; - int port = 2500 + arenenNummer; - ProcessBuilder pb = new ProcessBuilder( - "/home/minecraft/mc", - "-a", modus.name(), serverName, Integer.toString(port), map); - try{ - p = pb.start(); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this); - InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); - server = ProxyServer.getInstance().constructServerInfo( - serverName, address, "SteamWar.de - Arena", false); - ProxyServer.getInstance().getServers().put(serverName, server); - writer = new PrintWriter( p.getOutputStream(), true); - }catch(IOException e) { - e.printStackTrace(); - stop(); - } - } - - public void sendPlayer(ProxiedPlayer p){ - if(!started){ - p.sendMessage(BungeeCore.ChatPrefix + "§7Die Arena wird gestartet, einen Moment bitte..."); - cachedPlayers.add(p); - }else{ - p.connect(server); - players.add(p); - } - } - - public void removePlayer(ProxiedPlayer p){ - Iterator it = cachedPlayers.iterator(); - while(it.hasNext()){ - if(it.next().equals(p)){ - it.remove(); - return; - } - } - it = players.iterator(); - while(it.hasNext()){ - if(it.next().equals(p)){ - it.remove(); - return; - } - } - } - - void stop(){ - ProxyServer.getInstance().getServers().remove(serverName); - if(p != null && p.isAlive()){ - for(ProxiedPlayer player : server.getPlayers()){ - player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); - } - writer.println("stop"); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, ()->{ - try { - p.waitFor(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - ArenaSystem.arenen.remove(this); - }); - }else - ArenaSystem.arenen.remove(this); - } - - private void fatalError(){ - for(ProxiedPlayer cached : cachedPlayers){ - cached.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler beim Arenenstart."); - } - for(ProxiedPlayer player : server.getPlayers()){ - player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); - player.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler in der Arena."); - } - stop(); - } - - boolean inArena(ProxiedPlayer p){ - for(ProxiedPlayer ap : cachedPlayers) - if(ap.equals(p)) - return true; - for(ProxiedPlayer ap : players) - if(ap.equals(p)) - return true; - return false; - } - - @Override - public void run() { - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - - while (!started && (line = reader.readLine()) != null) { - started = line.contains(" INFO]: Done ("); //Problematisch - } - - if(line == null){ - BungeeCore.log("Arena "+serverName+" stopped to early!"); - fatalError(); - return; - } - - Thread.sleep(1000); - - sendPlayer(cachedPlayers.get(0)); - - Thread.sleep(200); - - for(int i = 1; i < cachedPlayers.size(); i++){ - sendPlayer(cachedPlayers.get(i)); - } - cachedPlayers.clear(); - - p.waitFor(); - }catch(IOException e){ - e.printStackTrace(); - fatalError(); - }catch(InterruptedException e){ - BungeeCore.log("Arena "+serverName+" was interrupted!"); - fatalError(); - } - stop(); - } -} diff --git a/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java b/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java deleted file mode 100644 index cd83c9dc..00000000 --- a/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java +++ /dev/null @@ -1,63 +0,0 @@ -package de.steamwar.bungeecore.arenasystem; - - -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.util.ArrayList; - -public class ArenaSystem { - - private ArenaSystem(){} - - static ArrayList arenen = new ArrayList<>(); - - private static int freeId(){ - int id = 0; - boolean isFree = false; - while(!isFree){ - id++; - isFree = true; - for(Arena arena : arenen){ - if(arena.arenenNummer == id){ - isFree = false; - break; - } - } - } - return id; - } - - public static Arena startServer(ArenaMode modus, String map){ - Arena arena = new Arena(modus, freeId(), map); - arenen.add(arena); - return arena; - } - - public static void shutdown(){ - while(!arenen.isEmpty()) - arenen.get(0).stop(); - } - - public static boolean inArena(ProxiedPlayer p){ - for(Arena a : arenen){ - if(a.inArena(p)) - return true; - } - return false; - } - - public static Arena getArena(ProxiedPlayer p){ - for(Arena a : arenen){ - if(a.inArena(p)) - return a; - } - return null; - } - - public static Arena getArena(String serverName){ - for(Arena a : arenen) - if(a.serverName.equals(serverName)) - return a; - return null; - } -} diff --git a/src/de/steamwar/bungeecore/bausystem/BauServer.java b/src/de/steamwar/bungeecore/bausystem/BauServer.java deleted file mode 100644 index eb960bb3..00000000 --- a/src/de/steamwar/bungeecore/bausystem/BauServer.java +++ /dev/null @@ -1,174 +0,0 @@ -package de.steamwar.bungeecore.bausystem; - -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.WarkingUser; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class BauServer implements Runnable{ - - private final UUID owner; - private final int id; - private final String name; - - private Process p; - private PrintWriter writer; - private ServerInfo server; - private boolean started = false; - private boolean stopped = false; - - private final List cachedPlayers = new ArrayList<>(); - private final List players = new ArrayList<>(); - - BauServer(int id, UUID owner){ - this.id = id; - this.owner = owner; - this.name = new WarkingUser(owner).getUserName() + "s Bau"; - int port = 4000 + id; - ProcessBuilder pb = new ProcessBuilder( - "/home/minecraft/mc", - "-b", owner.toString(), Integer.toString(port)); - try{ - p = pb.start(); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this); - InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); - server = ProxyServer.getInstance().constructServerInfo( - name, address, "SteamWar.de - BauServer", false); - ProxyServer.getInstance().getServers().put(name, server); - writer = new PrintWriter( p.getOutputStream(), true); - }catch(IOException e) { - e.printStackTrace(); - stop(); - } - } - - public void stop(){ - ProxyServer.getInstance().getServers().remove(name); - if(p != null && p.isAlive()) { - for (ProxiedPlayer player : server.getPlayers()) { - player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); - } - stopped = true; - writer.println("stop"); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, ()->{ - try { - p.waitFor(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - BauSystem.server.remove(owner); - }); - }else - BauSystem.server.remove(owner); - } - - void sendPlayer(ProxiedPlayer p){ - if(stopped) { - p.sendMessage(BungeeCore.ChatPrefix + "§7Die Bauwelt derzeit entladen, bitte versuche es später erneut."); - }else if(!started){ - p.sendMessage(BungeeCore.ChatPrefix + "§7Die Bauwelt wird geladen, einen Moment bitte..."); - cachedPlayers.add(p); - }else{ - p.connect(server); - players.add(p); - } - } - - boolean onBau(ProxiedPlayer p){ - for(ProxiedPlayer ap : cachedPlayers) - if(ap.equals(p)) - return true; - for(ProxiedPlayer ap : players) - if(ap.equals(p)) - return true; - return false; - } - - public void removePlayer(ProxiedPlayer p){ - cachedPlayers.remove(p); - players.remove(p); - } - - private void fatalError(){ - for(ProxiedPlayer cached : cachedPlayers){ - cached.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler beim Laden der Bauwelt."); - } - for(ProxiedPlayer player : server.getPlayers()){ - player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); - player.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler in der Bauwelt."); - } - stop(); - } - - @Override - public void run() { - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - - while (!started && (line = reader.readLine()) != null) { - started = line.contains(" INFO]: Done ("); - } - - if(line == null){ - BungeeCore.log("Bau "+name+" stopped to early!"); - fatalError(); - return; - } - - Thread.sleep(1000); - - for(ProxiedPlayer player : cachedPlayers){ - sendPlayer(player); - } - cachedPlayers.clear(); - - p.waitFor(); - }catch(IOException e){ - e.printStackTrace(); - fatalError(); - }catch(InterruptedException e){ - BungeeCore.log("Bau "+name+" was interrupted!"); - fatalError(); - } - stop(); - } - - public UUID getOwner() { - return owner; - } - - public int getId() { - return id; - } - - public ServerInfo getServer() { - return server; - } - - public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){ - ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); - if(o == null) - return; - - o.sendMessage(BungeeCore.ChatPrefix + "§e" + p.getName() + " §7möchte auf deine Bauwelt."); - TextComponent tc = new TextComponent("§7Klicke §ehier§7, wenn du das erlauben möchtest."); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e/bau addmember " + p.getName()).create())); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); - o.sendMessage(tc); - } -} diff --git a/src/de/steamwar/bungeecore/bausystem/BauSystem.java b/src/de/steamwar/bungeecore/bausystem/BauSystem.java deleted file mode 100644 index 216f03e9..00000000 --- a/src/de/steamwar/bungeecore/bausystem/BauSystem.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.steamwar.bungeecore.bausystem; - -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.Bauwelt; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.UUID; - -public class BauSystem { - - private BauSystem(){} - - static HashMap server = new HashMap<>(); - - private static int freeId(){ - int id = 0; - boolean isFree = false; - while(!isFree){ - id++; - isFree = true; - for(BauServer bau : server.values()){ - if(bau.getId() == id){ - isFree = false; - break; - } - } - } - return id; - } - - public static void sendToServer(ProxiedPlayer p, UUID owner){ - if(server.containsKey(owner)){ - server.get(owner).sendPlayer(p); - }else{ - File w = new File(BungeeCore.WorldFolder + owner); - if (!w.exists() || !w.isDirectory()){ - try { - Process pr; - ProcessBuilder pb = new ProcessBuilder( - "cp", "-r", BungeeCore.BauweltPrototyp, BungeeCore.WorldFolder + owner); - pr = pb.start(); - pr.waitFor(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - p.sendMessage(BungeeCore.ChatPrefix + "§cDas Erstellen der Welt ist fehlgeschlagen."); - return; - } - if(Bauwelt.getBauwelt(owner) == null) - new Bauwelt(owner, false, false); - } - BauServer bau = new BauServer(freeId(), owner); - server.put(owner, bau); - bau.sendPlayer(p); - } - } - - public static BauServer getBau(ProxiedPlayer p){ - for(BauServer bau : server.values()){ - if(bau.onBau(p)) - return bau; - } - return null; - } - - public static void shutdown(){ - Iterator it = server.values().iterator(); - while(it.hasNext()){ - it.next().stop(); - } - } -} diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 0a2d819f..9f4d17d6 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -1,8 +1,6 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.bausystem.BauServer; -import de.steamwar.bungeecore.bausystem.BauSystem; +import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.Bauwelt; import de.steamwar.bungeecore.sql.BauweltMember; import de.steamwar.bungeecore.sql.Permission; @@ -20,12 +18,13 @@ public class BauCommand { public static void onBau(ChatEvent e, String[] command){ ProxiedPlayer p = (ProxiedPlayer) e.getSender(); - BauServer bau = BauSystem.getBau(p); + Subserver server = Subserver.getSubserver(p); + Bauserver bau = server != null && server.getType() == Servertype.BAUSERVER ? (Bauserver)server : null; boolean ownBau = bau != null && bau.getOwner().equals(p.getUniqueId()); e.setCancelled(true); if(command.length == 1){ - BauSystem.sendToServer(p, p.getUniqueId()); + SubserverSystem.sendToBauServer(p, p.getUniqueId()); }else if(ownBau && command.length != 2 && ( command[1].equalsIgnoreCase("togglebuild") || command[1].equalsIgnoreCase("togglewe") || @@ -65,11 +64,11 @@ public class BauCommand { p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); return; }else if (!hasPermission(worldOwner, p, Permission.member)){ - BauServer.sendDeniedMessage(p, worldOwner); + SubserverSystem.sendDeniedMessage(p, worldOwner); p.sendMessage(BungeeCore.ChatPrefix + "§cDu darfst dich nicht auf diese Welt teleportieren"); return; } - BauSystem.sendToServer(p, worldOwner); + SubserverSystem.sendToBauServer(p, worldOwner); }else if(command[1].equalsIgnoreCase("togglebuild")){ if (command.length == 2) { p.sendMessage(BungeeCore.ChatPrefix + "/bau togglebuild "); @@ -125,12 +124,16 @@ public class BauCommand { }else if(command[1].equalsIgnoreCase("resetall") || command[1].equalsIgnoreCase("delete")){ p.sendMessage(BungeeCore.ChatPrefix + "§aDeine Welt wird zurückgesetzt. Einen Moment bitte..."); - BauServer bauserver = BauSystem.getBau(p); - if(bauserver != null){ - bauserver.stop(); - } - File directory = new File(BungeeCore.WorldFolder + p.getUniqueId().toString()); - del(directory); + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, () -> { + for(Subserver subserver : Subserver.getServerList()){ + if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(p.getUniqueId())){ + subserver.stop(); + break; + } + } + File directory = new File(BungeeCore.WorldFolder + p.getUniqueId().toString()); + del(directory); + }); }else{ HelpCommand.sendBauHelp(p); } @@ -192,8 +195,8 @@ public class BauCommand { ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); if(z != null){ z.sendMessage(BungeeCore.ChatPrefix + "§cDu wurdest von der Welt von §6" + p.getName() + " §centfernt."); - BauServer server = BauSystem.getBau(z); - if(server != null && server.getOwner().equals(p.getUniqueId())) + Subserver server = Subserver.getSubserver(z); + if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())) z.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); } p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler wurde entfernt."); diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 148ac8d0..0acd652d 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -1,9 +1,10 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.arenasystem.Arena; -import de.steamwar.bungeecore.arenasystem.ArenaMode; -import de.steamwar.bungeecore.arenasystem.ArenaSystem; +import de.steamwar.bungeecore.Servertype; +import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.SubserverSystem; +import de.steamwar.bungeecore.ArenaMode; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; @@ -52,41 +53,47 @@ public class FightCommand extends Command { if(sender instanceof ProxiedPlayer){ ProxiedPlayer player = (ProxiedPlayer) sender; - if(ArenaSystem.inArena(player)){ + Subserver subserver = Subserver.getSubserver(player); + if(subserver != null && subserver.getType() == Servertype.ARENA){ sender.sendMessage(BungeeCore.ChatPrefix + "§cDu befindest dich bereits in einer Arena."); return; } String map; - Arena arena; + Subserver arena; + String spielModus; switch(args[0].toLowerCase()){ case "as": case "airship": map = getMap(sender, ArenaMode.AirShip, args); if(map == null) return; - arena = ArenaSystem.startServer(ArenaMode.AirShip, map); + arena = SubserverSystem.startArena(ArenaMode.AirShip, map); + spielModus = "AirShip"; break; case "ws": case "warship": map = getMap(sender, ArenaMode.WarShip, args); if(map == null) return; - arena = ArenaSystem.startServer(ArenaMode.WarShip, map); + arena = SubserverSystem.startArena(ArenaMode.WarShip, map); + spielModus = "WarShip"; break; case "wg": case "wargear": map = getMap(sender, ArenaMode.WarGear, args); if(map == null) return; - arena = ArenaSystem.startServer(ArenaMode.WarGear, map); + arena = SubserverSystem.startArena(ArenaMode.WarGear, map); + spielModus = "WarGear"; break; case "mwg": case "miniwargear": map = getMap(sender, ArenaMode.MiniWarGear, args); if(map == null) return; - arena = ArenaSystem.startServer(ArenaMode.MiniWarGear, map); + arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map); + spielModus = "MiniWarGear"; break; default: sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]); @@ -94,7 +101,7 @@ public class FightCommand extends Command { } arena.sendPlayer(player); - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um §e" + arena.spielModus + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); + TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um §e" + spielModus + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aGegen §7" + player.getName() + " §ekämpfen").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); ProxyServer.getInstance().broadcast(tc); diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index fb0e9d46..a96ffbbd 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -1,10 +1,6 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.arenasystem.Arena; -import de.steamwar.bungeecore.arenasystem.ArenaSystem; -import de.steamwar.bungeecore.bausystem.BauServer; -import de.steamwar.bungeecore.bausystem.BauSystem; +import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.BauweltMember; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -46,18 +42,21 @@ public class JoinmeCommand extends Command { } ServerInfo server = target.getServer().getInfo(); String ServerPerm = BungeeCore.serverPermissions.get(server.getName()); - Arena arena = ArenaSystem.getArena(target); - BauServer bauserver = BauSystem.getBau(target); + Subserver subserver = Subserver.getSubserver(target); - if(arena != null) { - arena.sendPlayer(player); - }else if(bauserver != null){ - if(bauserver.getOwner().equals(player.getUniqueId()) || - BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null){ - BauSystem.sendToServer(player, bauserver.getOwner()); - }else{ - BauServer.sendDeniedMessage(player, bauserver.getOwner()); - player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); + if(subserver != null) { + Servertype type = subserver.getType(); + if (type == Servertype.ARENA) { + subserver.sendPlayer(player); + } else if (type == Servertype.BAUSERVER) { + Bauserver bauserver = (Bauserver) subserver; + if (bauserver.getOwner().equals(player.getUniqueId()) || + BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) { + subserver.sendPlayer(player); + } else { + SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); + player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); + } } }else if(ServerPerm != null && !player.hasPermission(ServerPerm)){ player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); diff --git a/src/plugin.yml b/src/plugin.yml index 1452d062..aaa56e1e 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,4 +1,5 @@ name: BungeeCore main: de.steamwar.bungeecore.BungeeCore version: 1.0 -author: Lixfel \ No newline at end of file +author: Lixfel +depend: [PersistentBungeeCore] \ No newline at end of file