diff --git a/src/de/steamwar/lobby/Config.java b/src/de/steamwar/lobby/Config.java index 096a383..c87868f 100644 --- a/src/de/steamwar/lobby/Config.java +++ b/src/de/steamwar/lobby/Config.java @@ -21,6 +21,7 @@ package de.steamwar.lobby; import de.steamwar.lobby.display.Hologram; import de.steamwar.lobby.portal.Portal; +import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.serialization.ConfigurationSerialization; @@ -31,17 +32,29 @@ public class Config { } private final FileConfiguration yml; + private Location waitingHallSpawn; public Config(FileConfiguration yml) { this.yml = yml; yml.getList("portals", Portal.getPortals()); yml.getList("holograms", Hologram.getHolograms()); + waitingHallSpawn = yml.getLocation("waitingHallSpawn"); + } + + public Location getWaitingHallSpawn() { + return waitingHallSpawn; + } + + public void setWaitingHallSpawn(Location waitingHallSpawn) { + this.waitingHallSpawn = waitingHallSpawn; + save(); } public void save() { yml.set("portals", Portal.getPortals()); yml.set("holograms", Hologram.getHolograms()); + yml.set("waitingHallSpawn", waitingHallSpawn); LobbySystem.getPlugin().saveConfig(); } diff --git a/src/de/steamwar/lobby/Fightserver.java b/src/de/steamwar/lobby/Fightserver.java index d8204a3..c973bb9 100644 --- a/src/de/steamwar/lobby/Fightserver.java +++ b/src/de/steamwar/lobby/Fightserver.java @@ -20,8 +20,11 @@ package de.steamwar.lobby; import com.google.common.io.ByteArrayDataInput; +import de.steamwar.comms.BungeeReceiver; +import de.steamwar.comms.PacketIdManager; import de.steamwar.comms.packets.FightInfoPacket; import de.steamwar.lobby.portal.FightserverPortal; +import org.bukkit.Bukkit; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -32,7 +35,12 @@ public class Fightserver { private static final Map servers = new HashMap<>(); - public static void newFightInfo(ByteArrayDataInput in) { + public static void init() { + BungeeReceiver.registerHandler(PacketIdManager.FIGHT_INFO, Fightserver::newFightInfo); + Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), Fightserver::removeStopped, 20, 20); + } + + private static void newFightInfo(ByteArrayDataInput in) { FightInfoPacket fightInfo = new FightInfoPacket(in); Fightserver server = servers.get(fightInfo.getServerName()); if (server == null) { @@ -42,7 +50,7 @@ public class Fightserver { } } - public static void removeStopped() { + private static void removeStopped() { Instant timeout = Instant.now().minus(5, ChronoUnit.SECONDS); Iterator> it = servers.entrySet().iterator(); diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index d53da98..54e78b1 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -42,7 +42,8 @@ public class LobbySystem extends JavaPlugin { public void onEnable() { message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader()); - new Fightservers(); + Fightserver.init(); + new WaitingHall(); new Portals(); new PortalCommand(); new HologramCommand(); diff --git a/src/de/steamwar/lobby/Fightservers.java b/src/de/steamwar/lobby/WaitingHall.java similarity index 61% rename from src/de/steamwar/lobby/Fightservers.java rename to src/de/steamwar/lobby/WaitingHall.java index a71fcee..26aa716 100644 --- a/src/de/steamwar/lobby/Fightservers.java +++ b/src/de/steamwar/lobby/WaitingHall.java @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * Copyright (C) 2022 SteamWar.de-Serverteam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -19,14 +19,19 @@ package de.steamwar.lobby; +import com.google.common.io.ByteArrayDataInput; import de.steamwar.comms.BungeeReceiver; import de.steamwar.comms.PacketIdManager; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; +import org.bukkit.event.player.PlayerTeleportEvent; -public class Fightservers { +public class WaitingHall { + public WaitingHall() { + BungeeReceiver.registerHandler(PacketIdManager.STARTING_SERVER, this::serverStarting); + } - public Fightservers() { - BungeeReceiver.registerHandler(PacketIdManager.FIGHT_INFO, Fightserver::newFightInfo); - Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), Fightserver::removeStopped, 20, 20); + private void serverStarting(ByteArrayDataInput in) { + Bukkit.getPlayer(SteamwarUser.get(in.readInt()).getUUID()).teleport(LobbySystem.config().getWaitingHallSpawn(), PlayerTeleportEvent.TeleportCause.PLUGIN); } } diff --git a/src/de/steamwar/lobby/command/ModifyCommand.java b/src/de/steamwar/lobby/command/ModifyCommand.java index dcf0644..ba04ac4 100644 --- a/src/de/steamwar/lobby/command/ModifyCommand.java +++ b/src/de/steamwar/lobby/command/ModifyCommand.java @@ -61,4 +61,9 @@ public class ModifyCommand extends SWCommand implements Listener { public void onLeave(PlayerQuitEvent event) { modifying.remove(event.getPlayer()); } + + @Register("waitinghallspawn") + public void setWaitingHallSpawn(Player player) { + LobbySystem.config().setWaitingHallSpawn(player.getLocation()); + } } diff --git a/src/de/steamwar/lobby/listener/PlayerSpawn.java b/src/de/steamwar/lobby/listener/PlayerSpawn.java index fc928bd..5d3cc97 100644 --- a/src/de/steamwar/lobby/listener/PlayerSpawn.java +++ b/src/de/steamwar/lobby/listener/PlayerSpawn.java @@ -44,7 +44,7 @@ public class PlayerSpawn extends BasicListener { player.setGameMode(GameMode.ADVENTURE); player.setWalkSpeed(0.5f); - player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); + player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, 0, 0.5)); player.setHealth(20); player.setFoodLevel(20); giveItems(player);