13
0

Merge pull request 'Network Update' (#21) from network into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #21
Dieser Commit ist enthalten in:
Lixfel 2022-06-14 08:51:41 +02:00
Commit 7ff46faad5
7 geänderte Dateien mit 59 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -20,10 +20,8 @@
package de.steamwar.lobby; package de.steamwar.lobby;
import com.google.common.io.ByteArrayDataInput; 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.lobby.portal.FightserverPortal;
import de.steamwar.network.packets.common.FightInfoPacket;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.time.Instant; import java.time.Instant;
@ -36,17 +34,15 @@ public class Fightserver {
private static final Map<String, Fightserver> servers = new HashMap<>(); private static final Map<String, Fightserver> servers = new HashMap<>();
public static void init() { public static void init() {
BungeeReceiver.registerHandler(PacketIdManager.FIGHT_INFO, Fightserver::newFightInfo);
Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), Fightserver::removeStopped, 20, 20); Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), Fightserver::removeStopped, 20, 20);
} }
private static void newFightInfo(ByteArrayDataInput in) { public static void newFightInfo(FightInfoPacket in) {
FightInfoPacket fightInfo = new FightInfoPacket(in); Fightserver server = servers.get(in.getServerName());
Fightserver server = servers.get(fightInfo.getServerName());
if (server == null) { if (server == null) {
new Fightserver(fightInfo); new Fightserver(in);
} else { } else {
server.update(fightInfo); server.update(in);
} }
} }

Datei anzeigen

@ -0,0 +1,37 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -68,6 +68,7 @@ public class LobbySystem extends JavaPlugin {
new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X); new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X);
new AlphaWall(l -> l.getZ() > 892, AlphaWall.REFLECT_Z); new AlphaWall(l -> l.getZ() > 892, AlphaWall.REFLECT_Z);
new AlphaWall(l -> l.getZ() < 1794, AlphaWall.REFLECT_Z); new AlphaWall(l -> l.getZ() < 1794, AlphaWall.REFLECT_Z);
new LobbyPacketHandler();
} }
@Override @Override

Datei anzeigen

@ -19,19 +19,20 @@
package de.steamwar.lobby; package de.steamwar.lobby;
import com.google.common.io.ByteArrayDataInput; import de.steamwar.network.packets.PacketHandler;
import de.steamwar.comms.BungeeReceiver;
import de.steamwar.comms.PacketIdManager;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import de.steamwar.network.packets.server.StartingServerPacket;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
public class WaitingHall { public class WaitingHall extends PacketHandler {
public WaitingHall() { public WaitingHall() {
BungeeReceiver.registerHandler(PacketIdManager.STARTING_SERVER, this::serverStarting); super();
this.register();
} }
private void serverStarting(ByteArrayDataInput in) { @Handler
Bukkit.getPlayer(SteamwarUser.get(in.readInt()).getUUID()).teleport(LobbySystem.config().getWaitingHallSpawn(), PlayerTeleportEvent.TeleportCause.PLUGIN); private void serverStarting(StartingServerPacket in) {
Bukkit.getPlayer(SteamwarUser.get(in.getUser()).getUUID()).teleport(LobbySystem.config().getWaitingHallSpawn(), PlayerTeleportEvent.TeleportCause.PLUGIN);
} }
} }

Datei anzeigen

@ -19,9 +19,10 @@
package de.steamwar.lobby.listener; package de.steamwar.lobby.listener;
import de.steamwar.comms.packets.ImALobbyPacket;
import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.util.ItemBuilder; 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.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
@ -57,7 +58,7 @@ public class PlayerSpawn extends BasicListener {
player.setFoodLevel(20); player.setFoodLevel(20);
giveItems(player); 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) { private void giveItems(Player player) {

Datei anzeigen

@ -19,10 +19,12 @@
package de.steamwar.lobby.portal; package de.steamwar.lobby.portal;
import de.steamwar.comms.packets.ExecuteCommandPacket;
import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.command.ModifyCommand; import de.steamwar.lobby.command.ModifyCommand;
import de.steamwar.lobby.listener.Portals; 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.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -82,7 +84,7 @@ public class CommandPortal implements PortalHandler {
if(ModifyCommand.modifying(player)) if(ModifyCommand.modifying(player))
player.sendMessage("/" + cmd); player.sendMessage("/" + cmd);
new ExecuteCommandPacket(player, cmd.toString()).send(player); NetworkSender.send(new ExecuteCommandPacket(SteamwarUser.get(player).getId(), cmd.toString()));
} }
@Override @Override

Datei anzeigen

@ -19,11 +19,11 @@
package de.steamwar.lobby.portal; package de.steamwar.lobby.portal;
import de.steamwar.comms.packets.FightInfoPacket;
import de.steamwar.lobby.Fightserver; import de.steamwar.lobby.Fightserver;
import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.display.Hologram; import de.steamwar.lobby.display.Hologram;
import de.steamwar.lobby.display.NPC; import de.steamwar.lobby.display.NPC;
import de.steamwar.network.packets.common.FightInfoPacket;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;