SteamWar/SpigotCore
Archiviert
13
0

Rework Server-Bungee Networking #198

Zusammengeführt
Lixfel hat 3 Commits von new_packet nach master 2022-06-14 08:50:09 +02:00 zusammengeführt
18 geänderte Dateien mit 181 neuen und 749 gelöschten Zeilen

Datei anzeigen

@ -62,6 +62,8 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
implementation project(':CommonCore')
}
processResources {

Datei anzeigen

@ -1,70 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import de.steamwar.comms.handlers.BungeeHandler;
import de.steamwar.comms.handlers.InventoryHandler;
import de.steamwar.comms.handlers.LocaleInvalidationHandler;
import de.steamwar.core.BountifulWrapper;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class BungeeReceiver implements PluginMessageListener {
private static Map<Byte, BungeeHandler> handlerMap = new HashMap<>();
public static void registerHandler(Byte code, BungeeHandler handler) {
handlerMap.put(code, handler);
}
static {
registerHandler(PacketIdManager.PING_PACKET, byteArrayDataInput -> {
UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID();
if(Bukkit.getPlayer(uuid).isOnline()) {
Player player = Bukkit.getPlayer(uuid);
BountifulWrapper.impl.playPling(player);
}
});
registerHandler(PacketIdManager.BAUMEMBER_UPDATE, byteArrayDataInput -> BauweltMember.clear());
registerHandler(PacketIdManager.INVENTORY_PACKET, new InventoryHandler());
registerHandler(PacketIdManager.INVENTORY_CLOSE_PACKET, byteArrayDataInput -> {
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
player.closeInventory();
});
registerHandler(PacketIdManager.LOCALE_INVALIDATION, new LocaleInvalidationHandler());
}
@Override
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
Byte handler = in.readByte();
handlerMap.get(handler).handle(in);
}
}

Datei anzeigen

@ -1,42 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms;
public class PacketIdManager {
private 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;
}

Datei anzeigen

@ -1,27 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
public interface BungeeHandler {
void handle(ByteArrayDataInput byteArrayDataInput);
}

Datei anzeigen

@ -1,62 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import de.steamwar.comms.packets.InventoryCallbackPacket;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryType;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class InventoryHandler implements BungeeHandler {
@Override
public void handle(ByteArrayDataInput byteArrayDataInput) {
JsonObject object = new JsonParser().parse(byteArrayDataInput.readUTF()).getAsJsonObject();
UUID player = SteamwarUser.get(object.get("id").getAsInt()).getUUID();
String title = object.get("title").getAsString();
int size = object.get("size").getAsInt();
int length = object.get("itemcount").getAsInt();
Map<Integer, SWItem> items = new HashMap<>();
JsonArray array = object.get("items").getAsJsonArray();
for (int i = 0; i < length; i++) {
JsonObject itemJson = array.get(i).getAsJsonObject();
SWItem item = SWItem.getItemFromJson(itemJson);
item.setCallback(click -> new InventoryCallbackPacket(itemJson, click, player).send(Bukkit.getPlayer(player)));
items.put(itemJson.get("position").getAsInt(), item);
}
SWInventory inventory = new SWInventory(Bukkit.getPlayer(player), size, title, items);
inventory.addCloseCallback(click -> {
if(Bukkit.getPlayer(player).getOpenInventory().getType() != InventoryType.CHEST)
new InventoryCallbackPacket(player).send(Bukkit.getPlayer(player));
});
inventory.open();
}
}

Datei anzeigen

@ -1,47 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player;
public class ExecuteCommandPacket extends SpigotPacket {
private final SteamwarUser user;
private final String command;
public ExecuteCommandPacket(Player player, String command) {
this.user = SteamwarUser.get(player.getUniqueId());
this.command = command;
}
@Override
public int getName() {
return PacketIdManager.EXECUTE_COMMAND;
}
@Override
public void writeVars(ByteArrayDataOutput out) {
out.writeInt(user.getId());
out.writeUTF(command);
}
}

Datei anzeigen

@ -1,76 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.List;
@AllArgsConstructor
@Getter
public class FightEndsPacket extends SpigotPacket {
private byte win;
private int blueSchem;
private int redSchem;
private List<Integer> bluePlayers;
private List<Integer> redPlayers;
private String gameMode;
public FightEndsPacket(ByteArrayDataInput byteArrayDataInput) {
win = byteArrayDataInput.readByte();
blueSchem = byteArrayDataInput.readInt();
redSchem = byteArrayDataInput.readInt();
int blueSize = byteArrayDataInput.readInt();
for (int i = 0; i < blueSize; i++) {
bluePlayers.add(byteArrayDataInput.readInt());
}
int redSize = byteArrayDataInput.readInt();
for (int i = 0; i < redSize; i++) {
redPlayers.add(byteArrayDataInput.readInt());
}
gameMode = byteArrayDataInput.readUTF();
}
@Override
public int getName() {
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);
}
}

Datei anzeigen

@ -1,174 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import java.util.ArrayList;
import java.util.List;
public class FightInfoPacket extends SpigotPacket {
private final String serverName; // Name of the Server, might be changed by Bungee
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<Integer> bluePlayers; // List of Blue SWUserIDs
private final List<Integer> redPlayers; // List of Red SWUserIDs
private final List<Integer> 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<Integer> bluePlayers, List<Integer> redPlayers, List<Integer> 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 getName() {
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 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<Integer> getBluePlayers() {
return bluePlayers;
}
public List<Integer> getRedPlayers() {
return redPlayers;
}
public List<Integer> getSpectators() {
return spectators;
}
private static List<Integer> readPlayerList(ByteArrayDataInput in) {
int length = in.readInt();
List<Integer> players = new ArrayList<>(length);
for(int i = 0; i < length; i++) {
players.add(in.readInt());
}
return players;
}
private void writePlayerList(ByteArrayDataOutput out, List<Integer> players) {
out.writeInt(players.size());
for(Integer player : players) {
out.writeInt(player);
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
public class ImALobbyPacket extends SpigotPacket {
@Override
public int getName() {
return PacketIdManager.I_AM_A_LOBBY;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
//no content
}
}

Datei anzeigen

@ -1,90 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import com.google.gson.JsonObject;
import de.steamwar.comms.PacketIdManager;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.event.inventory.ClickType;
import java.util.UUID;
public class InventoryCallbackPacket extends SpigotPacket {
int position = -1;
ClickType clickType;
CallbackType callbackType;
int owner;
@Override
public int getName() {
return PacketIdManager.INVENTORY_CALLBACK_PACKET;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(owner);
byteArrayDataOutput.writeUTF(callbackType.name());
if(position != -1){
byteArrayDataOutput.writeInt(position);
byteArrayDataOutput.writeUTF(clickType.name());
}
}
public InventoryCallbackPacket() {}
public InventoryCallbackPacket(JsonObject itemJson, ClickType click, UUID player) {
setPosition(itemJson.get("position").getAsInt());
setClick(click);
setCallback(InventoryCallbackPacket.CallbackType.CLICK);
setOwner(SteamwarUser.get(player).getId());
}
public InventoryCallbackPacket(UUID player) {
setCallback(CallbackType.CLOSE);
setOwner(SteamwarUser.get(player).getId());
}
public InventoryCallbackPacket setPosition(int position) {
this.position = position;
return this;
}
public InventoryCallbackPacket setClick(ClickType type){
this.clickType = type;
return this;
}
public InventoryCallbackPacket setCallback(CallbackType callback) {
callbackType = callback;
return this;
}
public InventoryCallbackPacket setOwner(int id) {
this.owner = id;
return this;
}
public enum CallbackType {
CLICK,
CLOSE,
}
}

Datei anzeigen

@ -1,51 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
public class PrepareSchemPacket extends SpigotPacket{
private final SteamwarUser user;
private final SchematicNode schematic;
private final SchematicType schematicType;
public PrepareSchemPacket(SteamwarUser user, SchematicNode schematic, SchematicType schematicType) {
this.user = user;
this.schematic = schematic;
this.schematicType = schematicType;
}
@Override
public int getName() {
return PacketIdManager.PREPARE_SCHEM;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(user.getId());
byteArrayDataOutput.writeInt(schematic.getId());
byteArrayDataOutput.writeUTF(schematicType.toDB());
}
}

Datei anzeigen

@ -1,39 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import de.steamwar.core.Core;
import org.bukkit.entity.Player;
public abstract class SpigotPacket {
public void send(Player player) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeByte(getName());
writeVars(out);
player.sendPluginMessage(Core.getInstance(), "sw:bridge", out.toByteArray());
}
public abstract int getName();
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
}

Datei anzeigen

@ -1,26 +0,0 @@
package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
public class TablistNamePacket extends SpigotPacket {
final int swUserId;
final String tablistName;
public TablistNamePacket(int swUserId, String tablistName){
this.swUserId = swUserId;
this.tablistName = tablistName;
}
@Override
public int getName() {
return PacketIdManager.TABLIST_NAME;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(swUserId);
byteArrayDataOutput.writeUTF(tablistName);
}
}

Datei anzeigen

@ -23,12 +23,12 @@ import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.SWTypeMapperCreator;
import de.steamwar.command.TypeMapper;
import de.steamwar.comms.BungeeReceiver;
import de.steamwar.core.authlib.AuthlibInjector;
import de.steamwar.core.events.ChattingEvent;
import de.steamwar.core.events.PlayerJoinedEvent;
import de.steamwar.core.events.WorldLoadEvent;
import de.steamwar.message.Message;
import de.steamwar.network.NetworkReceiver;
import de.steamwar.sql.Statement;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -120,7 +120,7 @@ public class Core extends JavaPlugin{
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this);
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new NetworkReceiver());
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
if(Core.getVersion() < 19)
AuthlibInjector.inject();

Datei anzeigen

@ -0,0 +1,71 @@
/*
* 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.network;
import de.steamwar.core.BountifulWrapper;
import de.steamwar.network.handlers.InventoryHandler;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.server.*;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
public class CoreNetworkHandler extends PacketHandler {
public CoreNetworkHandler() {
super();
new InventoryHandler().register();
}
@Handler
public void handleBaumemberUpdatePacket(BaumemberUpdatePacket packet) {
BauweltMember.clear();
}
@Handler
public void handleCloseInventoryPacket(CloseInventoryPacket packet) {
Player player = Bukkit.getPlayer(SteamwarUser.get(packet.getPlayerId()).getUUID());
if (player != null) {
player.closeInventory();
}
}
@Handler
public void handleInventoryPacket(InventoryPacket packet) {
InventoryHandler.handleInventoryPacket(packet);
}
@Handler
public void handlePingPacket(PingPacket packet) {
UUID uuid = SteamwarUser.get(packet.getId()).getUUID();
if(Bukkit.getPlayer(uuid) != null) {
Player player = Bukkit.getPlayer(uuid);
BountifulWrapper.impl.playPling(player);
}
}
@Handler
public void handleLocaleChange(LocaleInvalidationPacket packet) {
SteamwarUser.invalidate(packet.getPlayerId());
}
}

Datei anzeigen

@ -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,15 +17,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.comms.handlers;
package de.steamwar.network;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.network.packets.NetworkPacket;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
public class LocaleInvalidationHandler implements BungeeHandler {
public class NetworkReceiver implements PluginMessageListener {
public NetworkReceiver() {
new CoreNetworkHandler().register();
}
@Override
public void handle(ByteArrayDataInput byteArrayDataInput) {
SteamwarUser.invalidate(byteArrayDataInput.readInt());
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
NetworkPacket.handle(message);
}
}

Datei anzeigen

@ -0,0 +1,38 @@
/*
* 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.network;
import de.steamwar.core.Core;
import de.steamwar.network.packets.NetworkPacket;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class NetworkSender {
public static void send(NetworkPacket packet) {
Bukkit.getOnlinePlayers().stream().findAny().ifPresent(player -> send(packet, player));
}
@SneakyThrows
public static void send(NetworkPacket packet, Player player) {
player.sendPluginMessage(Core.getInstance(), "sw:bridge", packet.serialize());
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
* 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.network.handlers;
import com.google.gson.JsonParser;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.network.NetworkSender;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.client.InventoryCallbackPacket;
import de.steamwar.network.packets.server.InventoryPacket;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryType;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class InventoryHandler extends PacketHandler {
@Handler
public static void handleInventoryPacket(InventoryPacket packet) {
Map<Integer, SWItem> items = new HashMap<>();
packet.getItems().forEach((i, item) -> {
SWItem it = SWItem.getItemFromJson(JsonParser.parseString(item).getAsJsonObject());
it.setCallback(click -> NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).position(i).type(InventoryCallbackPacket.CallbackType.CLICK).clickType(InventoryCallbackPacket.ClickType.getByName(click.name())).build()));
items.put(i, it);
});
UUID player = SteamwarUser.get(packet.getPlayer()).getUUID();
SWInventory inventory = new SWInventory(Bukkit.getPlayer(player), packet.getSize(), packet.getTitle(), items);
inventory.addCloseCallback(click -> {
if(Bukkit.getPlayer(player).getOpenInventory().getType() != InventoryType.CHEST)
NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).type(InventoryCallbackPacket.CallbackType.CLOSE).build());
});
inventory.open();
}
}