Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Remove portedPlayers field, let platform handle players
Dieser Commit ist enthalten in:
Ursprung
d7027cc0e3
Commit
ca78bf9851
@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.ViaAPI;
|
|||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
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.TaskId;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
|
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.platform.*;
|
||||||
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player> {
|
||||||
|
|
||||||
private static ViaVersionPlugin instance;
|
private static ViaVersionPlugin instance;
|
||||||
|
|
||||||
|
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||||
|
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
private final BukkitCommandHandler commandHandler;
|
private final BukkitCommandHandler commandHandler;
|
||||||
private final BukkitViaConfig conf;
|
private final BukkitViaConfig conf;
|
||||||
private final ViaAPI<Player> api = new BukkitViaAPI(this);
|
private final ViaAPI<Player> api = new BukkitViaAPI(this);
|
||||||
@ -279,4 +283,35 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
|||||||
public static ViaVersionPlugin getInstance() {
|
public static ViaVersionPlugin getInstance() {
|
||||||
return instance;
|
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<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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,6 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||||
return Via.getManager().getPortedPlayers();
|
return Via.getManager().getConnectedClients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
registerListener(new Listener() {
|
registerListener(new Listener() {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
Via.getManager().removePortedClient(e.getPlayer().getUniqueId());
|
Via.getManager().handleDisconnect(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -22,15 +22,16 @@ import us.myles.ViaVersion.bungee.commands.BungeeCommandSender;
|
|||||||
import us.myles.ViaVersion.bungee.platform.*;
|
import us.myles.ViaVersion.bungee.platform.*;
|
||||||
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
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<>());
|
||||||
private BungeeViaAPI api;
|
private BungeeViaAPI api;
|
||||||
private BungeeViaConfig config;
|
private BungeeViaConfig config;
|
||||||
private BungeeCommandHandler commandHandler;
|
private BungeeCommandHandler commandHandler;
|
||||||
@ -184,13 +185,44 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
|||||||
return true;
|
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<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);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerDisconnectEvent e) {
|
public void onQuit(PlayerDisconnectEvent e) {
|
||||||
UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId());
|
UserConnection userConnection = getConnectedClient(e.getPlayer().getUniqueId());
|
||||||
if (userConnection != null) {
|
if (userConnection != null) {
|
||||||
// Only remove if the connection is disconnected (eg. relogin)
|
// Only remove if the connection is disconnected (eg. relogin)
|
||||||
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
|
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
|
||||||
Via.getManager().removePortedClient(e.getPlayer().getUniqueId());
|
Via.getManager().handleDisconnect(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||||
return Via.getManager().getPortedPlayers();
|
return Via.getManager().getConnectedClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
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_13to1_12_2.TabCompleteThread;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
||||||
import us.myles.ViaVersion.update.UpdateUtil;
|
import us.myles.ViaVersion.update.UpdateUtil;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class ViaManager {
|
public class ViaManager {
|
||||||
private final Map<UUID, UserConnection> portedPlayers = new ConcurrentHashMap<>();
|
private final ViaPlatform<?> platform;
|
||||||
private final ViaPlatform platform;
|
|
||||||
private final ViaProviders providers = new ViaProviders();
|
private final ViaProviders providers = new ViaProviders();
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
// Internals
|
// Internals
|
||||||
@ -30,7 +28,7 @@ public class ViaManager {
|
|||||||
private final ViaPlatformLoader loader;
|
private final ViaPlatformLoader loader;
|
||||||
|
|
||||||
@Builder
|
@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.platform = platform;
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.commandHandler = commandHandler;
|
this.commandHandler = commandHandler;
|
||||||
@ -112,23 +110,35 @@ public class ViaManager {
|
|||||||
loader.unload();
|
loader.unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPortedClient(UserConnection info) {
|
public Set<UserConnection> getConnections() {
|
||||||
portedPlayers.put(info.get(ProtocolInfo.class).getUuid(), info);
|
return platform.getConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePortedClient(UUID clientID) {
|
/**
|
||||||
portedPlayers.remove(clientID);
|
* @deprecated use getConnectedClients()
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public Map<UUID, UserConnection> getPortedClients() {
|
||||||
|
return getConnectedClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserConnection getConnection(UUID playerUUID) {
|
public Map<UUID, UserConnection> getConnectedClients() {
|
||||||
return portedPlayers.get(playerUUID);
|
return platform.getConnectedClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
public void handleLoginSuccess(UserConnection info) {
|
||||||
return portedPlayers;
|
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;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,4 +165,8 @@ public class ViaManager {
|
|||||||
public ViaPlatformLoader getLoader() {
|
public ViaPlatformLoader getLoader() {
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserConnection getConnection(UUID playerUUID) {
|
||||||
|
return platform.getConnectedClient(playerUUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,11 @@ import us.myles.ViaVersion.api.ViaAPI;
|
|||||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -166,4 +169,18 @@ public interface ViaPlatform<T> {
|
|||||||
* @return True if allowed
|
* @return True if allowed
|
||||||
*/
|
*/
|
||||||
boolean isOldClientsAllowed();
|
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();
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class BaseProtocol1_7 extends Protocol {
|
|||||||
String username = wrapper.passthrough(Type.STRING);
|
String username = wrapper.passthrough(Type.STRING);
|
||||||
info.setUsername(username);
|
info.setUsername(username);
|
||||||
// Add to ported clients
|
// Add to ported clients
|
||||||
Via.getManager().addPortedClient(wrapper.user());
|
Via.getManager().handleLoginSuccess(wrapper.user());
|
||||||
|
|
||||||
if (info.getPipeline().pipes().size() == 2
|
if (info.getPipeline().pipes().size() == 2
|
||||||
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_7.class
|
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_7.class
|
||||||
|
@ -8,7 +8,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTra
|
|||||||
public class TabCompleteThread implements Runnable {
|
public class TabCompleteThread implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) {
|
||||||
if (info.getChannel().isOpen()) {
|
if (info.getChannel().isOpen()) {
|
||||||
info.get(TabCompleteTracker.class).sendPacketToServer();
|
info.get(TabCompleteTracker.class).sendPacketToServer();
|
||||||
|
@ -9,7 +9,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
|||||||
public class ViaIdleThread implements Runnable {
|
public class ViaIdleThread implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
|
for (UserConnection info : Via.getManager().getConnections()) {
|
||||||
ProtocolInfo protocolInfo = info.get(ProtocolInfo.class);
|
ProtocolInfo protocolInfo = info.get(ProtocolInfo.class);
|
||||||
if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
|
if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||||
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
|
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
|
||||||
|
@ -20,9 +20,11 @@ import us.myles.ViaVersion.api.Via;
|
|||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
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.TaskId;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.sponge.VersionInfo;
|
import us.myles.ViaVersion.sponge.VersionInfo;
|
||||||
import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler;
|
import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler;
|
||||||
import us.myles.ViaVersion.sponge.commands.SpongeCommandSender;
|
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 us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@Plugin(id = "viaversion",
|
@Plugin(id = "viaversion",
|
||||||
@ -42,7 +43,10 @@ import java.util.logging.Logger;
|
|||||||
authors = {"_MylesC", "creeper123123321", "Gerrygames", "KennyTV", "Matsv"},
|
authors = {"_MylesC", "creeper123123321", "Gerrygames", "KennyTV", "Matsv"},
|
||||||
description = "Allow newer Minecraft versions to connect to an older server version."
|
description = "Allow newer Minecraft versions to connect to an older server version."
|
||||||
)
|
)
|
||||||
public class SpongePlugin implements ViaPlatform {
|
public class SpongePlugin implements ViaPlatform<Player> {
|
||||||
|
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||||
|
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Game game;
|
private Game game;
|
||||||
|
|
||||||
@ -50,8 +54,8 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
private PluginContainer container;
|
private PluginContainer container;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@DefaultConfig(sharedRoot = false)
|
@DefaultConfig(sharedRoot = true)
|
||||||
private File defaultConfig;
|
private File spongeConfig;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private SpongeViaAPI api = new SpongeViaAPI();
|
private SpongeViaAPI api = new SpongeViaAPI();
|
||||||
@ -66,7 +70,7 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
// Setup Logger
|
// Setup Logger
|
||||||
logger = new LoggerWrapper(container.getLogger());
|
logger = new LoggerWrapper(container.getLogger());
|
||||||
// Setup Plugin
|
// Setup Plugin
|
||||||
conf = new SpongeViaConfig(container, defaultConfig.getParentFile());
|
conf = new SpongeViaConfig(container, spongeConfig);
|
||||||
SpongeCommandHandler commandHandler = new SpongeCommandHandler();
|
SpongeCommandHandler commandHandler = new SpongeCommandHandler();
|
||||||
game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
|
game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
|
||||||
logger.info("ViaVersion " + getPluginVersion() + " is now loaded!");
|
logger.info("ViaVersion " + getPluginVersion() + " is now loaded!");
|
||||||
@ -203,7 +207,7 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getDataFolder() {
|
public File getDataFolder() {
|
||||||
return defaultConfig.getParentFile();
|
return spongeConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -234,4 +238,36 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
public boolean isOldClientsAllowed() {
|
public boolean isOldClientsAllowed() {
|
||||||
return true;
|
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<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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ import us.myles.ViaVersion.api.Via;
|
|||||||
public class ClientLeaveListener {
|
public class ClientLeaveListener {
|
||||||
@Listener
|
@Listener
|
||||||
public void onDisconnect(ClientConnectionEvent.Disconnect disconnect) {
|
public void onDisconnect(ClientConnectionEvent.Disconnect disconnect) {
|
||||||
Via.getManager().removePortedClient(disconnect.getTargetEntity().getUniqueId());
|
Via.getManager().handleDisconnect(disconnect.getTargetEntity().getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,6 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||||
return Via.getManager().getPortedPlayers();
|
return Via.getManager().getConnectedClients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
|||||||
import us.myles.ViaVersion.api.platform.TaskId;
|
import us.myles.ViaVersion.api.platform.TaskId;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
import us.myles.ViaVersion.velocity.VersionInfo;
|
import us.myles.ViaVersion.velocity.VersionInfo;
|
||||||
import us.myles.ViaVersion.velocity.command.VelocityCommandHandler;
|
import us.myles.ViaVersion.velocity.command.VelocityCommandHandler;
|
||||||
@ -33,9 +34,8 @@ import us.myles.ViaVersion.velocity.util.LoggerWrapper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Plugin(
|
@Plugin(
|
||||||
@ -46,19 +46,23 @@ import java.util.concurrent.TimeUnit;
|
|||||||
description = "Allow newer Minecraft versions to connect to an older server version.",
|
description = "Allow newer Minecraft versions to connect to an older server version.",
|
||||||
url = "https://viaversion.com"
|
url = "https://viaversion.com"
|
||||||
)
|
)
|
||||||
@Getter
|
|
||||||
public class VelocityPlugin implements ViaPlatform<Player> {
|
public class VelocityPlugin implements ViaPlatform<Player> {
|
||||||
|
private final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||||
|
private final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
@Inject
|
@Inject
|
||||||
private ProxyServer proxy;
|
private ProxyServer proxy;
|
||||||
@Inject
|
@Inject
|
||||||
public static ProxyServer PROXY;
|
public static ProxyServer PROXY;
|
||||||
@Inject
|
@Inject
|
||||||
private Logger loggerslf4j;
|
private Logger loggerslf4j;
|
||||||
|
|
||||||
private java.util.logging.Logger logger;
|
private java.util.logging.Logger logger;
|
||||||
@Inject
|
@Inject
|
||||||
@DataDirectory
|
@DataDirectory
|
||||||
private Path configDir;
|
private Path configDir;
|
||||||
|
|
||||||
private VelocityViaAPI api;
|
private VelocityViaAPI api;
|
||||||
|
|
||||||
private VelocityViaConfig conf;
|
private VelocityViaConfig conf;
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -84,11 +88,11 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onQuit(DisconnectEvent e) {
|
public void onQuit(DisconnectEvent e) {
|
||||||
UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId());
|
UserConnection userConnection = getConnectedClient(e.getPlayer().getUniqueId());
|
||||||
if (userConnection != null) {
|
if (userConnection != null) {
|
||||||
// Only remove if the connection is disconnected (eg. relogin)
|
// Only remove if the connection is disconnected (eg. relogin)
|
||||||
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
|
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<Player> {
|
|||||||
return configDir.toFile();
|
return configDir.toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VelocityViaAPI getApi() {
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VelocityViaConfig getConf() {
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReload() {
|
public void onReload() {
|
||||||
|
|
||||||
@ -215,4 +229,40 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
|||||||
public boolean isOldClientsAllowed() {
|
public boolean isOldClientsAllowed() {
|
||||||
return true;
|
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<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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,6 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||||
return Via.getManager().getPortedPlayers();
|
return Via.getManager().getConnectedClients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren