Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Make getPortedPlayers() private, update bungee-api, remove some lombok usage, create ViaConnectionManager
Dieser Commit ist enthalten in:
Ursprung
ca78bf9851
Commit
a105c5cb11
@ -11,8 +11,8 @@ 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.ViaConnectionManager;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
|
||||
import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler;
|
||||
@ -20,18 +20,13 @@ 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.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player> {
|
||||
|
||||
private static ViaVersionPlugin instance;
|
||||
|
||||
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||
private final BukkitCommandHandler commandHandler;
|
||||
private final BukkitViaConfig conf;
|
||||
private final ViaAPI<Player> api = new BukkitViaAPI(this);
|
||||
@ -285,33 +280,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
}
|
||||
|
||||
@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<UUID, UserConnection> getConnectedClients() {
|
||||
return Collections.unmodifiableMap(clients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
public ViaConnectionManager getConnectionManager() {
|
||||
return connectionManager;
|
||||
}
|
||||
}
|
||||
|
@ -71,12 +71,12 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar createBossBar(String title, BossColor color, BossStyle style) {
|
||||
public BossBar<Player> createBossBar(String title, BossColor color, BossStyle style) {
|
||||
return new ViaBossBar(title, 1F, color, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) {
|
||||
public BossBar<Player> createBossBar(String title, float health, BossColor color, BossStyle style) {
|
||||
return new ViaBossBar(title, health, color, style);
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
return plugin.isProtocolSupport();
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.13-SNAPSHOT</version>
|
||||
<version>1.15-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
@ -15,6 +16,7 @@ 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.ViaConnectionManager;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.bungee.commands.BungeeCommand;
|
||||
import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler;
|
||||
@ -22,19 +24,15 @@ 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.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>, Listener {
|
||||
private BungeeViaAPI api;
|
||||
private BungeeViaConfig config;
|
||||
private BungeeCommandHandler commandHandler;
|
||||
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -52,7 +50,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
|
||||
api = new BungeeViaAPI();
|
||||
config = new BungeeViaConfig(getDataFolder());
|
||||
commandHandler = new BungeeCommandHandler();
|
||||
BungeeCommandHandler commandHandler = new BungeeCommandHandler();
|
||||
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
|
||||
|
||||
// Init platform
|
||||
@ -130,13 +128,13 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
|
||||
@Override
|
||||
public void sendMessage(UUID uuid, String message) {
|
||||
getProxy().getPlayer(uuid).sendMessage(message);
|
||||
getProxy().getPlayer(uuid).sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean kickPlayer(UUID uuid, String message) {
|
||||
if (getProxy().getPlayer(uuid) != null) {
|
||||
getProxy().getPlayer(uuid).disconnect(message);
|
||||
getProxy().getPlayer(uuid).disconnect(TextComponent.fromLegacyText(message));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -148,7 +146,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaAPI getApi() {
|
||||
public ViaAPI<ProxiedPlayer> getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
@ -173,7 +171,13 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
|
||||
List<PluginInfo> plugins = new ArrayList<>();
|
||||
for (Plugin p : ProxyServer.getInstance().getPluginManager().getPlugins())
|
||||
plugins.add(new PluginInfo(true, p.getDescription().getName(), p.getDescription().getVersion(), p.getDescription().getMain(), Arrays.asList(p.getDescription().getAuthor())));
|
||||
plugins.add(new PluginInfo(
|
||||
true,
|
||||
p.getDescription().getName(),
|
||||
p.getDescription().getVersion(),
|
||||
p.getDescription().getMain(),
|
||||
Collections.singletonList(p.getDescription().getAuthor())
|
||||
));
|
||||
|
||||
platformSpecific.add("plugins", GsonUtil.getGson().toJsonTree(plugins));
|
||||
platformSpecific.add("servers", GsonUtil.getGson().toJsonTree(ProtocolDetectorService.getDetectedIds()));
|
||||
@ -186,39 +190,13 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
}
|
||||
|
||||
@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<UUID, UserConnection> getConnectedClients() {
|
||||
return Collections.unmodifiableMap(clients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
public ViaConnectionManager getConnectionManager() {
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerDisconnectEvent e) {
|
||||
UserConnection userConnection = getConnectedClient(e.getPlayer().getUniqueId());
|
||||
UserConnection userConnection = getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
|
||||
if (userConnection != null) {
|
||||
// Only remove if the connection is disconnected (eg. relogin)
|
||||
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
|
||||
|
@ -78,7 +78,7 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ public class ViaManager {
|
||||
}
|
||||
|
||||
public Set<UserConnection> getConnections() {
|
||||
return platform.getConnections();
|
||||
return platform.getConnectionManager().getConnections();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,11 +123,11 @@ public class ViaManager {
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getConnectedClients() {
|
||||
return platform.getConnectedClients();
|
||||
return platform.getConnectionManager().getConnectedClients();
|
||||
}
|
||||
|
||||
public void handleLoginSuccess(UserConnection info) {
|
||||
platform.onLoginSuccess(info);
|
||||
platform.getConnectionManager().onLoginSuccess(info);
|
||||
}
|
||||
|
||||
public void handleDisconnect(UUID id) {
|
||||
@ -135,7 +135,7 @@ public class ViaManager {
|
||||
}
|
||||
|
||||
public void handleDisconnect(UserConnection info) {
|
||||
platform.onDisconnect(info);
|
||||
platform.getConnectionManager().onDisconnect(info);
|
||||
}
|
||||
|
||||
public ViaPlatform<?> getPlatform() {
|
||||
@ -167,6 +167,6 @@ public class ViaManager {
|
||||
}
|
||||
|
||||
public UserConnection getConnection(UUID playerUUID) {
|
||||
return platform.getConnectedClient(playerUUID);
|
||||
return platform.getConnectionManager().getConnectedClient(playerUUID);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
package us.myles.ViaVersion.api.platform;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Handles UserConnections
|
||||
*/
|
||||
public class ViaConnectionManager {
|
||||
protected final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||
protected final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void onDisconnect(UserConnection connection) {
|
||||
Objects.requireNonNull(connection, "connection is null!");
|
||||
UUID id = connection.get(ProtocolInfo.class).getUuid();
|
||||
connections.remove(connection);
|
||||
clients.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map containing the UUIDs and frontend UserConnections from players connected to this proxy server
|
||||
* Returns empty list when there isn't a server
|
||||
*/
|
||||
public Map<UUID, UserConnection> getConnectedClients() {
|
||||
return Collections.unmodifiableMap(clients);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the frontend UserConnection from the player connected to this proxy server
|
||||
* Returns null when there isn't a server or connection was not found
|
||||
*/
|
||||
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all UserConnections which are active
|
||||
* May contain duplicated UUIDs on multiple ProtocolInfo.
|
||||
* May contain frontend, backend and/or client-sided connections.
|
||||
*/
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
}
|
||||
}
|
@ -5,11 +5,8 @@ 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;
|
||||
|
||||
@ -170,17 +167,5 @@ public interface ViaPlatform<T> {
|
||||
*/
|
||||
boolean isOldClientsAllowed();
|
||||
|
||||
void onLoginSuccess(UserConnection connection);
|
||||
|
||||
void onDisconnect(UserConnection connection);
|
||||
|
||||
Map<UUID, UserConnection> getConnectedClients();
|
||||
|
||||
UserConnection getConnectedClient(UUID clientIdentifier);
|
||||
|
||||
/**
|
||||
* May contain duplicated UUIDs on multiple ProtocolInfo.
|
||||
* May contain client-sided connections.
|
||||
*/
|
||||
Set<UserConnection> getConnections();
|
||||
ViaConnectionManager getConnectionManager();
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package us.myles.ViaVersion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.spongepowered.api.Game;
|
||||
@ -20,11 +19,10 @@ 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.ViaConnectionManager;
|
||||
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;
|
||||
@ -34,7 +32,6 @@ import us.myles.ViaVersion.util.GsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Plugin(id = "viaversion",
|
||||
@ -44,25 +41,17 @@ import java.util.logging.Logger;
|
||||
description = "Allow newer Minecraft versions to connect to an older server version."
|
||||
)
|
||||
public class SpongePlugin implements ViaPlatform<Player> {
|
||||
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
|
||||
@Inject
|
||||
private Game game;
|
||||
|
||||
@Inject
|
||||
private PluginContainer container;
|
||||
|
||||
@Inject
|
||||
@DefaultConfig(sharedRoot = true)
|
||||
private File spongeConfig;
|
||||
|
||||
@Getter
|
||||
private SpongeViaAPI api = new SpongeViaAPI();
|
||||
@Getter
|
||||
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||
private final SpongeViaAPI api = new SpongeViaAPI();
|
||||
private SpongeViaConfig conf;
|
||||
|
||||
@Getter
|
||||
private Logger logger;
|
||||
|
||||
@Listener
|
||||
@ -190,7 +179,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
@Override
|
||||
public boolean kickPlayer(UUID uuid, String message) {
|
||||
return game.getServer().getPlayer(uuid).map(player -> {
|
||||
player.kick(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
|
||||
player.kick(TextSerializers.formattingCode('§').deserialize(message));
|
||||
return true;
|
||||
}).orElse(false);
|
||||
}
|
||||
@ -239,35 +228,23 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
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);
|
||||
public ViaConnectionManager getConnectionManager() {
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
@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);
|
||||
public SpongeViaAPI getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, UserConnection> getConnectedClients() {
|
||||
return Collections.unmodifiableMap(clients);
|
||||
public SpongeViaConfig getConf() {
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import lombok.Getter;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
@ -21,9 +20,9 @@ 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.ViaConnectionManager;
|
||||
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;
|
||||
@ -35,7 +34,6 @@ import us.myles.ViaVersion.velocity.util.LoggerWrapper;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Plugin(
|
||||
@ -47,23 +45,20 @@ import java.util.concurrent.TimeUnit;
|
||||
url = "https://viaversion.com"
|
||||
)
|
||||
public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
public static ProxyServer PROXY;
|
||||
|
||||
@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 java.util.logging.Logger logger;
|
||||
private VelocityViaConfig conf;
|
||||
private ViaConnectionManager connectionManager;
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInit(ProxyInitializeEvent e) {
|
||||
@ -73,6 +68,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
api = new VelocityViaAPI();
|
||||
conf = new VelocityViaConfig(configDir.toFile());
|
||||
logger = new LoggerWrapper(loggerslf4j);
|
||||
connectionManager = new ViaConnectionManager();
|
||||
Via.init(ViaManager.builder()
|
||||
.platform(this)
|
||||
.commandHandler(commandHandler)
|
||||
@ -88,7 +84,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
|
||||
@Subscribe
|
||||
public void onQuit(DisconnectEvent e) {
|
||||
UserConnection userConnection = getConnectedClient(e.getPlayer().getUniqueId());
|
||||
UserConnection userConnection = connectionManager.getConnectedClient(e.getPlayer().getUniqueId());
|
||||
if (userConnection != null) {
|
||||
// Only remove if the connection is disconnected (eg. relogin)
|
||||
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
|
||||
@ -236,33 +232,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@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<UUID, UserConnection> getConnectedClients() {
|
||||
return Collections.unmodifiableMap(clients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
public ViaConnectionManager getConnectionManager() {
|
||||
return connectionManager;
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren