3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 17:10:13 +01:00

Use return value from add/remove and add abstract isFrontEnd

Dieser Commit ist enthalten in:
creeper123123321 2020-06-25 11:40:15 -03:00
Ursprung 9df545483c
Commit 1ab0cd07af
2 geänderte Dateien mit 30 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -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);
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,10 +30,21 @@ public class ViaConnectionManager {
public void onDisconnect(UserConnection connection) {
Objects.requireNonNull(connection, "connection is null!");
UUID id = connection.getProtocolInfo().getUuid();
connections.remove(connection);
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;
}
/**
* Returns a map containing the UUIDs and frontend UserConnections from players connected to this proxy server

Datei anzeigen

@ -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,12 +82,9 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override
public BossBar addConnection(UserConnection conn) {
if (!connections.contains(conn)) {
connections.add(conn);
if (visible) {
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);