Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 00:50:13 +01:00
Use return value from add/remove and add abstract isFrontEnd
Dieser Commit ist enthalten in:
Ursprung
9df545483c
Commit
1ab0cd07af
@ -3,7 +3,6 @@ package us.myles.ViaVersion.api.platform;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -17,9 +16,12 @@ public class ViaConnectionManager {
|
||||
|
||||
public void onLoginSuccess(UserConnection connection) {
|
||||
Objects.requireNonNull(connection, "connection is null!");
|
||||
UUID id = connection.getProtocolInfo().getUuid();
|
||||
connections.add(connection);
|
||||
clients.put(id, connection);
|
||||
|
||||
if (isFrontEnd(connection)) {
|
||||
UUID id = connection.getProtocolInfo().getUuid();
|
||||
clients.put(id, connection);
|
||||
}
|
||||
|
||||
if (connection.getChannel() != null) {
|
||||
connection.getChannel().closeFuture().addListener((ChannelFutureListener) future -> onDisconnect(connection));
|
||||
@ -28,9 +30,20 @@ public class ViaConnectionManager {
|
||||
|
||||
public void onDisconnect(UserConnection connection) {
|
||||
Objects.requireNonNull(connection, "connection is null!");
|
||||
UUID id = connection.getProtocolInfo().getUuid();
|
||||
connections.remove(connection);
|
||||
clients.remove(id);
|
||||
|
||||
if (isFrontEnd(connection)) {
|
||||
UUID id = connection.getProtocolInfo().getUuid();
|
||||
clients.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend connections will have the UUID stored. Override this if your platform isn't always frontend.
|
||||
* UUIDs can't be duplicate between frontend connections.
|
||||
*/
|
||||
protected boolean isFrontEnd(UserConnection conn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,6 @@ import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossFlag;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
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;
|
||||
|
||||
@ -17,13 +16,13 @@ import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
private final UUID uuid;
|
||||
private final Set<UserConnection> connections;
|
||||
private final Set<BossFlag> flags;
|
||||
private String title;
|
||||
private float health;
|
||||
private BossColor color;
|
||||
private BossStyle style;
|
||||
private final Set<UserConnection> connections;
|
||||
private boolean visible;
|
||||
private final Set<BossFlag> flags;
|
||||
|
||||
public CommonBoss(String title, float health, BossColor color, BossStyle style) {
|
||||
Preconditions.checkNotNull(title, "Title cannot be null");
|
||||
@ -83,11 +82,8 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
|
||||
@Override
|
||||
public BossBar addConnection(UserConnection conn) {
|
||||
if (!connections.contains(conn)) {
|
||||
connections.add(conn);
|
||||
if (visible) {
|
||||
sendPacketConnection(conn, getPacket(CommonBoss.UpdateAction.ADD, conn));
|
||||
}
|
||||
if (connections.add(conn) && visible) {
|
||||
sendPacketConnection(conn, getPacket(CommonBoss.UpdateAction.ADD, conn));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -99,8 +95,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
|
||||
@Override
|
||||
public BossBar removeConnection(UserConnection conn) {
|
||||
if (connections.contains(conn)) {
|
||||
connections.remove(conn);
|
||||
if (connections.remove(conn)) {
|
||||
sendPacketConnection(conn, getPacket(UpdateAction.REMOVE, conn));
|
||||
}
|
||||
return this;
|
||||
@ -158,6 +153,13 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
return visible;
|
||||
}
|
||||
|
||||
private void setVisible(boolean value) {
|
||||
if (visible != value) {
|
||||
visible = value;
|
||||
sendPacket(value ? CommonBoss.UpdateAction.ADD : CommonBoss.UpdateAction.REMOVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return uuid;
|
||||
@ -186,13 +188,6 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
return flags;
|
||||
}
|
||||
|
||||
private void setVisible(boolean value) {
|
||||
if (visible != value) {
|
||||
visible = value;
|
||||
sendPacket(value ? CommonBoss.UpdateAction.ADD : CommonBoss.UpdateAction.REMOVE);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(UpdateAction action) {
|
||||
for (UserConnection conn : new ArrayList<>(connections)) {
|
||||
PacketWrapper wrapper = getPacket(action, conn);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren