Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-29 01:20:15 +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 io.netty.channel.ChannelFutureListener;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -17,9 +16,12 @@ public class ViaConnectionManager {
|
|||||||
|
|
||||||
public void onLoginSuccess(UserConnection connection) {
|
public void onLoginSuccess(UserConnection connection) {
|
||||||
Objects.requireNonNull(connection, "connection is null!");
|
Objects.requireNonNull(connection, "connection is null!");
|
||||||
UUID id = connection.getProtocolInfo().getUuid();
|
|
||||||
connections.add(connection);
|
connections.add(connection);
|
||||||
|
|
||||||
|
if (isFrontEnd(connection)) {
|
||||||
|
UUID id = connection.getProtocolInfo().getUuid();
|
||||||
clients.put(id, connection);
|
clients.put(id, connection);
|
||||||
|
}
|
||||||
|
|
||||||
if (connection.getChannel() != null) {
|
if (connection.getChannel() != null) {
|
||||||
connection.getChannel().closeFuture().addListener((ChannelFutureListener) future -> onDisconnect(connection));
|
connection.getChannel().closeFuture().addListener((ChannelFutureListener) future -> onDisconnect(connection));
|
||||||
@ -28,10 +30,21 @@ public class ViaConnectionManager {
|
|||||||
|
|
||||||
public void onDisconnect(UserConnection connection) {
|
public void onDisconnect(UserConnection connection) {
|
||||||
Objects.requireNonNull(connection, "connection is null!");
|
Objects.requireNonNull(connection, "connection is null!");
|
||||||
UUID id = connection.getProtocolInfo().getUuid();
|
|
||||||
connections.remove(connection);
|
connections.remove(connection);
|
||||||
|
|
||||||
|
if (isFrontEnd(connection)) {
|
||||||
|
UUID id = connection.getProtocolInfo().getUuid();
|
||||||
clients.remove(id);
|
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
|
* Returns a map containing the UUIDs and frontend UserConnections from players connected to this proxy server
|
||||||
|
@ -8,7 +8,6 @@ import us.myles.ViaVersion.api.boss.BossColor;
|
|||||||
import us.myles.ViaVersion.api.boss.BossFlag;
|
import us.myles.ViaVersion.api.boss.BossFlag;
|
||||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
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> {
|
public abstract class CommonBoss<T> extends BossBar<T> {
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
private final Set<UserConnection> connections;
|
||||||
|
private final Set<BossFlag> flags;
|
||||||
private String title;
|
private String title;
|
||||||
private float health;
|
private float health;
|
||||||
private BossColor color;
|
private BossColor color;
|
||||||
private BossStyle style;
|
private BossStyle style;
|
||||||
private final Set<UserConnection> connections;
|
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
private final Set<BossFlag> flags;
|
|
||||||
|
|
||||||
public CommonBoss(String title, float health, BossColor color, BossStyle style) {
|
public CommonBoss(String title, float health, BossColor color, BossStyle style) {
|
||||||
Preconditions.checkNotNull(title, "Title cannot be null");
|
Preconditions.checkNotNull(title, "Title cannot be null");
|
||||||
@ -83,12 +82,9 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BossBar addConnection(UserConnection conn) {
|
public BossBar addConnection(UserConnection conn) {
|
||||||
if (!connections.contains(conn)) {
|
if (connections.add(conn) && visible) {
|
||||||
connections.add(conn);
|
|
||||||
if (visible) {
|
|
||||||
sendPacketConnection(conn, getPacket(CommonBoss.UpdateAction.ADD, conn));
|
sendPacketConnection(conn, getPacket(CommonBoss.UpdateAction.ADD, conn));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +95,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BossBar removeConnection(UserConnection conn) {
|
public BossBar removeConnection(UserConnection conn) {
|
||||||
if (connections.contains(conn)) {
|
if (connections.remove(conn)) {
|
||||||
connections.remove(conn);
|
|
||||||
sendPacketConnection(conn, getPacket(UpdateAction.REMOVE, conn));
|
sendPacketConnection(conn, getPacket(UpdateAction.REMOVE, conn));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -158,6 +153,13 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
|||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setVisible(boolean value) {
|
||||||
|
if (visible != value) {
|
||||||
|
visible = value;
|
||||||
|
sendPacket(value ? CommonBoss.UpdateAction.ADD : CommonBoss.UpdateAction.REMOVE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return uuid;
|
return uuid;
|
||||||
@ -186,13 +188,6 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
|||||||
return flags;
|
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) {
|
private void sendPacket(UpdateAction action) {
|
||||||
for (UserConnection conn : new ArrayList<>(connections)) {
|
for (UserConnection conn : new ArrayList<>(connections)) {
|
||||||
PacketWrapper wrapper = getPacket(action, conn);
|
PacketWrapper wrapper = getPacket(action, conn);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren