diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java
index e15cfc4..40b8399 100644
--- a/src/de/steamwar/bungeecore/BungeeCore.java
+++ b/src/de/steamwar/bungeecore/BungeeCore.java
@@ -22,9 +22,9 @@ package de.steamwar.bungeecore;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.commands.*;
-import de.steamwar.bungeecore.comms.SpigotReceiver;
import de.steamwar.bungeecore.listeners.*;
import de.steamwar.bungeecore.listeners.mods.*;
+import de.steamwar.bungeecore.network.NetworkReceiver;
import de.steamwar.bungeecore.sql.*;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
@@ -156,7 +156,7 @@ public class BungeeCore extends Plugin {
new EventStarter();
new SessionManager();
- new SpigotReceiver();
+ new NetworkReceiver();
new TablistManager();
new SettingsChangedListener();
diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java
index 2908acb..9842154 100644
--- a/src/de/steamwar/bungeecore/SubserverSystem.java
+++ b/src/de/steamwar/bungeecore/SubserverSystem.java
@@ -19,10 +19,11 @@
package de.steamwar.bungeecore;
-import de.steamwar.bungeecore.comms.handlers.FightInfoHandler;
-import de.steamwar.bungeecore.comms.packets.StartingServerPacket;
+import de.steamwar.bungeecore.network.NetworkSender;
+import de.steamwar.bungeecore.network.handlers.FightInfoHandler;
import de.steamwar.bungeecore.sql.IgnoreSystem;
import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.network.packets.server.StartingServerPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -53,6 +54,6 @@ public class SubserverSystem {
public static void sendPlayer(Subserver subserver, ProxiedPlayer player) {
subserver.sendPlayer(player);
if(!subserver.hasStarted() && FightInfoHandler.onLobby(player))
- new StartingServerPacket(SteamwarUser.get(player.getUniqueId())).send(player);
+ NetworkSender.send(player, new StartingServerPacket(SteamwarUser.get(player.getUniqueId()).getId()));
}
}
diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java
index ea21cd9..fb28fd8 100644
--- a/src/de/steamwar/bungeecore/commands/BauCommand.java
+++ b/src/de/steamwar/bungeecore/commands/BauCommand.java
@@ -20,12 +20,13 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
-import de.steamwar.bungeecore.comms.packets.BaumemberUpdatePacket;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
+import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.messages.ChatSender;
+import de.steamwar.network.packets.server.BaumemberUpdatePacket;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
@@ -197,7 +198,7 @@ public class BauCommand extends BasicCommand {
for(ServerInfo info : ProxyServer.getInstance().getServers().values()){
Subserver server = Subserver.getSubserver(info);
if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){
- info.getPlayers().stream().findAny().ifPresent(player -> new BaumemberUpdatePacket().send(player));
+ info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket()));
break;
}
}
diff --git a/src/de/steamwar/bungeecore/comms/BungeePacket.java b/src/de/steamwar/bungeecore/comms/BungeePacket.java
deleted file mode 100644
index b0417d2..0000000
--- a/src/de/steamwar/bungeecore/comms/BungeePacket.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms;
-
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.connection.Server;
-
-import java.io.ByteArrayOutputStream;
-
-public abstract class BungeePacket {
-
- public void send(Server server) {
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeByte(getId());
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- writeVars(out);
- out.writeUTF(outputStream.toByteArray().toString());
- server.sendData("sw:bridge", out.toByteArray());
- }
-
- public void send(ProxiedPlayer player) {
- send(player.getServer());
- }
-
- public abstract int getId();
-
- public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
-}
diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java
deleted file mode 100644
index 94edde9..0000000
--- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms;
-
-public class PacketIdManager {
-
- //0x0(X) Standalone Packets
- public static final byte PING_PACKET = 0x01;
- public static final byte TABLIST_NAME = 0x02;
- public static final byte PREPARE_SCHEM = 0x03;
- public static final byte BAUMEMBER_UPDATE = 0x04;
- public static final byte EXECUTE_COMMAND = 0x05;
-
- public static final byte LOCALE_INVALIDATION = 0x06;
-
- //0x1(X) Bungee Inventory
- public static final byte INVENTORY_PACKET = 0x10;
- public static final byte INVENTORY_CALLBACK_PACKET = 0x11;
- public static final byte INVENTORY_CLOSE_PACKET = 0x12;
-
- //0x2(X) Server Information System
- 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/SpigotHandler.java b/src/de/steamwar/bungeecore/comms/SpigotHandler.java
deleted file mode 100644
index 574e9a2..0000000
--- a/src/de/steamwar/bungeecore/comms/SpigotHandler.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms;
-
-import com.google.common.io.ByteArrayDataInput;
-import net.md_5.bungee.api.config.ServerInfo;
-
-public interface SpigotHandler {
-
- void handle(ByteArrayDataInput in, ServerInfo info);
-}
diff --git a/src/de/steamwar/bungeecore/comms/SpigotReceiver.java b/src/de/steamwar/bungeecore/comms/SpigotReceiver.java
deleted file mode 100644
index 04b107a..0000000
--- a/src/de/steamwar/bungeecore/comms/SpigotReceiver.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms;
-
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteStreams;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.comms.handlers.*;
-import de.steamwar.bungeecore.listeners.BasicListener;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.connection.Server;
-import net.md_5.bungee.api.event.PluginMessageEvent;
-import net.md_5.bungee.event.EventHandler;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class SpigotReceiver extends BasicListener {
-
- private static final Map handlerMap = new HashMap<>();
-
- @EventHandler
- public void onPluginMessage(PluginMessageEvent event) {
- if(!event.getTag().equalsIgnoreCase("sw:bridge"))
- return;
-
- event.setCancelled(true);
- if(!(event.getSender() instanceof Server))
- return;
-
- ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
- Byte handler = in.readByte();
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo()));
- }
-
- public static void registerHandler(Byte id, SpigotHandler handler) {
- handlerMap.put(id, handler);
- }
-
- static {
- registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
- registerHandler(PacketIdManager.TABLIST_NAME, (in, info) -> {});
- registerHandler(PacketIdManager.PREPARE_SCHEM, new PrepareSchemHandler());
- registerHandler(PacketIdManager.I_AM_A_LOBBY, new ImALobbyHandler());
- registerHandler(PacketIdManager.FIGHT_INFO, new FightInfoHandler());
- registerHandler(PacketIdManager.EXECUTE_COMMAND, new ExecuteCommandHandler());
- registerHandler(PacketIdManager.FIGHT_ENDS, new FightEndsHandler());
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java b/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java
deleted file mode 100644
index ddb4021..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-
-public class BaumemberUpdatePacket extends BungeePacket {
- @Override
- public int getId() {
- return PacketIdManager.BAUMEMBER_UPDATE;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
- // empty
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java b/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java
deleted file mode 100644
index 0445c10..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-
-public class CloseInventoryPacket extends BungeePacket {
-
- final int player;
-
- @Override
- public int getId() {
- return PacketIdManager.INVENTORY_CLOSE_PACKET;
- }
-
- public CloseInventoryPacket(int player) {
- this.player = player;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
- byteArrayDataOutput.writeInt(player);
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java b/src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java
deleted file mode 100644
index 3e282ee..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2020 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.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@AllArgsConstructor
-@Getter
-public class FightEndsPacket extends BungeePacket {
-
- private byte win;
- private int blueSchem;
- private int redSchem;
- private List bluePlayers;
- private List redPlayers;
- private String gameMode;
-
- public FightEndsPacket(ByteArrayDataInput byteArrayDataInput) {
- win = byteArrayDataInput.readByte();
- blueSchem = byteArrayDataInput.readInt();
- redSchem = byteArrayDataInput.readInt();
- int blueSize = byteArrayDataInput.readInt();
- bluePlayers = new ArrayList<>(blueSize);
- for (int i = 0; i < blueSize; i++) {
- bluePlayers.add(byteArrayDataInput.readInt());
- }
- int redSize = byteArrayDataInput.readInt();
- redPlayers = new ArrayList<>(redSize);
- for (int i = 0; i < redSize; i++) {
- redPlayers.add(byteArrayDataInput.readInt());
- }
- gameMode = byteArrayDataInput.readUTF();
- }
-
- @Override
- public int getId() {
- return PacketIdManager.FIGHT_ENDS;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
- byteArrayDataOutput.writeByte(win);
- byteArrayDataOutput.writeInt(blueSchem);
- byteArrayDataOutput.writeInt(redSchem);
- byteArrayDataOutput.writeInt(bluePlayers.size());
- for (int i : bluePlayers) {
- byteArrayDataOutput.writeInt(i);
- }
- byteArrayDataOutput.writeInt(redPlayers.size());
- for (int i : redPlayers) {
- byteArrayDataOutput.writeInt(i);
- }
- byteArrayDataOutput.writeUTF(gameMode);
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java b/src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java
deleted file mode 100644
index 34f120a..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class FightInfoPacket extends BungeePacket {
-
- private String serverName; // Name of the Server
- private final String gameMode; // GameMode aka Schematictype (if known, else "")
- private final String arena; // Name of the arena
- private final String blueName; // Name of the blue team, expected to begin with "§a" colorcode
- private final String redName; // Name of the red team, expected to begin with "§a" colorcode
- private final String fightState; // Fight state (technical term) (if known, else "")
- private final int countdown; // Countdown state in seconds (if known, else 0)
- private final int blueLeader; // SWUserID of the blue team leader (if known, else 0)
- private final int redLeader; // SWUserID of the red team leader (if known, else 0)
- private final int blueSchem; // Blue SchemID (if known, else 0)
- private final int redSchem; // Red SchemID (if known, else 0)
- private final List bluePlayers; // List of Blue SWUserIDs
- private final List redPlayers; // List of Red SWUserIDs
- private final List spectators; // List of Spectator SWUserIDs
-
- public FightInfoPacket(String serverName, String gameMode, String arena, String blueName, String redName, String fightState, int countdown, int blueLeader, int redLeader, int blueSchem, int redSchem, List bluePlayers, List redPlayers, List spectators) {
- this.serverName = serverName;
- this.gameMode = gameMode;
- this.arena = arena;
- this.blueName = blueName;
- this.redName = redName;
- this.fightState = fightState;
- this.countdown = countdown;
- this.blueLeader = blueLeader;
- this.redLeader = redLeader;
- this.blueSchem = blueSchem;
- this.redSchem = redSchem;
- this.bluePlayers = bluePlayers;
- this.redPlayers = redPlayers;
- this.spectators = spectators;
- }
-
- public FightInfoPacket(ByteArrayDataInput in) {
- this.serverName = in.readUTF();
- this.gameMode = in.readUTF();
- this.arena = in.readUTF();
- this.blueName = in.readUTF();
- this.redName = in.readUTF();
- this.fightState = in.readUTF();
- this.countdown = in.readInt();
- this.blueLeader = in.readInt();
- this.redLeader = in.readInt();
- this.blueSchem = in.readInt();
- this.redSchem = in.readInt();
- this.bluePlayers = readPlayerList(in);
- this.redPlayers = readPlayerList(in);
- this.spectators = readPlayerList(in);
- }
-
- @Override
- public int getId() {
- return PacketIdManager.FIGHT_INFO;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput out) {
- out.writeUTF(serverName);
- out.writeUTF(gameMode);
- out.writeUTF(arena);
- out.writeUTF(blueName);
- out.writeUTF(redName);
- out.writeUTF(fightState);
- out.writeInt(countdown);
- out.writeInt(blueLeader);
- out.writeInt(redLeader);
- out.writeInt(blueSchem);
- out.writeInt(redSchem);
- writePlayerList(out, bluePlayers);
- writePlayerList(out, redPlayers);
- writePlayerList(out, spectators);
- }
-
- public String getServerName() {
- return serverName;
- }
-
- public void setServerName(String serverName) {
- this.serverName = serverName;
- }
-
- public String getGameMode() {
- return gameMode;
- }
-
- public String getArena() {
- return arena;
- }
-
- public String getBlueName() {
- return blueName;
- }
-
- public String getRedName() {
- return redName;
- }
-
- public String getFightState() {
- return fightState;
- }
-
- public int getCountdown() {
- return countdown;
- }
-
- public int getBlueLeader() {
- return blueLeader;
- }
-
- public int getRedLeader() {
- return redLeader;
- }
-
- public int getBlueSchem() {
- return blueSchem;
- }
-
- public int getRedSchem() {
- return redSchem;
- }
-
- public List getBluePlayers() {
- return bluePlayers;
- }
-
- public List getRedPlayers() {
- return redPlayers;
- }
-
- public List getSpectators() {
- return spectators;
- }
-
- public int playerSize(){
- return bluePlayers.size() + redPlayers.size() + spectators.size();
- }
-
- private static List readPlayerList(ByteArrayDataInput in) {
- int length = in.readInt();
- List players = new ArrayList<>(length);
- for(int i = 0; i < length; i++) {
- players.add(in.readInt());
- }
- return players;
- }
-
- private void writePlayerList(ByteArrayDataOutput out, List players) {
- out.writeInt(players.size());
- for(Integer player : players) {
- out.writeInt(player);
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java b/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java
deleted file mode 100644
index f9a6195..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-import de.steamwar.bungeecore.inventory.SWInventory;
-import de.steamwar.bungeecore.inventory.SWItem;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.sql.SteamwarUser;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class InventoryPacket extends BungeePacket {
-
- final String title;
- final int player;
- final int size;
- final Map items;
-
- public InventoryPacket(int size, String title, ProxiedPlayer player) {
- items = new HashMap<>();
- this.title = title;
- this.size = size;
- this.player = SteamwarUser.get(player).getId();
- }
-
- public InventoryPacket(SWInventory inventory) {
- items = inventory.getItems();
- this.title = inventory.getTitle();
- this.size = inventory.getSize();
- this.player = SteamwarUser.get(inventory.getPlayer()).getId();
- }
-
- @Override
- public int getId() {
- return PacketIdManager.INVENTORY_PACKET;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
- JsonObject object = new JsonObject();
- object.addProperty("id", player);
- object.addProperty("title", title);
- object.addProperty("size", size);
- object.addProperty("itemcount", items.size());
- JsonArray array = new JsonArray();
- for (int i = 0; i < size; i++) {
- if(items.get(i) != null)
- array.add(items.get(i).writeToString(i));
- }
- object.add("items", array);
- byteArrayDataOutput.writeUTF(object.toString());
- }
-
- public void setItem(int index, SWItem item) {
- items.put(index, item);
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/PingPacket.java b/src/de/steamwar/bungeecore/comms/packets/PingPacket.java
deleted file mode 100644
index 47f2bd3..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/PingPacket.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-
-public class PingPacket extends BungeePacket {
-
- final int id;
-
- @Override
- public int getId() {
- return PacketIdManager.PING_PACKET;
- }
-
- public PingPacket(int id) {
- this.id = id;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
- byteArrayDataOutput.writeInt(id);
- }
-}
diff --git a/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java b/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java
deleted file mode 100644
index 1e5edf1..0000000
--- a/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package de.steamwar.bungeecore.comms.packets;
-
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
-import de.steamwar.bungeecore.sql.SteamwarUser;
-
-public class StartingServerPacket extends BungeePacket {
-
- private final int user;
-
- public StartingServerPacket(SteamwarUser user) {
- this.user = user.getId();
- }
-
- @Override
- public int getId() {
- return PacketIdManager.STARTING_SERVER;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput out) {
- out.writeInt(user);
- }
-}
diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java
index 0d4a8d3..1f83b41 100644
--- a/src/de/steamwar/bungeecore/inventory/SWInventory.java
+++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java
@@ -19,10 +19,11 @@
package de.steamwar.bungeecore.inventory;
-import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
-import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
-import de.steamwar.bungeecore.comms.packets.InventoryPacket;
+import de.steamwar.bungeecore.network.NetworkSender;
+import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.network.packets.server.CloseInventoryPacket;
+import de.steamwar.network.packets.server.InventoryPacket;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList;
@@ -30,6 +31,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiFunction;
public class SWInventory {
@@ -120,8 +122,14 @@ public class SWInventory {
}
public void open() {
- InventoryPacket inv = new InventoryPacket(this);
- inv.send(player);
+ InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).getAsString()));
+ NetworkSender.send(player, inv);
+ }
+
+ private static Map map(Map map, BiFunction function) {
+ Map result = new HashMap<>();
+ map.forEach((key, value) -> result.put(key, function.apply(key, value)));
+ return result;
}
public void close() {
@@ -129,7 +137,7 @@ public class SWInventory {
}
public static void close(ProxiedPlayer player) {
- new CloseInventoryPacket(SteamwarUser.get(player).getId()).send(player);
+ NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player).getId()));
}
public void setClose(InvCallback close) {
diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java
index 483dc9d..a815f6a 100644
--- a/src/de/steamwar/bungeecore/listeners/ChatListener.java
+++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java
@@ -21,10 +21,11 @@ package de.steamwar.bungeecore.listeners;
import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.bungeecore.comms.packets.PingPacket;
+import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.messages.ChatSender;
+import de.steamwar.network.packets.server.PingPacket;
import net.md_5.bungee.api.*;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
@@ -203,7 +204,7 @@ public class ChatListener extends BasicListener {
String mark = "@" + player.user().getUserName();
return Arrays.stream(message.split(" ")).map(cur -> {
if(cur.equalsIgnoreCase(mark)) {
- new PingPacket(player.user().getId()).send(player.user().getPlayer());
+ NetworkSender.send(player.user().getPlayer(), new PingPacket(player.user().getId()));
return "§e" + cur + returnColor;
}
return cur;
diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java
index 0a58268..e1c3325 100644
--- a/src/de/steamwar/bungeecore/listeners/TablistManager.java
+++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java
@@ -26,10 +26,10 @@ import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
-import de.steamwar.bungeecore.comms.packets.FightInfoPacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.UserGroup;
import net.md_5.bungee.BungeeCord;
+import de.steamwar.network.packets.common.FightInfoPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
diff --git a/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java
new file mode 100644
index 0000000..1cc4854
--- /dev/null
+++ b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java
@@ -0,0 +1,35 @@
+/*
+ * 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.bungeecore.network;
+
+import de.steamwar.bungeecore.network.handlers.*;
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+public class BungeeNetworkHandler {
+ public static void register() {
+ new ExecuteCommandHandler().register();
+ new FightEndsHandler().register();
+ new FightInfoHandler().register();
+ new ImALobbyHandler().register();
+ new InventoryCallbackHandler().register();
+ new PrepareSchemHandler().register();
+ }
+}
diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java
new file mode 100644
index 0000000..ee2e000
--- /dev/null
+++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java
@@ -0,0 +1,61 @@
+/*
+ * 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.bungeecore.network;
+
+import de.steamwar.bungeecore.BungeeCore;
+import de.steamwar.bungeecore.listeners.BasicListener;
+import de.steamwar.network.packets.NetworkPacket;
+import net.md_5.bungee.api.config.ServerInfo;
+import net.md_5.bungee.api.connection.Server;
+import net.md_5.bungee.api.event.PluginMessageEvent;
+import net.md_5.bungee.event.EventHandler;
+import net.md_5.bungee.event.EventPriority;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+
+public class NetworkReceiver extends BasicListener {
+
+ private static final List blockedTags = Arrays.asList("bungeecord:main", "BungeeCord", "sw:bridge");
+ private static final List allowedAddresses = Arrays.asList("localhost", "127.0.0.1", "0.0.0.0");
+
+ public static ServerInfo sender;
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onPluginMessage(PluginMessageEvent event) {
+ if (blockedTags.contains(event.getTag()) && !allowedAddresses.contains(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString())) {
+ BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag());
+ event.setCancelled(true);
+ return;
+ }
+ if(!event.getTag().equalsIgnoreCase("sw:bridge"))
+ return;
+
+ event.setCancelled(true);
+ if(!(event.getSender() instanceof Server))
+ return;
+
+ sender = (ServerInfo) event.getSender();
+ NetworkPacket.handle(event.getData());
+ sender = null;
+ }
+}
diff --git a/src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java b/src/de/steamwar/bungeecore/network/NetworkSender.java
similarity index 54%
rename from src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java
rename to src/de/steamwar/bungeecore/network/NetworkSender.java
index 1a0f4f7..d683f4a 100644
--- a/src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java
+++ b/src/de/steamwar/bungeecore/network/NetworkSender.java
@@ -1,7 +1,7 @@
/*
* This file is a part of the SteamWar software.
*
- * Copyright (C) 2020 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
@@ -17,27 +17,22 @@
* along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.packets;
+package de.steamwar.bungeecore.network;
-import com.google.common.io.ByteArrayDataOutput;
-import de.steamwar.bungeecore.comms.BungeePacket;
-import de.steamwar.bungeecore.comms.PacketIdManager;
+import de.steamwar.network.packets.NetworkPacket;
+import lombok.SneakyThrows;
+import net.md_5.bungee.api.config.ServerInfo;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
-public class LocaleInvalidationPacket extends BungeePacket {
+public class NetworkSender {
- private int userId;
-
- public LocaleInvalidationPacket(int userId) {
- this.userId = userId;
+ @SneakyThrows
+ public static void send(ProxiedPlayer player, NetworkPacket packet) {
+ player.sendData("sw:bridge", packet.serialize());
}
- @Override
- public int getId() {
- return PacketIdManager.LOCALE_INVALIDATION;
- }
-
- @Override
- public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
- byteArrayDataOutput.writeInt(userId);
+ public static void send(ServerInfo serverInfo, NetworkPacket packet) {
+ ProxiedPlayer player = serverInfo.getPlayers().iterator().next();
+ send(player, packet);
}
}
diff --git a/src/de/steamwar/bungeecore/comms/handlers/ExecuteCommandHandler.java b/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java
similarity index 70%
rename from src/de/steamwar/bungeecore/comms/handlers/ExecuteCommandHandler.java
rename to src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java
index 0051e55..ae31db5 100644
--- a/src/de/steamwar/bungeecore/comms/handlers/ExecuteCommandHandler.java
+++ b/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java
@@ -17,19 +17,19 @@
along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.handlers;
+package de.steamwar.bungeecore.network.handlers;
-import com.google.common.io.ByteArrayDataInput;
-import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.network.packets.PacketHandler;
+import de.steamwar.network.packets.client.ExecuteCommandPacket;
import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.config.ServerInfo;
-public class ExecuteCommandHandler implements SpigotHandler {
- @Override
- public void handle(ByteArrayDataInput in, ServerInfo info) {
- SteamwarUser target = SteamwarUser.get(in.readInt());
- String command = in.readUTF();
+public class ExecuteCommandHandler extends PacketHandler {
+
+ @Handler
+ public void handle(ExecuteCommandPacket packet) {
+ SteamwarUser target = SteamwarUser.get(packet.getPlayerId());
+ String command = packet.getCommand();
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getPlayer(target.getUuid()), command);
}
diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java
similarity index 93%
rename from src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java
rename to src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java
index b9a7492..b6a3f6b 100644
--- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java
+++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java
@@ -17,20 +17,18 @@
* along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.handlers;
+package de.steamwar.bungeecore.network.handlers;
-import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.ArenaMode;
-import de.steamwar.bungeecore.comms.SpigotHandler;
-import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
import de.steamwar.bungeecore.sql.*;
+import de.steamwar.network.packets.PacketHandler;
+import de.steamwar.network.packets.common.FightEndsPacket;
import lombok.RequiredArgsConstructor;
-import net.md_5.bungee.api.config.ServerInfo;
import java.util.*;
import java.util.stream.Collectors;
-public class FightEndsHandler implements SpigotHandler {
+public class FightEndsHandler extends PacketHandler {
private Map> gameModeGames = new HashMap<>();
@@ -46,10 +44,8 @@ public class FightEndsHandler implements SpigotHandler {
fightCounts.put("miniwargear", 3L);
}
- @Override
- public void handle(ByteArrayDataInput in, ServerInfo info) {
- FightEndsPacket fightEndsPacket = new FightEndsPacket(in);
-
+ @Handler
+ public void handle(FightEndsPacket fightEndsPacket) {
if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) {
return;
}
diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java
similarity index 75%
rename from src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java
rename to src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java
index eb708df..a4b6367 100644
--- a/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java
+++ b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java
@@ -17,12 +17,13 @@
along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.handlers;
+package de.steamwar.bungeecore.network.handlers;
-import com.google.common.io.ByteArrayDataInput;
-import de.steamwar.bungeecore.comms.SpigotHandler;
-import de.steamwar.bungeecore.comms.packets.FightInfoPacket;
import de.steamwar.bungeecore.listeners.TablistManager;
+import de.steamwar.bungeecore.network.NetworkReceiver;
+import de.steamwar.bungeecore.network.NetworkSender;
+import de.steamwar.network.packets.PacketHandler;
+import de.steamwar.network.packets.common.FightInfoPacket;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -30,7 +31,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-public class FightInfoHandler implements SpigotHandler {
+public class FightInfoHandler extends PacketHandler {
private static final Set lobbys = new HashSet<>();
@@ -42,10 +43,11 @@ public class FightInfoHandler implements SpigotHandler {
return lobbys.contains(player.getServer().getInfo());
}
- @Override
- public void handle(ByteArrayDataInput in, ServerInfo info) {
- FightInfoPacket packet = new FightInfoPacket(in);
- packet.setServerName(info.getName());
+ @Handler
+ public void handle(FightInfoPacket packet) {
+ ServerInfo info = NetworkReceiver.sender;
+
+ FightInfoPacket lobbyPacket = packet.withServerName(info.getName());
TablistManager.newFightInfo(info, packet);
@@ -58,7 +60,7 @@ public class FightInfoHandler implements SpigotHandler {
continue;
}
- packet.send(it.next());
+ NetworkSender.send(lobby, lobbyPacket);
}
}
}
diff --git a/src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java
similarity index 67%
rename from src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java
rename to src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java
index 8d2013d..54ce65f 100644
--- a/src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java
+++ b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java
@@ -17,16 +17,16 @@
along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.handlers;
+package de.steamwar.bungeecore.network.handlers;
-import com.google.common.io.ByteArrayDataInput;
-import de.steamwar.bungeecore.comms.SpigotHandler;
-import net.md_5.bungee.api.config.ServerInfo;
+import de.steamwar.bungeecore.network.NetworkReceiver;
+import de.steamwar.network.packets.PacketHandler;
+import de.steamwar.network.packets.client.ImALobbyPacket;
-public class ImALobbyHandler implements SpigotHandler {
+public class ImALobbyHandler extends PacketHandler {
- @Override
- public void handle(ByteArrayDataInput in, ServerInfo info) {
- FightInfoHandler.addLobby(info);
+ @Handler
+ public void handle(ImALobbyPacket packet) {
+ FightInfoHandler.addLobby(NetworkReceiver.sender);
}
}
diff --git a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java
similarity index 65%
rename from src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java
rename to src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java
index 0fd90a6..6110611 100644
--- a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java
+++ b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java
@@ -17,41 +17,42 @@
along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.handlers;
+package de.steamwar.bungeecore.network.handlers;
-import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.comms.SpigotHandler;
-import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
import de.steamwar.bungeecore.inventory.InvCallback;
import de.steamwar.bungeecore.inventory.SWInventory;
+import de.steamwar.bungeecore.network.NetworkReceiver;
+import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.network.packets.PacketHandler;
+import de.steamwar.network.packets.client.InventoryCallbackPacket;
+import de.steamwar.network.packets.server.CloseInventoryPacket;
import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.config.ServerInfo;
import java.util.HashMap;
import java.util.Map;
-public class InventoryCallbackHandler implements SpigotHandler {
+public class InventoryCallbackHandler extends PacketHandler {
public static final Map inventoryHashMap = new HashMap<>();
- @Override
- public void handle(ByteArrayDataInput in, ServerInfo info) {
- SteamwarUser owner = SteamwarUser.get(in.readInt());
- CallbackType type = CallbackType.valueOf(in.readUTF());
+ @Handler
+ public void handle(InventoryCallbackPacket packet) {
+ SteamwarUser owner = SteamwarUser.get(packet.getOwner());
+ InventoryCallbackPacket.CallbackType type = packet.getType();
if(!inventoryHashMap.containsKey(owner.getId())) {
BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden.");
- if(type == CallbackType.CLICK) {
- new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid()));
+ if(type == InventoryCallbackPacket.CallbackType.CLICK) {
+ NetworkSender.send(NetworkReceiver.sender, new CloseInventoryPacket(owner.getId()));
}
return;
}
- if(type == CallbackType.CLICK) {
- int pos = in.readInt();
- InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(in.readUTF());
+ if(type == InventoryCallbackPacket.CallbackType.CLICK) {
+ int pos = packet.getPosition();
+ InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(packet.getClickType().name());
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
- }else if(type == CallbackType.CLOSE) {
+ }else if(type == InventoryCallbackPacket.CallbackType.CLOSE) {
if(inventoryHashMap.get(owner.getId()).isNext()) {
inventoryHashMap.get(owner.getId()).handleClose();
return;
@@ -59,9 +60,4 @@ public class InventoryCallbackHandler implements SpigotHandler {
inventoryHashMap.get(owner.getId()).setNext(true);
}
}
-
- public enum CallbackType {
- CLICK,
- CLOSE,
- }
}
diff --git a/src/de/steamwar/bungeecore/comms/handlers/PrepareSchemHandler.java b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java
similarity index 74%
rename from src/de/steamwar/bungeecore/comms/handlers/PrepareSchemHandler.java
rename to src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java
index d968178..c59c8df 100644
--- a/src/de/steamwar/bungeecore/comms/handlers/PrepareSchemHandler.java
+++ b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java
@@ -17,24 +17,24 @@
along with this program. If not, see .
*/
-package de.steamwar.bungeecore.comms.handlers;
+package de.steamwar.bungeecore.network.handlers;
-import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.ServerStarter;
-import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.network.packets.PacketHandler;
+import de.steamwar.network.packets.client.PrepareSchemPacket;
import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
-public class PrepareSchemHandler implements SpigotHandler {
- @Override
- public void handle(ByteArrayDataInput in, ServerInfo info) {
- ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(in.readInt()).getUuid());
- int schematicID = in.readInt();
- ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(in.readUTF()));
+public class PrepareSchemHandler extends PacketHandler {
+
+ @Handler
+ public void handle(PrepareSchemPacket packet) {
+ ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(packet.getPlayer()).getUuid());
+ int schematicID = packet.getSchem();
+ ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType()));
new ServerStarter().test(mode, mode.getRandomMap(), player).prepare(schematicID).start();
}
diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java
index 829ee84..96c92d5 100644
--- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java
+++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java
@@ -23,9 +23,10 @@ import com.google.gson.JsonParser;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.WebregisterCommand;
-import de.steamwar.bungeecore.comms.packets.LocaleInvalidationPacket;
import de.steamwar.bungeecore.listeners.ConnectionListener;
+import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.messages.ChatSender;
+import de.steamwar.network.packets.server.LocaleInvalidationPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -388,6 +389,6 @@ public class SteamwarUser {
this.locale = locale;
this.manualLocale = manualLocale;
updateLocale.update(locale.toLanguageTag(), manualLocale, id);
- new LocaleInvalidationPacket(id).send(getPlayer());
+ NetworkSender.send(getPlayer(), new LocaleInvalidationPacket(id));
}
}