From 555d79d9328769a67d143791ee96a0a521732223 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Mar 2022 23:06:31 +0100 Subject: [PATCH] Send subserver start packet on lobby Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/EventStarter.java | 2 +- .../steamwar/bungeecore/SubserverSystem.java | 17 +++++++++++++---- .../bungeecore/commands/ArenaCommand.java | 3 ++- .../bungeecore/commands/ChallengeCommand.java | 4 ++-- .../bungeecore/commands/EventCommand.java | 7 ++----- .../bungeecore/commands/FightCommand.java | 2 +- .../bungeecore/commands/HistoricCommand.java | 2 +- .../bungeecore/commands/JoinmeCommand.java | 4 ++-- .../bungeecore/commands/ReplayCommand.java | 2 +- .../bungeecore/commands/TpCommand.java | 4 ++-- .../bungeecore/comms/PacketIdManager.java | 1 + .../comms/handlers/FightInfoHandler.java | 4 ++++ .../comms/packets/StartingServerPacket.java | 18 ++++++++++++++++++ 13 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index b1738285..e0e29af9 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -69,7 +69,7 @@ public class EventStarter implements Runnable { ProxiedPlayer leiter = ProxyServer.getInstance().getPlayer(SteamwarUser.get(next.getKampfleiter()).getUuid()); if(leiter != null) - subserver.sendPlayer(leiter); + SubserverSystem.sendPlayer(subserver, leiter); eventServer.put(blue.getTeamId(), subserver); eventServer.put(red.getTeamId(), subserver); diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 102b64fd..015393b9 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore; +import de.steamwar.bungeecore.comms.handlers.FightInfoHandler; +import de.steamwar.bungeecore.comms.packets.StartingServerPacket; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.IgnoreSystem; import de.steamwar.bungeecore.sql.SteamwarUser; @@ -142,7 +144,7 @@ public class SubserverSystem { } public static void startTestServer(ProxiedPlayer p, ArenaMode m, String map, int checkSchemId, int prepareSchemId){ - startArena(m, map, -1, checkSchemId, prepareSchemId, 0, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null).sendPlayer(p); + sendPlayer(startArena(m, map, -1, checkSchemId, prepareSchemId, 0, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null), p); } private static synchronized void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){ @@ -155,9 +157,10 @@ public class SubserverSystem { Node node = Node.getNode(); int port = bauPorts.freePort(); - new Bauserver(user.getUserName() + "s Bau", owner, port, node.startServer( + + sendPlayer(new Bauserver(user.getUserName() + "s Bau", owner, port, node.startServer( serverJar, directory, worldDir, worldName, port, xmx, "logPath=" + worldName - ), () -> {}).sendPlayer(p); + ), () -> {}), p); } public static void sendToBauServer(ProxiedPlayer p, UUID owner){ @@ -183,10 +186,16 @@ public class SubserverSystem { new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); } + public static void sendPlayer(Subserver subserver, ProxiedPlayer player) { + subserver.sendPlayer(player); + if(!subserver.hasStarted() && FightInfoHandler.onLobby(player)) + new StartingServerPacket().send(player); + } + private static boolean bauRunning(ProxiedPlayer p, UUID owner){ for(Subserver subserver : Subserver.getServerList()){ if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(owner)){ - subserver.sendPlayer(p); + sendPlayer(subserver, p); return true; } } diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 9abd0f5b..d88950f7 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.SubserverSystem; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -51,6 +52,6 @@ public class ArenaCommand extends BasicCommand { return; } - subserver.sendPlayer(player); + SubserverSystem.sendPlayer(subserver, player); } } diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index df477c9a..27d9ba73 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -78,8 +78,8 @@ public class ChallengeCommand extends BasicCommand { Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, 0, null, null, player.getUniqueId(), target.getUniqueId()); - arena.sendPlayer(player); - arena.sendPlayer(target); + SubserverSystem.sendPlayer(arena, player); + SubserverSystem.sendPlayer(arena, target); Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName(), target.getName()); diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 680b0a93..79ae6208 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -19,10 +19,7 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.EventStarter; -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.Team; @@ -72,7 +69,7 @@ public class EventCommand extends BasicCommand { return; } - eventArena.sendPlayer(player); + SubserverSystem.sendPlayer(eventArena, player); } private void noCurrentEvent(ProxiedPlayer player){ diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 653db48d..1d2e396f 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -165,7 +165,7 @@ public class FightCommand extends BasicCommand { public void execute(CommandSender sender, String[] args) { createArena(sender, "/fight ", args, 0, false, (player, mode, map) -> { Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, 0, null, null, player.getUniqueId(), null); - arena.sendPlayer(player); + SubserverSystem.sendPlayer(arena, player); Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); }); diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index 7e34836c..6c9c0709 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -37,7 +37,7 @@ public class HistoricCommand extends BasicCommand { public void execute(CommandSender sender, String[] args) { FightCommand.createArena(sender, "/historic ", args, 0, true, (player, mode, map) -> { Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, 0, null, null, player.getUniqueId(), null); - arena.sendPlayer(player); + SubserverSystem.sendPlayer(arena, player); Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER" , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); }); diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 37fb8061..105063c0 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -59,12 +59,12 @@ public class JoinmeCommand extends BasicCommand { if(subserver != null) { Servertype type = subserver.getType(); if (type == Servertype.ARENA) { - subserver.sendPlayer(player); + SubserverSystem.sendPlayer(subserver, 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); + SubserverSystem.sendPlayer(subserver, player); } else { SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); Message.send("JOIN_PLAYER_BLOCK", player); diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index 806df5a3..f5dd44ac 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -35,7 +35,7 @@ public class ReplayCommand extends BasicCommand { } ArenaMode mode = fight.getGameMode(); - SubserverSystem.startArena(mode, mode.getRandomMap(), 0, 0, 0, fight.getFightID(), null, null, null, null).sendPlayer(player); + SubserverSystem.sendPlayer(SubserverSystem.startArena(mode, mode.getRandomMap(), 0, 0, 0, fight.getFightID(), null, null, null, null), player); }, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(player, fight), fight)).collect(Collectors.toList())).open(); } diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index ae2f9a99..c3a81b25 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -118,12 +118,12 @@ public class TpCommand extends BasicCommand { if(subserver != null) { Servertype type = subserver.getType(); if (type == Servertype.ARENA) { - subserver.sendPlayer(player); + SubserverSystem.sendPlayer(subserver, 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); + SubserverSystem.sendPlayer(subserver, player); } else { SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); Message.send("JOIN_PLAYER_BLOCK", player); diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java index 1ee0c27a..8689fc6a 100644 --- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java +++ b/src/de/steamwar/bungeecore/comms/PacketIdManager.java @@ -37,4 +37,5 @@ public class PacketIdManager { public static final byte I_AM_A_LOBBY = 0x20; public static final byte FIGHT_INFO = 0x21; public static final byte FIGHT_ENDS = 0x22; + public static final byte STARTING_SERVER = 0x23; } diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java index 998e53e3..eb708dfb 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java @@ -38,6 +38,10 @@ public class FightInfoHandler implements SpigotHandler { lobbys.add(lobby); } + public static boolean onLobby(ProxiedPlayer player) { + return lobbys.contains(player.getServer().getInfo()); + } + @Override public void handle(ByteArrayDataInput in, ServerInfo info) { FightInfoPacket packet = new FightInfoPacket(in); diff --git a/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java b/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java new file mode 100644 index 00000000..b7058c2b --- /dev/null +++ b/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java @@ -0,0 +1,18 @@ +package de.steamwar.bungeecore.comms.packets; + +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.bungeecore.comms.BungeePacket; +import de.steamwar.bungeecore.comms.PacketIdManager; + +public class StartingServerPacket extends BungeePacket { + + @Override + public int getId() { + return PacketIdManager.STARTING_SERVER; + } + + @Override + public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { + //nothing to write + } +}