3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Convert map of players to list (may address #833)

Dieser Commit ist enthalten in:
RednedEpic 2020-07-06 20:11:34 -05:00
Ursprung 699402e635
Commit 24f9651cc6
9 geänderte Dateien mit 23 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -47,7 +47,7 @@ public class GeyserSpigotBlockPlaceListener implements Listener {
@EventHandler
public void place(final BlockPlaceEvent event) {
for (GeyserSession session : connector.getPlayers().values()) {
for (GeyserSession session : connector.getPlayers()) {
if (event.getPlayer() == Bukkit.getPlayer(session.getPlayerEntity().getUsername())) {
LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
placeBlockSoundPacket.setSound(SoundEvent.PLACE);

Datei anzeigen

@ -42,7 +42,6 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@ -292,10 +291,10 @@ public class GeyserStandaloneGUI {
// Update player table
playerTableModel.getDataVector().removeAllElements();
for (Map.Entry<InetSocketAddress, GeyserSession> player : GeyserConnector.getInstance().getPlayers().entrySet()) {
for (GeyserSession player : GeyserConnector.getInstance().getPlayers()) {
Vector row = new Vector();
row.add(player.getKey().getHostName());
row.add(player.getValue().getPlayerEntity().getUsername());
row.add(player.getSocketAddress().getHostName());
row.add(player.getPlayerEntity().getUsername());
playerTableModel.addRow(row);
}

Datei anzeigen

@ -59,8 +59,8 @@ import org.geysermc.connector.utils.LocaleUtils;
import java.net.InetSocketAddress;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -76,7 +76,7 @@ public class GeyserConnector {
public static final String NAME = "Geyser";
public static final String VERSION = "DEV"; // A fallback for running in IDEs
private final Map<InetSocketAddress, GeyserSession> players = new HashMap<>();
private final List<GeyserSession> players = new ArrayList<>();
private static GeyserConnector instance;
@ -185,7 +185,7 @@ public class GeyserConnector {
if (players.size() >= 1) {
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.kick.log", players.size()));
for (GeyserSession playerSession : players.values()) {
for (GeyserSession playerSession : players) {
playerSession.disconnect(LanguageUtils.getPlayerLocaleString("geyser.core.shutdown.kick.message", playerSession.getClientData().getLanguageCode()));
}
@ -227,11 +227,11 @@ public class GeyserConnector {
}
public void addPlayer(GeyserSession player) {
players.put(player.getSocketAddress(), player);
players.add(player);
}
public void removePlayer(GeyserSession player) {
players.remove(player.getSocketAddress());
players.remove(player);
}
public static GeyserConnector start(PlatformType platformType, GeyserBootstrap bootstrap) {

Datei anzeigen

@ -47,9 +47,9 @@ public class ListCommand extends GeyserCommand {
public void execute(CommandSender sender, String[] args) {
String message = "";
if (sender instanceof GeyserSession) {
message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", ((GeyserSession) sender).getClientData().getLanguageCode(), connector.getPlayers().size(), connector.getPlayers().values().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", ((GeyserSession) sender).getClientData().getLanguageCode(), connector.getPlayers().size(), connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
} else {
message = LanguageUtils.getLocaleStringLog("geyser.commands.list.message", connector.getPlayers().size(), connector.getPlayers().values().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
message = LanguageUtils.getLocaleStringLog("geyser.commands.list.message", connector.getPlayers().size(), connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
}
sender.sendMessage(message);

Datei anzeigen

@ -59,7 +59,7 @@ public class OffhandCommand extends GeyserCommand {
return;
}
// Needed for Bukkit - sender is not an instance of GeyserSession
for (GeyserSession session : connector.getPlayers().values()) {
for (GeyserSession session : connector.getPlayers()) {
if (sender.getName().equals(session.getPlayerEntity().getUsername())) {
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, new Position(0,0,0),
BlockFace.DOWN);

Datei anzeigen

@ -56,7 +56,7 @@ public class ReloadCommand extends GeyserCommand {
sender.sendMessage(message);
for (GeyserSession session : connector.getPlayers().values()) {
for (GeyserSession session : connector.getPlayers()) {
session.disconnect(LanguageUtils.getPlayerLocaleString("geyser.commands.reload.kick", session.getClientData().getLanguageCode()));
}
connector.reload();

Datei anzeigen

@ -37,7 +37,7 @@ public class FishingHookEntity extends Entity {
public FishingHookEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, ProjectileData data) {
super(entityId, geyserId, entityType, position, motion, rotation);
for (GeyserSession session : GeyserConnector.getInstance().getPlayers().values()) {
for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
Entity entity = session.getEntityCache().getEntityByJavaId(data.getOwnerId());
if (entity == null && session.getPlayerEntity().getEntityId() == data.getOwnerId()) {
entity = session.getPlayerEntity();

Datei anzeigen

@ -108,15 +108,6 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
bedrockServerSession.addDisconnectHandler(disconnectReason -> {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.disconnect", bedrockServerSession.getAddress().getAddress(), disconnectReason));
GeyserSession player = connector.getPlayers().get(bedrockServerSession.getAddress());
if (player != null) {
player.disconnect(disconnectReason.name());
connector.removePlayer(player);
}
});
bedrockServerSession.setPacketCodec(GeyserConnector.BEDROCK_PACKET_CODEC);
}

Datei anzeigen

@ -210,6 +210,13 @@ public class GeyserSession implements CommandSender {
this.loggedIn = false;
this.inventoryCache.getInventories().put(0, inventory);
bedrockServerSession.addDisconnectHandler(disconnectReason -> {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.disconnect", bedrockServerSession.getAddress().getAddress(), disconnectReason));
disconnect(disconnectReason.name());
connector.removePlayer(this);
});
}
public void connect(RemoteServer remoteServer) {
@ -428,7 +435,7 @@ public class GeyserSession implements CommandSender {
downstream.getSession().disconnect(reason);
}
if (upstream != null && !upstream.isClosed()) {
connector.getPlayers().remove(this.upstream.getAddress());
connector.getPlayers().remove(this);
upstream.disconnect(reason);
}
}