From 24b974d032aff0ddeac033b7012d19baeb690d36 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 7 Jun 2022 21:02:41 +0200 Subject: [PATCH 1/2] Network Update --- src/de/steamwar/lobby/Fightserver.java | 14 +++++--------- src/de/steamwar/lobby/LobbyPacketHandler.java | 18 ++++++++++++++++++ src/de/steamwar/lobby/LobbySystem.java | 1 + src/de/steamwar/lobby/WaitingHall.java | 15 ++++++++------- .../steamwar/lobby/listener/PlayerSpawn.java | 5 +++-- .../steamwar/lobby/portal/CommandPortal.java | 6 ++++-- .../lobby/portal/FightserverPortal.java | 2 +- 7 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 src/de/steamwar/lobby/LobbyPacketHandler.java diff --git a/src/de/steamwar/lobby/Fightserver.java b/src/de/steamwar/lobby/Fightserver.java index c973bb9..2cb4ed0 100644 --- a/src/de/steamwar/lobby/Fightserver.java +++ b/src/de/steamwar/lobby/Fightserver.java @@ -20,10 +20,8 @@ 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 de.steamwar.network.packets.common.FightInfoPacket; import org.bukkit.Bukkit; import java.time.Instant; @@ -36,17 +34,15 @@ public class Fightserver { private static final Map servers = new HashMap<>(); 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()); + public static void newFightInfo(FightInfoPacket in) { + Fightserver server = servers.get(in.getServerName()); if (server == null) { - new Fightserver(fightInfo); + new Fightserver(in); } else { - server.update(fightInfo); + server.update(in); } } diff --git a/src/de/steamwar/lobby/LobbyPacketHandler.java b/src/de/steamwar/lobby/LobbyPacketHandler.java new file mode 100644 index 0000000..1541b26 --- /dev/null +++ b/src/de/steamwar/lobby/LobbyPacketHandler.java @@ -0,0 +1,18 @@ +package de.steamwar.lobby; + +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.common.FightInfoPacket; + +public class LobbyPacketHandler extends PacketHandler { + + public LobbyPacketHandler() { + super(); + this.register(); + } + + @Handler + public void handleFightserver(FightInfoPacket packet) { + Fightserver.newFightInfo(packet); + } + +} diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 0ec117d..e22339c 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -68,6 +68,7 @@ public class LobbySystem extends JavaPlugin { new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X); new AlphaWall(l -> l.getZ() > 892, AlphaWall.REFLECT_Z); new AlphaWall(l -> l.getZ() < 1794, AlphaWall.REFLECT_Z); + new LobbyPacketHandler(); } @Override diff --git a/src/de/steamwar/lobby/WaitingHall.java b/src/de/steamwar/lobby/WaitingHall.java index 26aa716..ea97117 100644 --- a/src/de/steamwar/lobby/WaitingHall.java +++ b/src/de/steamwar/lobby/WaitingHall.java @@ -19,19 +19,20 @@ package de.steamwar.lobby; -import com.google.common.io.ByteArrayDataInput; -import de.steamwar.comms.BungeeReceiver; -import de.steamwar.comms.PacketIdManager; +import de.steamwar.network.packets.PacketHandler; import de.steamwar.sql.SteamwarUser; +import de.steamwar.network.packets.server.StartingServerPacket; import org.bukkit.Bukkit; import org.bukkit.event.player.PlayerTeleportEvent; -public class WaitingHall { +public class WaitingHall extends PacketHandler { public WaitingHall() { - BungeeReceiver.registerHandler(PacketIdManager.STARTING_SERVER, this::serverStarting); + super(); + this.register(); } - private void serverStarting(ByteArrayDataInput in) { - Bukkit.getPlayer(SteamwarUser.get(in.readInt()).getUUID()).teleport(LobbySystem.config().getWaitingHallSpawn(), PlayerTeleportEvent.TeleportCause.PLUGIN); + @Handler + private void serverStarting(StartingServerPacket in) { + Bukkit.getPlayer(SteamwarUser.get(in.getUser()).getUUID()).teleport(LobbySystem.config().getWaitingHallSpawn(), PlayerTeleportEvent.TeleportCause.PLUGIN); } } diff --git a/src/de/steamwar/lobby/listener/PlayerSpawn.java b/src/de/steamwar/lobby/listener/PlayerSpawn.java index b3e70fe..2a5c058 100644 --- a/src/de/steamwar/lobby/listener/PlayerSpawn.java +++ b/src/de/steamwar/lobby/listener/PlayerSpawn.java @@ -19,9 +19,10 @@ package de.steamwar.lobby.listener; -import de.steamwar.comms.packets.ImALobbyPacket; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.util.ItemBuilder; +import de.steamwar.network.NetworkSender; +import de.steamwar.network.packets.client.ImALobbyPacket; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; @@ -57,7 +58,7 @@ public class PlayerSpawn extends BasicListener { player.setFoodLevel(20); giveItems(player); - Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> new ImALobbyPacket().send(player), 20); + Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> NetworkSender.send(new ImALobbyPacket()), 20); } private void giveItems(Player player) { diff --git a/src/de/steamwar/lobby/portal/CommandPortal.java b/src/de/steamwar/lobby/portal/CommandPortal.java index 3dfe6ed..64552dd 100644 --- a/src/de/steamwar/lobby/portal/CommandPortal.java +++ b/src/de/steamwar/lobby/portal/CommandPortal.java @@ -19,10 +19,12 @@ package de.steamwar.lobby.portal; -import de.steamwar.comms.packets.ExecuteCommandPacket; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.command.ModifyCommand; import de.steamwar.lobby.listener.Portals; +import de.steamwar.network.NetworkSender; +import de.steamwar.network.packets.client.ExecuteCommandPacket; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -82,7 +84,7 @@ public class CommandPortal implements PortalHandler { if(ModifyCommand.modifying(player)) player.sendMessage("/" + cmd); - new ExecuteCommandPacket(player, cmd.toString()).send(player); + NetworkSender.send(new ExecuteCommandPacket(SteamwarUser.get(player).getId(), cmd.toString())); } @Override diff --git a/src/de/steamwar/lobby/portal/FightserverPortal.java b/src/de/steamwar/lobby/portal/FightserverPortal.java index ab80531..9ae1c3b 100644 --- a/src/de/steamwar/lobby/portal/FightserverPortal.java +++ b/src/de/steamwar/lobby/portal/FightserverPortal.java @@ -19,11 +19,11 @@ package de.steamwar.lobby.portal; -import de.steamwar.comms.packets.FightInfoPacket; import de.steamwar.lobby.Fightserver; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.display.Hologram; import de.steamwar.lobby.display.NPC; +import de.steamwar.network.packets.common.FightInfoPacket; import de.steamwar.sql.SteamwarUser; import org.bukkit.Location; import org.bukkit.entity.Player; From 48db45f8a89a7808be5b77b440dd0ea0c96377a4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 08:46:20 +0200 Subject: [PATCH 2/2] Fix copyright --- src/de/steamwar/lobby/LobbyPacketHandler.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/de/steamwar/lobby/LobbyPacketHandler.java b/src/de/steamwar/lobby/LobbyPacketHandler.java index 1541b26..ccd5ef8 100644 --- a/src/de/steamwar/lobby/LobbyPacketHandler.java +++ b/src/de/steamwar/lobby/LobbyPacketHandler.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.lobby; import de.steamwar.network.packets.PacketHandler;