From ca78bf98513b7902d674d0b2e4f56110bc0303ce Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Sun, 12 Apr 2020 15:37:08 -0300 Subject: [PATCH] Remove portedPlayers field, let platform handle players --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 43 +++++++++++-- .../bukkit/platform/BukkitViaAPI.java | 2 +- .../bukkit/platform/BukkitViaLoader.java | 2 +- .../us/myles/ViaVersion/BungeePlugin.java | 44 +++++++++++-- .../bungee/platform/BungeeViaAPI.java | 2 +- .../java/us/myles/ViaVersion/ViaManager.java | 42 ++++++++----- .../ViaVersion/api/platform/ViaPlatform.java | 17 +++++ .../protocols/base/BaseProtocol1_7.java | 2 +- .../TabCompleteThread.java | 2 +- .../protocol1_9to1_8/ViaIdleThread.java | 2 +- .../us/myles/ViaVersion/SpongePlugin.java | 52 +++++++++++++--- .../sponge/listeners/ClientLeaveListener.java | 2 +- .../sponge/platform/SpongeViaAPI.java | 2 +- .../us/myles/ViaVersion/VelocityPlugin.java | 62 +++++++++++++++++-- .../velocity/platform/VelocityViaAPI.java | 2 +- 15 files changed, 231 insertions(+), 47 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index d42b874a5..1ee6b90e0 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.data.MappingDataLoader; +import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator; @@ -19,15 +20,18 @@ import us.myles.ViaVersion.bukkit.commands.BukkitCommandSender; import us.myles.ViaVersion.bukkit.platform.*; import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.dump.PluginInfo; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.util.GsonUtil; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; -public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { +public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { private static ViaVersionPlugin instance; + + private final Map clients = new ConcurrentHashMap<>(); + private final Set connections = Collections.newSetFromMap(new ConcurrentHashMap<>()); private final BukkitCommandHandler commandHandler; private final BukkitViaConfig conf; private final ViaAPI api = new BukkitViaAPI(this); @@ -279,4 +283,35 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { public static ViaVersionPlugin getInstance() { return instance; } + + @Override + public void onLoginSuccess(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.add(connection); + clients.put(id, connection); + } + + @Override + public void onDisconnect(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.remove(connection); + clients.remove(id); + } + + @Override + public Map getConnectedClients() { + return Collections.unmodifiableMap(clients); + } + + @Override + public UserConnection getConnectedClient(UUID clientIdentifier) { + return clients.get(clientIdentifier); + } + + @Override + public Set getConnections() { + return Collections.unmodifiableSet(connections); + } } diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java index 8ff4ec35d..cf88538a5 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java @@ -108,6 +108,6 @@ public class BukkitViaAPI implements ViaAPI { } public Map getPortedPlayers() { - return Via.getManager().getPortedPlayers(); + return Via.getManager().getConnectedClients(); } } diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index 50d5eba46..7672cfadc 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -71,7 +71,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { registerListener(new Listener() { @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { - Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); + Via.getManager().handleDisconnect(e.getPlayer().getUniqueId()); } }); diff --git a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java index bf8a49f03..cbaf8fe27 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java +++ b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java @@ -22,15 +22,16 @@ import us.myles.ViaVersion.bungee.commands.BungeeCommandSender; import us.myles.ViaVersion.bungee.platform.*; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; import us.myles.ViaVersion.dump.PluginInfo; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.util.GsonUtil; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; public class BungeePlugin extends Plugin implements ViaPlatform, Listener { + private final Map clients = new ConcurrentHashMap<>(); + private final Set connections = Collections.newSetFromMap(new ConcurrentHashMap<>()); private BungeeViaAPI api; private BungeeViaConfig config; private BungeeCommandHandler commandHandler; @@ -184,13 +185,44 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener { return true; } + @Override + public void onLoginSuccess(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.add(connection); + clients.put(id, connection); + } + + @Override + public void onDisconnect(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.remove(connection); + clients.remove(id); + } + + @Override + public Map getConnectedClients() { + return Collections.unmodifiableMap(clients); + } + + @Override + public UserConnection getConnectedClient(UUID clientIdentifier) { + return clients.get(clientIdentifier); + } + + @Override + public Set getConnections() { + return Collections.unmodifiableSet(connections); + } + @EventHandler public void onQuit(PlayerDisconnectEvent e) { - UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId()); + UserConnection userConnection = getConnectedClient(e.getPlayer().getUniqueId()); if (userConnection != null) { // Only remove if the connection is disconnected (eg. relogin) if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) { - Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); + Via.getManager().handleDisconnect(e.getPlayer().getUniqueId()); } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java index 5b779c85f..3ace9afec 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java @@ -79,7 +79,7 @@ public class BungeeViaAPI implements ViaAPI { } public Map getPortedPlayers() { - return Via.getManager().getPortedPlayers(); + return Via.getManager().getConnectedClients(); } /** diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManager.java b/common/src/main/java/us/myles/ViaVersion/ViaManager.java index d3d9fde44..2b971521b 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManager.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManager.java @@ -10,18 +10,16 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.commands.ViaCommandHandler; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread; import us.myles.ViaVersion.update.UpdateUtil; import java.util.Map; +import java.util.Set; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; public class ViaManager { - private final Map portedPlayers = new ConcurrentHashMap<>(); - private final ViaPlatform platform; + private final ViaPlatform platform; private final ViaProviders providers = new ViaProviders(); private boolean debug; // Internals @@ -30,7 +28,7 @@ public class ViaManager { private final ViaPlatformLoader loader; @Builder - public ViaManager(ViaPlatform platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) { + public ViaManager(ViaPlatform platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) { this.platform = platform; this.injector = injector; this.commandHandler = commandHandler; @@ -112,23 +110,35 @@ public class ViaManager { loader.unload(); } - public void addPortedClient(UserConnection info) { - portedPlayers.put(info.get(ProtocolInfo.class).getUuid(), info); + public Set getConnections() { + return platform.getConnections(); } - public void removePortedClient(UUID clientID) { - portedPlayers.remove(clientID); + /** + * @deprecated use getConnectedClients() + */ + @Deprecated + public Map getPortedClients() { + return getConnectedClients(); } - public UserConnection getConnection(UUID playerUUID) { - return portedPlayers.get(playerUUID); + public Map getConnectedClients() { + return platform.getConnectedClients(); } - public Map getPortedPlayers() { - return portedPlayers; + public void handleLoginSuccess(UserConnection info) { + platform.onLoginSuccess(info); } - public ViaPlatform getPlatform() { + public void handleDisconnect(UUID id) { + handleDisconnect(getConnection(id)); + } + + public void handleDisconnect(UserConnection info) { + platform.onDisconnect(info); + } + + public ViaPlatform getPlatform() { return platform; } @@ -155,4 +165,8 @@ public class ViaManager { public ViaPlatformLoader getLoader() { return loader; } + + public UserConnection getConnection(UUID playerUUID) { + return platform.getConnectedClient(playerUUID); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java index b04bb75c7..24a04348e 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java +++ b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java @@ -5,8 +5,11 @@ import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; +import us.myles.ViaVersion.api.data.UserConnection; import java.io.File; +import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.logging.Logger; @@ -166,4 +169,18 @@ public interface ViaPlatform { * @return True if allowed */ boolean isOldClientsAllowed(); + + void onLoginSuccess(UserConnection connection); + + void onDisconnect(UserConnection connection); + + Map getConnectedClients(); + + UserConnection getConnectedClient(UUID clientIdentifier); + + /** + * May contain duplicated UUIDs on multiple ProtocolInfo. + * May contain client-sided connections. + */ + Set getConnections(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java index 8ad74afde..8ccd9f60a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java @@ -133,7 +133,7 @@ public class BaseProtocol1_7 extends Protocol { String username = wrapper.passthrough(Type.STRING); info.setUsername(username); // Add to ported clients - Via.getManager().addPortedClient(wrapper.user()); + Via.getManager().handleLoginSuccess(wrapper.user()); if (info.getPipeline().pipes().size() == 2 && info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_7.class diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java index 2f08b6217..57971b5cd 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java @@ -8,7 +8,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTra public class TabCompleteThread implements Runnable { @Override public void run() { - for (UserConnection info : Via.getManager().getPortedPlayers().values()) { + for (UserConnection info : Via.getManager().getConnections()) { if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) { if (info.getChannel().isOpen()) { info.get(TabCompleteTracker.class).sendPacketToServer(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java index 6dc8edf14..497eaebfa 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java @@ -9,7 +9,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; public class ViaIdleThread implements Runnable { @Override public void run() { - for (UserConnection info : Via.getManager().getPortedPlayers().values()) { + for (UserConnection info : Via.getManager().getConnections()) { ProtocolInfo protocolInfo = info.get(ProtocolInfo.class); if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); diff --git a/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java b/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java index dc5290184..6fcd299cc 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java +++ b/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java @@ -20,9 +20,11 @@ import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.data.MappingDataLoader; +import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.dump.PluginInfo; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.sponge.VersionInfo; import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler; import us.myles.ViaVersion.sponge.commands.SpongeCommandSender; @@ -31,9 +33,8 @@ import us.myles.ViaVersion.sponge.util.LoggerWrapper; import us.myles.ViaVersion.util.GsonUtil; import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; @Plugin(id = "viaversion", @@ -42,7 +43,10 @@ import java.util.logging.Logger; authors = {"_MylesC", "creeper123123321", "Gerrygames", "KennyTV", "Matsv"}, description = "Allow newer Minecraft versions to connect to an older server version." ) -public class SpongePlugin implements ViaPlatform { +public class SpongePlugin implements ViaPlatform { + private final Map clients = new ConcurrentHashMap<>(); + private final Set connections = Collections.newSetFromMap(new ConcurrentHashMap<>()); + @Inject private Game game; @@ -50,8 +54,8 @@ public class SpongePlugin implements ViaPlatform { private PluginContainer container; @Inject - @DefaultConfig(sharedRoot = false) - private File defaultConfig; + @DefaultConfig(sharedRoot = true) + private File spongeConfig; @Getter private SpongeViaAPI api = new SpongeViaAPI(); @@ -66,7 +70,7 @@ public class SpongePlugin implements ViaPlatform { // Setup Logger logger = new LoggerWrapper(container.getLogger()); // Setup Plugin - conf = new SpongeViaConfig(container, defaultConfig.getParentFile()); + conf = new SpongeViaConfig(container, spongeConfig); SpongeCommandHandler commandHandler = new SpongeCommandHandler(); game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge"); logger.info("ViaVersion " + getPluginVersion() + " is now loaded!"); @@ -203,7 +207,7 @@ public class SpongePlugin implements ViaPlatform { @Override public File getDataFolder() { - return defaultConfig.getParentFile(); + return spongeConfig; } @Override @@ -234,4 +238,36 @@ public class SpongePlugin implements ViaPlatform { public boolean isOldClientsAllowed() { return true; } + + + @Override + public void onLoginSuccess(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.add(connection); + clients.put(id, connection); + } + + @Override + public void onDisconnect(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.remove(connection); + clients.remove(id); + } + + @Override + public Map getConnectedClients() { + return Collections.unmodifiableMap(clients); + } + + @Override + public UserConnection getConnectedClient(UUID clientIdentifier) { + return clients.get(clientIdentifier); + } + + @Override + public Set getConnections() { + return Collections.unmodifiableSet(connections); + } } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/ClientLeaveListener.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/ClientLeaveListener.java index 20ef79688..874ab3429 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/ClientLeaveListener.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/ClientLeaveListener.java @@ -7,6 +7,6 @@ import us.myles.ViaVersion.api.Via; public class ClientLeaveListener { @Listener public void onDisconnect(ClientConnectionEvent.Disconnect disconnect) { - Via.getManager().removePortedClient(disconnect.getTargetEntity().getUniqueId()); + Via.getManager().handleDisconnect(disconnect.getTargetEntity().getUniqueId()); } } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java index c23452b80..4f17fb37b 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java @@ -74,6 +74,6 @@ public class SpongeViaAPI implements ViaAPI { } public Map getPortedPlayers() { - return Via.getManager().getPortedPlayers(); + return Via.getManager().getConnectedClients(); } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/VelocityPlugin.java b/velocity/src/main/java/us/myles/ViaVersion/VelocityPlugin.java index 0d59a40f9..05e3b5278 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/VelocityPlugin.java +++ b/velocity/src/main/java/us/myles/ViaVersion/VelocityPlugin.java @@ -23,6 +23,7 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.dump.PluginInfo; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.velocity.VersionInfo; import us.myles.ViaVersion.velocity.command.VelocityCommandHandler; @@ -33,9 +34,8 @@ import us.myles.ViaVersion.velocity.util.LoggerWrapper; import java.io.File; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @Plugin( @@ -46,19 +46,23 @@ import java.util.concurrent.TimeUnit; description = "Allow newer Minecraft versions to connect to an older server version.", url = "https://viaversion.com" ) -@Getter public class VelocityPlugin implements ViaPlatform { + private final Map clients = new ConcurrentHashMap<>(); + private final Set connections = Collections.newSetFromMap(new ConcurrentHashMap<>()); @Inject private ProxyServer proxy; @Inject public static ProxyServer PROXY; @Inject private Logger loggerslf4j; + private java.util.logging.Logger logger; @Inject @DataDirectory private Path configDir; + private VelocityViaAPI api; + private VelocityViaConfig conf; @Subscribe @@ -84,11 +88,11 @@ public class VelocityPlugin implements ViaPlatform { @Subscribe public void onQuit(DisconnectEvent e) { - UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId()); + UserConnection userConnection = getConnectedClient(e.getPlayer().getUniqueId()); if (userConnection != null) { // Only remove if the connection is disconnected (eg. relogin) if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) { - Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); + Via.getManager().handleDisconnect(e.getPlayer().getUniqueId()); } } } @@ -188,6 +192,16 @@ public class VelocityPlugin implements ViaPlatform { return configDir.toFile(); } + @Override + public VelocityViaAPI getApi() { + return api; + } + + @Override + public VelocityViaConfig getConf() { + return conf; + } + @Override public void onReload() { @@ -215,4 +229,40 @@ public class VelocityPlugin implements ViaPlatform { public boolean isOldClientsAllowed() { return true; } + + @Override + public java.util.logging.Logger getLogger() { + return logger; + } + + @Override + public void onLoginSuccess(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.add(connection); + clients.put(id, connection); + } + + @Override + public void onDisconnect(UserConnection connection) { + Objects.requireNonNull(connection, "connection is null!"); + UUID id = connection.get(ProtocolInfo.class).getUuid(); + connections.remove(connection); + clients.remove(id); + } + + @Override + public Map getConnectedClients() { + return Collections.unmodifiableMap(clients); + } + + @Override + public UserConnection getConnectedClient(UUID clientIdentifier) { + return clients.get(clientIdentifier); + } + + @Override + public Set getConnections() { + return Collections.unmodifiableSet(connections); + } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java index dc6674d6d..00b2f1318 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java @@ -80,6 +80,6 @@ public class VelocityViaAPI implements ViaAPI { } public Map getPortedPlayers() { - return Via.getManager().getPortedPlayers(); + return Via.getManager().getConnectedClients(); } }