Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-17 01:23:43 +02:00
dont use uuids for bossbars, use userconnection
Dieser Commit ist enthalten in:
Ursprung
d86ac64ac9
Commit
7b200ad264
@ -1,6 +1,7 @@
|
||||
package us.myles.ViaVersion.api.boss;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -80,13 +81,21 @@ public abstract class BossBar<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the bossbar to a player (uuid)
|
||||
* Show the bossbar to a player (uuid). You can retrieve it later with #getPlayers()
|
||||
*
|
||||
* @param player uuid of the player
|
||||
* @return The BossBar object
|
||||
*/
|
||||
public abstract BossBar addPlayer(UUID player);
|
||||
|
||||
/**
|
||||
* Show the bossbar to a player connection. You may retrieve it later with #getConnections()
|
||||
*
|
||||
* @param conn UserConnection of the connection
|
||||
* @return The BossBar object
|
||||
*/
|
||||
public abstract BossBar addConnection(UserConnection conn);
|
||||
|
||||
/**
|
||||
* add multiple players
|
||||
*
|
||||
@ -112,13 +121,21 @@ public abstract class BossBar<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the bossbar from a player
|
||||
* Removes the bossbar from a player. You shouldn't use this with #addConnection
|
||||
*
|
||||
* @param uuid The platers YYUD
|
||||
* @param uuid The players UUID
|
||||
* @return The BossBar object
|
||||
*/
|
||||
public abstract BossBar removePlayer(UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes the bossbar from a player connection. You shouldn't use this with #addPlayer
|
||||
*
|
||||
* @param conn The UserConnection
|
||||
* @return The BossBar object
|
||||
*/
|
||||
public abstract BossBar removeConnection(UserConnection conn);
|
||||
|
||||
/**
|
||||
* Add flags
|
||||
*
|
||||
@ -142,12 +159,19 @@ public abstract class BossBar<T> {
|
||||
public abstract boolean hasFlag(BossFlag flag);
|
||||
|
||||
/**
|
||||
* Get players
|
||||
* Get players. The storage is different from #getConnections()
|
||||
*
|
||||
* @return UUIDS from players (sorry I lied)
|
||||
*/
|
||||
public abstract Set<UUID> getPlayers();
|
||||
|
||||
/**
|
||||
* Get UserConnections. The storage is different from #getPlayers()
|
||||
*
|
||||
* @return UserConnection from players
|
||||
*/
|
||||
public abstract Set<UserConnection> getConnections();
|
||||
|
||||
/**
|
||||
* Show the bossbar to everyone (In the getPlayer set)
|
||||
*
|
||||
|
@ -12,11 +12,7 @@ import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
private final UUID uuid;
|
||||
@ -25,6 +21,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
private BossColor color;
|
||||
private BossStyle style;
|
||||
private final Set<UUID> players;
|
||||
private final Set<UserConnection> connections;
|
||||
private boolean visible;
|
||||
private final Set<BossFlag> flags;
|
||||
|
||||
@ -38,6 +35,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
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;
|
||||
}
|
||||
@ -91,6 +89,17 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addConnection(UserConnection conn) {
|
||||
if (!connections.contains(conn)) {
|
||||
connections.add(conn);
|
||||
if (visible) {
|
||||
sendPacketConnection(conn, getPacket(CommonBoss.UpdateAction.ADD, conn));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removePlayer(UUID uuid) {
|
||||
if (players.contains(uuid)) {
|
||||
@ -101,6 +110,15 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removeConnection(UserConnection conn) {
|
||||
if (connections.contains(conn)) {
|
||||
connections.remove(conn);
|
||||
sendPacketConnection(conn, getPacket(UpdateAction.REMOVE, conn));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addFlag(BossFlag flag) {
|
||||
Preconditions.checkNotNull(flag);
|
||||
@ -130,6 +148,11 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
return Collections.unmodifiableSet(players);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar show() {
|
||||
setVisible(true);
|
||||
@ -188,6 +211,10 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
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) {
|
||||
@ -202,6 +229,18 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacketConnection(UserConnection conn, PacketWrapper wrapper) {
|
||||
if (conn.getProtocolInfo() == null || conn.getProtocolInfo().getProtocolVersion() >= ProtocolVersion.v1_9.getId()) {
|
||||
connections.remove(conn);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
wrapper.send(Protocol1_9To1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private PacketWrapper getPacket(UpdateAction action, UserConnection connection) {
|
||||
try {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x0C, null, connection); // TODO don't use fixed packet ids for future support
|
||||
|
@ -191,7 +191,6 @@ public class EntityTracker1_9 extends EntityTracker {
|
||||
}
|
||||
}
|
||||
}
|
||||
UUID uuid = getUser().getProtocolInfo().getUuid();
|
||||
// Boss bar
|
||||
if (Via.getConfig().isBossbarPatch()) {
|
||||
if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
|
||||
@ -202,7 +201,7 @@ public class EntityTracker1_9 extends EntityTracker {
|
||||
if (bar == null) {
|
||||
bar = Via.getAPI().createBossBar(title, BossColor.PINK, BossStyle.SOLID);
|
||||
bossBarMap.put(entityId, bar);
|
||||
bar.addPlayer(uuid);
|
||||
bar.addConnection(getUser());
|
||||
bar.show();
|
||||
|
||||
// Send to provider
|
||||
@ -219,7 +218,7 @@ public class EntityTracker1_9 extends EntityTracker {
|
||||
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
|
||||
bar = Via.getAPI().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
|
||||
bossBarMap.put(entityId, bar);
|
||||
bar.addPlayer(uuid);
|
||||
bar.addConnection(getUser());
|
||||
bar.show();
|
||||
// Send to provider
|
||||
Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren