Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 09:00:09 +01:00
Redirect UUID to UserConnection bossbars
Dieser Commit ist enthalten in:
Ursprung
8bd982a412
Commit
3f93bb051d
@ -156,6 +156,10 @@ public class ViaManager {
|
||||
return platform.getConnectionManager().getConnectedClients();
|
||||
}
|
||||
|
||||
public UUID getConnectedClientId(UserConnection conn) {
|
||||
return platform.getConnectionManager().getConnectedClientId(conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ViaConnectionManager#isClientConnected(UUID)
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public abstract class BossBar<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the bossbar to a player (uuid). You can retrieve it later with #getPlayers()
|
||||
* Show the bossbar to a player (uuid).
|
||||
*
|
||||
* @param player uuid of the player
|
||||
* @return The BossBar object
|
||||
@ -89,7 +89,7 @@ public abstract class BossBar<T> {
|
||||
public abstract BossBar addPlayer(UUID player);
|
||||
|
||||
/**
|
||||
* Show the bossbar to a player connection. You may retrieve it later with #getConnections()
|
||||
* Show the bossbar to a player connection.
|
||||
*
|
||||
* @param conn UserConnection of the connection
|
||||
* @return The BossBar object
|
||||
@ -121,7 +121,7 @@ public abstract class BossBar<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the bossbar from a player. You shouldn't use this with #addConnection
|
||||
* Removes the bossbar from a player.
|
||||
*
|
||||
* @param uuid The players UUID
|
||||
* @return The BossBar object
|
||||
@ -129,7 +129,7 @@ public abstract class BossBar<T> {
|
||||
public abstract BossBar removePlayer(UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes the bossbar from a player connection. You shouldn't use this with #addPlayer
|
||||
* Removes the bossbar from a player connection.
|
||||
*
|
||||
* @param conn The UserConnection
|
||||
* @return The BossBar object
|
||||
@ -159,14 +159,14 @@ public abstract class BossBar<T> {
|
||||
public abstract boolean hasFlag(BossFlag flag);
|
||||
|
||||
/**
|
||||
* Get players. The storage is different from #getConnections()
|
||||
* Get players. Only returns UUIDs which are front-end. For all connections, use #getConnections()
|
||||
*
|
||||
* @return UUIDS from players (sorry I lied)
|
||||
*/
|
||||
public abstract Set<UUID> getPlayers();
|
||||
|
||||
/**
|
||||
* Get UserConnections. The storage is different from #getPlayers()
|
||||
* Get UserConnections.
|
||||
*
|
||||
* @return UserConnection from players
|
||||
*/
|
||||
|
@ -57,6 +57,26 @@ public class ViaConnectionManager {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UUID from the frontend connection to this proxy server
|
||||
* Returns null when there isn't a server or frontend id was not found
|
||||
* When ViaVersion is reloaded, this method may not return some players.
|
||||
* May not return ProtocolSupport players.
|
||||
* <p>
|
||||
* Note that connections are removed as soon as their channel is closed,
|
||||
* so avoid using this method during player quits for example.
|
||||
*/
|
||||
@Nullable
|
||||
public UUID getConnectedClientId(UserConnection conn) {
|
||||
if (conn.getProtocolInfo() == null) return null;
|
||||
UUID uuid = conn.getProtocolInfo().getUuid();
|
||||
if (clients.get(uuid).equals(conn)) {
|
||||
// This is frontend
|
||||
return uuid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all UserConnections which are registered
|
||||
* May contain duplicated UUIDs on multiple ProtocolInfo.
|
||||
|
@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
private final UUID uuid;
|
||||
@ -20,7 +21,6 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
private float health;
|
||||
private BossColor color;
|
||||
private BossStyle style;
|
||||
private final Set<UUID> players;
|
||||
private final Set<UserConnection> connections;
|
||||
private boolean visible;
|
||||
private final Set<BossFlag> flags;
|
||||
@ -34,7 +34,6 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
this.health = health;
|
||||
this.color = color == null ? BossColor.PURPLE : color;
|
||||
this.style = style == null ? BossStyle.SOLID : style;
|
||||
this.players = new HashSet<>();
|
||||
this.connections = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
this.flags = new HashSet<>();
|
||||
visible = true;
|
||||
@ -79,14 +78,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
|
||||
@Override
|
||||
public BossBar addPlayer(UUID player) {
|
||||
if (!players.contains(player)) {
|
||||
players.add(player);
|
||||
if (visible) {
|
||||
UserConnection user = Via.getManager().getConnection(player);
|
||||
sendPacket(player, getPacket(CommonBoss.UpdateAction.ADD, user));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
return addConnection(Via.getManager().getConnection(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,12 +94,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
|
||||
@Override
|
||||
public BossBar removePlayer(UUID uuid) {
|
||||
if (players.contains(uuid)) {
|
||||
players.remove(uuid);
|
||||
UserConnection user = Via.getManager().getConnection(uuid);
|
||||
sendPacket(uuid, getPacket(UpdateAction.REMOVE, user));
|
||||
}
|
||||
return this;
|
||||
return removeConnection(Via.getManager().getConnection(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -145,7 +132,8 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return Collections.unmodifiableSet(players);
|
||||
return connections.stream().map(conn -> Via.getManager().getConnectedClientId(conn)).filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -206,31 +194,14 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
}
|
||||
|
||||
private void sendPacket(UpdateAction action) {
|
||||
for (UUID uuid : new ArrayList<>(players)) {
|
||||
UserConnection connection = Via.getManager().getConnection(uuid);
|
||||
PacketWrapper wrapper = getPacket(action, connection);
|
||||
sendPacket(uuid, wrapper);
|
||||
}
|
||||
for (UserConnection conn : new ArrayList<>(connections)) {
|
||||
PacketWrapper wrapper = getPacket(action, conn);
|
||||
sendPacketConnection(conn, wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(UUID uuid, PacketWrapper wrapper) {
|
||||
if (!Via.getAPI().isInjected(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||
players.remove(uuid);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
wrapper.send(Protocol1_9To1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacketConnection(UserConnection conn, PacketWrapper wrapper) {
|
||||
if (conn.getProtocolInfo() == null || conn.getProtocolInfo().getProtocolVersion() < ProtocolVersion.v1_9.getId()) {
|
||||
if (conn.getProtocolInfo() == null || conn.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
connections.remove(conn);
|
||||
return;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren