geforkt von SteamWar/BungeeCore
Merge pull request 'Use new FightInfo + Tablist refactoring' (#234) from fightInfoPacket into master
Reviewed-on: SteamWar/BungeeCore#234 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
bf2a4822ef
@ -31,4 +31,8 @@ public class PacketIdManager {
|
|||||||
public static final byte INVENTORY_PACKET = 0x10;
|
public static final byte INVENTORY_PACKET = 0x10;
|
||||||
public static final byte INVENTORY_CALLBACK_PACKET = 0x11;
|
public static final byte INVENTORY_CALLBACK_PACKET = 0x11;
|
||||||
public static final byte INVENTORY_CLOSE_PACKET = 0x12;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
package de.steamwar.bungeecore.comms;
|
package de.steamwar.bungeecore.comms;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
public interface SpigotHandler {
|
public interface SpigotHandler {
|
||||||
|
|
||||||
void handle(ByteArrayDataInput byteArrayDataInput);
|
void handle(ByteArrayDataInput in, ServerInfo info);
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,9 @@ package de.steamwar.bungeecore.comms;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
|
import de.steamwar.bungeecore.comms.handlers.*;
|
||||||
import de.steamwar.bungeecore.comms.handlers.PrepareSchemHandler;
|
|
||||||
import de.steamwar.bungeecore.comms.handlers.TablistNameHandler;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
@ -39,14 +38,14 @@ public class SpigotReceiver extends BasicListener {
|
|||||||
public void onPluginMessage(PluginMessageEvent event) {
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
|
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
|
||||||
return;
|
return;
|
||||||
if(!event.getSender().getAddress().getHostName().equals("localhost")){
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
if(!(event.getSender() instanceof Server))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||||
Byte handler = in.readByte();
|
Byte handler = in.readByte();
|
||||||
handlerMap.get(handler).handle(in);
|
handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo());
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerHandler(Byte id, SpigotHandler handler) {
|
public static void registerHandler(Byte id, SpigotHandler handler) {
|
||||||
@ -55,7 +54,9 @@ public class SpigotReceiver extends BasicListener {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
|
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
|
||||||
registerHandler(PacketIdManager.TABLIST_NAME, new TablistNameHandler());
|
registerHandler(PacketIdManager.TABLIST_NAME, (in, info) -> {});
|
||||||
registerHandler(PacketIdManager.PREPARE_SCHEM, new PrepareSchemHandler());
|
registerHandler(PacketIdManager.PREPARE_SCHEM, new PrepareSchemHandler());
|
||||||
|
registerHandler(PacketIdManager.I_AM_A_LOBBY, new ImALobbyHandler());
|
||||||
|
registerHandler(PacketIdManager.FIGHT_INFO, new FightInfoHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
60
src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java
Normale Datei
60
src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java
Normale Datei
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
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.bungeecore.comms.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 net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class FightInfoHandler implements SpigotHandler {
|
||||||
|
|
||||||
|
private static final Set<ServerInfo> lobbys = new HashSet<>();
|
||||||
|
|
||||||
|
public static void addLobby(ServerInfo lobby) {
|
||||||
|
lobbys.add(lobby);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(ByteArrayDataInput in, ServerInfo info) {
|
||||||
|
FightInfoPacket packet = new FightInfoPacket(in);
|
||||||
|
packet.setServerName(info.getName());
|
||||||
|
|
||||||
|
TablistManager.newFightInfo(info, packet);
|
||||||
|
|
||||||
|
Iterator<ServerInfo> lobbyIt = lobbys.iterator();
|
||||||
|
while(lobbyIt.hasNext()) {
|
||||||
|
ServerInfo lobby = lobbyIt.next();
|
||||||
|
Iterator<ProxiedPlayer> it = lobby.getPlayers().iterator();
|
||||||
|
if(!it.hasNext()){
|
||||||
|
lobbyIt.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
packet.send(it.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java
Normale Datei
32
src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java
Normale Datei
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
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.bungeecore.comms.handlers;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import de.steamwar.bungeecore.comms.SpigotHandler;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
|
public class ImALobbyHandler implements SpigotHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(ByteArrayDataInput in, ServerInfo info) {
|
||||||
|
FightInfoHandler.addLobby(info);
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,7 @@ import de.steamwar.bungeecore.inventory.InvCallback;
|
|||||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -36,9 +37,9 @@ public class InventoryCallbackHandler implements SpigotHandler {
|
|||||||
public static final Map<Integer, SWInventory> inventoryHashMap = new HashMap<>();
|
public static final Map<Integer, SWInventory> inventoryHashMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
public void handle(ByteArrayDataInput in, ServerInfo info) {
|
||||||
SteamwarUser owner = SteamwarUser.get(byteArrayDataInput.readInt());
|
SteamwarUser owner = SteamwarUser.get(in.readInt());
|
||||||
CallbackType type = CallbackType.valueOf(byteArrayDataInput.readUTF());
|
CallbackType type = CallbackType.valueOf(in.readUTF());
|
||||||
if(!inventoryHashMap.containsKey(owner.getId())) {
|
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.");
|
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) {
|
if(type == CallbackType.CLICK) {
|
||||||
@ -47,8 +48,8 @@ public class InventoryCallbackHandler implements SpigotHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(type == CallbackType.CLICK) {
|
if(type == CallbackType.CLICK) {
|
||||||
int pos = byteArrayDataInput.readInt();
|
int pos = in.readInt();
|
||||||
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF());
|
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(in.readUTF());
|
||||||
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
|
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
|
||||||
}else if(type == CallbackType.CLOSE) {
|
}else if(type == CallbackType.CLOSE) {
|
||||||
if(inventoryHashMap.get(owner.getId()).isNext()) {
|
if(inventoryHashMap.get(owner.getId()).isNext()) {
|
||||||
|
@ -27,14 +27,15 @@ import de.steamwar.bungeecore.comms.SpigotHandler;
|
|||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.bungeecore.sql.SchematicType;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
public class PrepareSchemHandler implements SpigotHandler {
|
public class PrepareSchemHandler implements SpigotHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
public void handle(ByteArrayDataInput in, ServerInfo info) {
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUuid());
|
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(in.readInt()).getUuid());
|
||||||
int schematicID = byteArrayDataInput.readInt();
|
int schematicID = in.readInt();
|
||||||
ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(byteArrayDataInput.readUTF()));
|
ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(in.readUTF()));
|
||||||
|
|
||||||
BauCommand.stopBauserver(player);
|
BauCommand.stopBauserver(player);
|
||||||
SubserverSystem.startTestServer(player, mode, mode.getRandomMap(), 0, schematicID);
|
SubserverSystem.startTestServer(player, mode, mode.getRandomMap(), 0, schematicID);
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.comms.handlers;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import de.steamwar.bungeecore.Subserver;
|
|
||||||
import de.steamwar.bungeecore.comms.SpigotHandler;
|
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
public class TablistNameHandler implements SpigotHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUuid());
|
|
||||||
Subserver subserver = Subserver.getSubserver(player.getServer().getInfo());
|
|
||||||
if(subserver == null)
|
|
||||||
return;
|
|
||||||
subserver.getTablistNames().put(player, byteArrayDataInput.readUTF());
|
|
||||||
}
|
|
||||||
}
|
|
183
src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java
Normale Datei
183
src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java
Normale Datei
@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
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.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<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 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<Integer> getBluePlayers() {
|
||||||
|
return bluePlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getRedPlayers() {
|
||||||
|
return redPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getSpectators() {
|
||||||
|
return spectators;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int playerSize(){
|
||||||
|
return bluePlayers.size() + redPlayers.size() + spectators.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,13 +26,12 @@ import de.steamwar.bungeecore.BungeeCore;
|
|||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.Servertype;
|
import de.steamwar.bungeecore.Servertype;
|
||||||
import de.steamwar.bungeecore.Subserver;
|
import de.steamwar.bungeecore.Subserver;
|
||||||
|
import de.steamwar.bungeecore.comms.packets.FightInfoPacket;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.bungeecore.sql.Team;
|
|
||||||
import de.steamwar.bungeecore.sql.UserGroup;
|
import de.steamwar.bungeecore.sql.UserGroup;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
@ -42,21 +41,39 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class TablistManager extends BasicListener {
|
public class TablistManager extends BasicListener {
|
||||||
|
|
||||||
private static final Map<ProxiedPlayer, Tablist> tablists = new HashMap<>();
|
private static final Map<ProxiedPlayer, Tablist> tablists = new HashMap<>();
|
||||||
|
|
||||||
private int seconds = 0;
|
@EventHandler
|
||||||
private Icon darkGray;
|
public synchronized void onJoin(PostLoginEvent e){
|
||||||
private Icon gray;
|
tablists.put(e.getPlayer(), new Tablist(e.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public synchronized void onLeave(PlayerDisconnectEvent e){
|
||||||
|
tablists.remove(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final Map<ServerInfo, FightInfoPacket> fightInfos = new HashMap<>();
|
||||||
|
|
||||||
|
public static synchronized void newFightInfo(ServerInfo info, FightInfoPacket packet) {
|
||||||
|
fightInfos.put(info, packet);
|
||||||
|
fightInfos.keySet().removeIf(serverInfo -> serverInfo.getPlayers().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Icon darkGray;
|
||||||
|
private static Icon gray;
|
||||||
|
|
||||||
|
private int seconds = 0;
|
||||||
private int size;
|
private int size;
|
||||||
private final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
|
private TablistGroup tablist;
|
||||||
|
|
||||||
public TablistManager(){
|
public TablistManager(){
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::updateCustomTablist, 1, 1, TimeUnit.SECONDS);
|
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::updateTablist, 1, 1, TimeUnit.SECONDS);
|
||||||
try{
|
try{
|
||||||
BungeeTabListPlusAPI.createIcon(ImageIO.read(new File("/configs/BungeeTabListPlus/heads/colors/dark_gray.png")), (icon) -> darkGray = icon);
|
BungeeTabListPlusAPI.createIcon(ImageIO.read(new File("/configs/BungeeTabListPlus/heads/colors/dark_gray.png")), (icon) -> darkGray = icon);
|
||||||
BungeeTabListPlusAPI.createIcon(ImageIO.read(new File("/configs/BungeeTabListPlus/heads/colors/gray.png")), (icon) -> gray = icon);
|
BungeeTabListPlusAPI.createIcon(ImageIO.read(new File("/configs/BungeeTabListPlus/heads/colors/gray.png")), (icon) -> gray = icon);
|
||||||
@ -69,61 +86,39 @@ public class TablistManager extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateSize() {
|
private synchronized void updateTablist(){
|
||||||
size = -1;
|
|
||||||
size += playerMap.size() * 2 + ProxyServer.getInstance().getPlayers().size();
|
|
||||||
size = (size + 19) / 20;
|
|
||||||
if(size > 5) size = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void updateCustomTablist(){
|
|
||||||
//Calculate server-player-map
|
//Calculate server-player-map
|
||||||
playerMap.clear();
|
tablist = new TablistGroup(true, "");
|
||||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
TablistGroup bau = new TablistGroup(false, "Bau");
|
||||||
Server pserver = player.getServer();
|
tablist.addSubTablist(bau);
|
||||||
if (pserver == null) //Happens temporarily
|
for (ServerInfo server : ProxyServer.getInstance().getServers().values()){
|
||||||
|
if(server.getPlayers().isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ServerInfo server = pserver.getInfo();
|
|
||||||
String serverName = server.getName();
|
|
||||||
|
|
||||||
Subserver subserver = Subserver.getSubserver(server);
|
Subserver subserver = Subserver.getSubserver(server);
|
||||||
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
|
if(subserver != null && subserver.getType() == Servertype.BAUSERVER)
|
||||||
playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player);
|
bau.addSubTablist(new TablistServer(server));
|
||||||
} else {
|
else if(fightInfos.containsKey(server))
|
||||||
playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player);
|
tablist.addSubTablist(new TablistServer(server, fightInfos.get(server)));
|
||||||
}
|
else
|
||||||
|
tablist.addSubTablist(new TablistServer(server));
|
||||||
}
|
}
|
||||||
playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
|
|
||||||
|
|
||||||
//Set size
|
|
||||||
calculateSize();
|
|
||||||
|
|
||||||
for(Tablist tablist : tablists.values())
|
|
||||||
tablist.refresh();
|
|
||||||
|
|
||||||
|
size = (int) Math.ceil(tablist.size() / 20.0);
|
||||||
|
tablists.values().forEach(Tablist::refresh);
|
||||||
seconds++;
|
seconds++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public synchronized void onJoin(PostLoginEvent e){
|
|
||||||
tablists.put(e.getPlayer(), new Tablist(e.getPlayer()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public synchronized void onLeave(PlayerDisconnectEvent e){
|
|
||||||
tablists.remove(e.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Tablist extends DefaultCustomTablist {
|
private class Tablist extends DefaultCustomTablist {
|
||||||
private final ProxiedPlayer player;
|
private final ProxiedPlayer player;
|
||||||
|
private int pos = 0;
|
||||||
|
|
||||||
private Tablist(ProxiedPlayer player){
|
private Tablist(ProxiedPlayer player){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
BungeeTabListPlusAPI.setCustomTabList(player, this);
|
BungeeTabListPlusAPI.setCustomTabList(player, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String calcHeader(ProxiedPlayer player){
|
private String header(){
|
||||||
int phase = (seconds % 16) / 3;
|
int phase = (seconds % 16) / 3;
|
||||||
switch(phase){
|
switch(phase){
|
||||||
case 0:
|
case 0:
|
||||||
@ -136,7 +131,7 @@ public class TablistManager extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPing(){
|
private String ping(){
|
||||||
int ping = player.getPing();
|
int ping = player.getPing();
|
||||||
if(ping < 50){
|
if(ping < 50){
|
||||||
return "§a" + ping;
|
return "§a" + ping;
|
||||||
@ -151,126 +146,164 @@ public class TablistManager extends BasicListener {
|
|||||||
if (player.getServer() == null) {
|
if (player.getServer() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ServerInfo currentServer = player.getServer().getInfo();
|
pos = 0;
|
||||||
setHeader(calcHeader(player));
|
setHeader(header());
|
||||||
// TABLIST_FOOTER=§e{0} {1}§8ms §eSpieler§8: §7{2}
|
setFooter("§e" + player.getServer().getInfo().getName() + " " + ping() + "§8ms §eSpieler§8: §7" + ProxyServer.getInstance().getPlayers().size());
|
||||||
setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms §eSpieler§8: §7" + ProxyServer.getInstance().getPlayers().size());
|
int currentSize = size > 4 ? tablist.slimSize(player) : size;
|
||||||
setSize(size, 20);
|
setSize(currentSize, 20);
|
||||||
|
|
||||||
if (size >= 5) {
|
tablist.print(this, size > 4);
|
||||||
refreshSlim(currentServer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
while (pos < currentSize*20){
|
||||||
int i = 0;
|
setSlot(darkGray, "", 1000);
|
||||||
for (String server : playerMap.navigableKeySet()) {
|
|
||||||
if (i > 0){
|
|
||||||
setSlot(i%20, i/20, darkGray, "", 1000);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if(server.equals("Bau"))
|
|
||||||
server = Message.parse("TABLIST_BAU", player);
|
|
||||||
setSlot(i%20, i/20, gray, "§7§l" + server, 1000);
|
|
||||||
i++;
|
|
||||||
i = update(currentServer, playerMap.get(server), i);
|
|
||||||
}
|
|
||||||
|
|
||||||
finish(i);
|
|
||||||
}catch(IndexOutOfBoundsException | NullPointerException e){
|
|
||||||
//Ignore IndexOutOfBoundsException
|
|
||||||
//Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshSlim(ServerInfo currentServer) {
|
private void setSlot(Icon icon, String name, int ping){
|
||||||
try {
|
setSlot(pos % 20, pos / 20, icon, name, ping);
|
||||||
int i = 0;
|
pos++;
|
||||||
boolean spacer = true;
|
}
|
||||||
for (String server : playerMap.navigableKeySet()) {
|
}
|
||||||
if (i > 0 && spacer) {
|
|
||||||
setSlot(i%20, i/20, darkGray, "", 1000);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
spacer = true;
|
|
||||||
Team team = getTeam(player);
|
|
||||||
List<ProxiedPlayer> players = playerMap.get(server)
|
|
||||||
.stream()
|
|
||||||
.filter(p -> (p.getServer() != null && p.getServer().getInfo() == currentServer) || SteamwarUser.get(p).getUserGroup() != UserGroup.Member || (team != null && team == getTeam(p)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
Subserver subserver = Subserver.getSubserver(player);
|
private interface TablistPart {
|
||||||
if (server.equals("Bau")) {
|
int size();
|
||||||
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
|
int slimSize(ProxiedPlayer viewer);
|
||||||
players = playerMap.get(server);
|
String name();
|
||||||
}
|
void print(Tablist viewer, boolean slim);
|
||||||
server = Message.parse("TABLIST_BAU", player);
|
}
|
||||||
}
|
|
||||||
if (subserver != null && subserver.getType() == Servertype.ARENA && playerMap.get(server).size() == 1) {
|
|
||||||
players = playerMap.get(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
int increment = playerMap.get(server).size() - players.size();
|
private static class TablistGroup implements TablistPart {
|
||||||
if (players.isEmpty()) {
|
|
||||||
server += " §7(" + increment + ")";
|
|
||||||
spacer = false;
|
|
||||||
} else if (increment != 0) {
|
|
||||||
server += " §7(+" + increment + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
setSlot(i%20, i/20, gray, "§7§l" + server, 1000);
|
private final boolean withHeaders;
|
||||||
i++;
|
private final String orderName;
|
||||||
i = update(currentServer, players, i);
|
private final List<TablistPart> subTablists = new ArrayList<>();
|
||||||
}
|
|
||||||
|
|
||||||
finish(i);
|
private TablistGroup(boolean withHeaders, String orderName) {
|
||||||
}catch(IndexOutOfBoundsException | NullPointerException e){
|
this.withHeaders = withHeaders;
|
||||||
//Ignore IndexOutOfBoundsException
|
this.orderName = orderName;
|
||||||
//Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int update(ServerInfo currentServer, List<ProxiedPlayer> players, int i) {
|
private void addSubTablist(TablistPart tablist){
|
||||||
for (ProxiedPlayer p : players){
|
subTablists.add(tablist);
|
||||||
boolean sameServer = currentServer == p.getServer().getInfo();
|
subTablists.sort((t1, t2) -> t1.name().compareToIgnoreCase(t2.name()));
|
||||||
setSlot(i % 20, i / 20, BungeeTabListPlusAPI.getIconFromPlayer(p), getTablistName(p), (sameServer ? 1 : 500));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finish(int i) {
|
@Override
|
||||||
while (i < size*20){
|
public int size() {
|
||||||
setSlot(i%20, i/20, darkGray, "", 1000);
|
int size = subTablists.stream().map(TablistPart::size).reduce(Integer::sum).orElse(0);
|
||||||
i++;
|
if(withHeaders)
|
||||||
}
|
size += Math.min(subTablists.size() - 1, 0);
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Team getTeam(ProxiedPlayer p) {
|
@Override
|
||||||
Team team = Team.get(SteamwarUser.get(p).getTeam());
|
public int slimSize(ProxiedPlayer viewer) {
|
||||||
return team.getTeamId() <= 0 ? null : team;
|
int size = subTablists.stream().map(tablist -> tablist.slimSize(viewer)).reduce(Integer::sum).orElse(0);
|
||||||
|
if(withHeaders)
|
||||||
|
size += Math.min(subTablists.size() - 1, 0);
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTablistName(ProxiedPlayer p) {
|
@Override
|
||||||
Subserver server = Subserver.getSubserver(p);
|
public String name() {
|
||||||
if(server != null){
|
return orderName;
|
||||||
String tablistName = server.getTablistNames().get(p);
|
}
|
||||||
if(tablistName != null)
|
|
||||||
return tablistName;
|
@Override
|
||||||
|
public void print(Tablist viewer, boolean slim) {
|
||||||
|
subTablists.forEach(tablist -> {
|
||||||
|
if(withHeaders)
|
||||||
|
viewer.setSlot(gray, "§l" + tablist.name(), 1000);
|
||||||
|
tablist.print(viewer, slim);
|
||||||
|
if(withHeaders)
|
||||||
|
viewer.setSlot(darkGray, "", 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TablistServer implements TablistPart {
|
||||||
|
private static class TablistPlayer {
|
||||||
|
private final ProxiedPlayer player;
|
||||||
|
private final String defaultName;
|
||||||
|
|
||||||
|
private TablistPlayer(ProxiedPlayer player, String defaultName) {
|
||||||
|
this.player = player;
|
||||||
|
this.defaultName = defaultName;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
private final List<TablistPlayer> players = new ArrayList<>();
|
||||||
|
private final ServerInfo info;
|
||||||
|
private final Subserver subserver;
|
||||||
|
|
||||||
StringBuilder st = new StringBuilder();
|
private TablistServer(ServerInfo info, FightInfoPacket packet){
|
||||||
UserGroup group = SteamwarUser.get(p).getUserGroup();
|
this.info = info;
|
||||||
|
subserver = Subserver.getSubserver(info);
|
||||||
|
Collection<ProxiedPlayer> onlinePlayers = info.getPlayers();
|
||||||
|
addPlayers(packet.getBlueName().substring(0, 2), packet.getBluePlayers(), onlinePlayers);
|
||||||
|
addPlayers(packet.getRedName().substring(0, 2), packet.getRedPlayers(), onlinePlayers);
|
||||||
|
addPlayers("§7", packet.getSpectators(), onlinePlayers);
|
||||||
|
}
|
||||||
|
|
||||||
if (group == UserGroup.Member) {
|
private void addPlayers(String prefix, List<Integer> teamPlayers, Collection<ProxiedPlayer> onlinePlayers){
|
||||||
Team team = getTeam(player);
|
teamPlayers.stream().map(SteamwarUser::get).map(
|
||||||
if (team != null && team == getTeam(p)) st.append("§f");
|
user -> onlinePlayers.stream().filter(player -> player.getUniqueId().equals(user.getUuid())).findAny()
|
||||||
else st.append("§7");
|
).filter(Optional::isPresent).map(Optional::get).sorted(
|
||||||
} else {
|
(p1, p2) -> p1.getName().compareToIgnoreCase(p2.getName())
|
||||||
st.append(group.getColorCode());
|
).forEachOrdered(player -> players.add(new TablistPlayer(player, prefix + player.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TablistServer(ServerInfo info) {
|
||||||
|
this.info = info;
|
||||||
|
subserver = Subserver.getSubserver(info);
|
||||||
|
for(ProxiedPlayer player : info.getPlayers()){
|
||||||
|
players.add(new TablistPlayer(player, SteamwarUser.get(player.getUniqueId()).getUserGroup().getColorCode() + player.getName()));
|
||||||
}
|
}
|
||||||
|
players.sort((tp1, tp2) -> tp1.player.getName().compareToIgnoreCase(tp2.player.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
return st.append(p.getName()).toString();
|
private boolean displaySlim(ProxiedPlayer viewer, ProxiedPlayer player){
|
||||||
|
if(subserver != null && subserver.getType() == Servertype.ARENA && info.getPlayers().size() == 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
SteamwarUser user = SteamwarUser.get(player);
|
||||||
|
if(user.getUserGroup() != UserGroup.Member)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return user.getTeam() != 0 && SteamwarUser.get(viewer).getTeam() == user.getTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return 1 + players.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int slimSize(ProxiedPlayer viewer) {
|
||||||
|
if(viewer.getServer().getInfo() == info)
|
||||||
|
return size();
|
||||||
|
|
||||||
|
int size = 1;
|
||||||
|
for(TablistPlayer player : players)
|
||||||
|
size += displaySlim(viewer, player.player) ? 1 : 0;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return info.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print(Tablist viewer, boolean slim) {
|
||||||
|
boolean sameServer = viewer.player.getServer().getInfo() == info;
|
||||||
|
|
||||||
|
SteamwarUser user = SteamwarUser.get(viewer.player.getUniqueId());
|
||||||
|
for(TablistPlayer player : players){
|
||||||
|
if(sameServer || (user.getTeam() != 0 && user.getTeam() == SteamwarUser.get(player.player.getUniqueId()).getTeam()))
|
||||||
|
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), player.defaultName.startsWith("§7") ? "§f" + player.player.getName() : player.defaultName, 1);
|
||||||
|
else if(!slim || displaySlim(viewer.player, player.player))
|
||||||
|
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), player.defaultName, 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren