Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 17:10:13 +01:00
Merge pull request #1719 from creeper123123321/portedplayerschange
Remove portedPlayers field, let platform handle players
Dieser Commit ist enthalten in:
Commit
d9291e6457
@ -12,6 +12,7 @@ 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.platform.TaskId;
|
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.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
|
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
|
||||||
import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler;
|
import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler;
|
||||||
@ -21,13 +22,11 @@ import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
|||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
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.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 ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||||
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 +278,9 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
|||||||
public static ViaVersionPlugin getInstance() {
|
public static ViaVersionPlugin getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViaConnectionManager getConnectionManager() {
|
||||||
|
return connectionManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import us.myles.ViaVersion.boss.ViaBossBar;
|
|||||||
import us.myles.ViaVersion.bukkit.util.ProtocolSupportUtil;
|
import us.myles.ViaVersion.bukkit.util.ProtocolSupportUtil;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -34,9 +33,9 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(UUID uuid) {
|
public int getPlayerVersion(UUID uuid) {
|
||||||
if (!isPorted(uuid))
|
if (!isInjected(uuid))
|
||||||
return getExternalVersion(Bukkit.getPlayer(uuid));
|
return getExternalVersion(Bukkit.getPlayer(uuid));
|
||||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getExternalVersion(Player player) {
|
private int getExternalVersion(Player player) {
|
||||||
@ -48,8 +47,8 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPorted(UUID playerUUID) {
|
public boolean isInjected(UUID playerUUID) {
|
||||||
return getPortedPlayers().containsKey(playerUUID);
|
return Via.getManager().isClientConnected(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,8 +58,8 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||||
UserConnection ci = getPortedPlayers().get(uuid);
|
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||||
ci.sendRawPacket(packet);
|
ci.sendRawPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,12 +69,12 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return new ViaBossBar(title, 1F, color, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return new ViaBossBar(title, health, color, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +105,4 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
|||||||
return plugin.isProtocolSupport();
|
return plugin.isProtocolSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
|
||||||
return Via.getManager().getPortedPlayers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,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());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>bungeecord-api</artifactId>
|
||||||
<version>1.13-SNAPSHOT</version>
|
<version>1.15-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
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.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
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.MappingDataLoader;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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.ViaConnectionManager;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.bungee.commands.BungeeCommand;
|
import us.myles.ViaVersion.bungee.commands.BungeeCommand;
|
||||||
import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler;
|
import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler;
|
||||||
@ -24,16 +26,13 @@ import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
|||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
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.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<ProxiedPlayer>, Listener {
|
||||||
|
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||||
private BungeeViaAPI api;
|
private BungeeViaAPI api;
|
||||||
private BungeeViaConfig config;
|
private BungeeViaConfig config;
|
||||||
private BungeeCommandHandler commandHandler;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
@ -51,7 +50,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
|||||||
|
|
||||||
api = new BungeeViaAPI();
|
api = new BungeeViaAPI();
|
||||||
config = new BungeeViaConfig(getDataFolder());
|
config = new BungeeViaConfig(getDataFolder());
|
||||||
commandHandler = new BungeeCommandHandler();
|
BungeeCommandHandler commandHandler = new BungeeCommandHandler();
|
||||||
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
|
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
|
||||||
|
|
||||||
// Init platform
|
// Init platform
|
||||||
@ -129,13 +128,13 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(UUID uuid, String message) {
|
public void sendMessage(UUID uuid, String message) {
|
||||||
getProxy().getPlayer(uuid).sendMessage(message);
|
getProxy().getPlayer(uuid).sendMessage(TextComponent.fromLegacyText(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean kickPlayer(UUID uuid, String message) {
|
public boolean kickPlayer(UUID uuid, String message) {
|
||||||
if (getProxy().getPlayer(uuid) != null) {
|
if (getProxy().getPlayer(uuid) != null) {
|
||||||
getProxy().getPlayer(uuid).disconnect(message);
|
getProxy().getPlayer(uuid).disconnect(TextComponent.fromLegacyText(message));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -147,7 +146,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViaAPI getApi() {
|
public ViaAPI<ProxiedPlayer> getApi() {
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +171,13 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
|||||||
|
|
||||||
List<PluginInfo> plugins = new ArrayList<>();
|
List<PluginInfo> plugins = new ArrayList<>();
|
||||||
for (Plugin p : ProxyServer.getInstance().getPluginManager().getPlugins())
|
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("plugins", GsonUtil.getGson().toJsonTree(plugins));
|
||||||
platformSpecific.add("servers", GsonUtil.getGson().toJsonTree(ProtocolDetectorService.getDetectedIds()));
|
platformSpecific.add("servers", GsonUtil.getGson().toJsonTree(ProtocolDetectorService.getDetectedIds()));
|
||||||
@ -184,13 +189,18 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViaConnectionManager getConnectionManager() {
|
||||||
|
return connectionManager;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerDisconnectEvent e) {
|
public void onQuit(PlayerDisconnectEvent e) {
|
||||||
UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId());
|
UserConnection userConnection = getConnectionManager().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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
|||||||
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -23,24 +22,21 @@ import java.util.UUID;
|
|||||||
public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(@NonNull ProxiedPlayer player) {
|
public int getPlayerVersion(@NonNull ProxiedPlayer player) {
|
||||||
if (!isPorted(player.getUniqueId()))
|
UserConnection conn = Via.getManager().getConnection(player.getUniqueId());
|
||||||
|
if (conn == null) {
|
||||||
return player.getPendingConnection().getVersion();
|
return player.getPendingConnection().getVersion();
|
||||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
}
|
||||||
|
return conn.get(ProtocolInfo.class).getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(@NonNull UUID uuid) {
|
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||||
if (!isPorted(uuid)) {
|
return getPlayerVersion(ProxyServer.getInstance().getPlayer(uuid));
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
|
||||||
if (player != null) return player.getPendingConnection().getVersion();
|
|
||||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
|
||||||
}
|
|
||||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPorted(UUID playerUUID) {
|
public boolean isInjected(UUID playerUUID) {
|
||||||
return getPortedPlayers().containsKey(playerUUID);
|
return Via.getManager().isClientConnected(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,8 +46,10 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
if (!isInjected(uuid)) {
|
||||||
UserConnection ci = getPortedPlayers().get(uuid);
|
throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||||
|
}
|
||||||
|
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||||
ci.sendRawPacket(packet);
|
ci.sendRawPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,10 +76,6 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
|||||||
return outputSet;
|
return outputSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
|
||||||
return Via.getManager().getPortedPlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces ViaVersion to probe a server
|
* Forces ViaVersion to probe a server
|
||||||
*
|
*
|
||||||
|
@ -10,27 +10,25 @@ 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;
|
|
||||||
// Internals
|
// Internals
|
||||||
private final ViaInjector injector;
|
private final ViaInjector injector;
|
||||||
private final ViaCommandHandler commandHandler;
|
private final ViaCommandHandler commandHandler;
|
||||||
private final ViaPlatformLoader loader;
|
private final ViaPlatformLoader loader;
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
@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,39 @@ 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.getConnectionManager().getConnections();
|
||||||
}
|
|
||||||
|
|
||||||
public void removePortedClient(UUID clientID) {
|
|
||||||
portedPlayers.remove(clientID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserConnection getConnection(UUID playerUUID) {
|
|
||||||
return portedPlayers.get(playerUUID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use getConnectedClients()
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||||
return portedPlayers;
|
return getConnectedClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViaPlatform getPlatform() {
|
public Map<UUID, UserConnection> getConnectedClients() {
|
||||||
|
return platform.getConnectionManager().getConnectedClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClientConnected(UUID player) {
|
||||||
|
return platform.getConnectionManager().isClientConnected(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLoginSuccess(UserConnection info) {
|
||||||
|
platform.getConnectionManager().onLoginSuccess(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleDisconnect(UUID id) {
|
||||||
|
handleDisconnect(getConnection(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleDisconnect(UserConnection info) {
|
||||||
|
platform.getConnectionManager().onDisconnect(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ViaPlatform<?> getPlatform() {
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,4 +169,8 @@ public class ViaManager {
|
|||||||
public ViaPlatformLoader getLoader() {
|
public ViaPlatformLoader getLoader() {
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserConnection getConnection(UUID playerUUID) {
|
||||||
|
return platform.getConnectionManager().getConnectedClient(playerUUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,21 @@ public interface ViaAPI<T> {
|
|||||||
*
|
*
|
||||||
* @param playerUUID UUID of a player
|
* @param playerUUID UUID of a player
|
||||||
* @return true if Via has a cached userconnection for this player
|
* @return true if Via has a cached userconnection for this player
|
||||||
* @deprecated as of 0.9.9, because all players are ported use {@link #getPlayerVersion(UUID)}
|
* @deprecated as of 0.9.9, because all players are ported use {@link #getPlayerVersion(UUID)},
|
||||||
|
* or use {@link #isInjected(UUID)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean isPorted(UUID playerUUID);
|
default boolean isPorted(UUID playerUUID) {
|
||||||
|
return isInjected(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if Via injected into this player connection
|
||||||
|
*
|
||||||
|
* @param playerUUID UUID of a player
|
||||||
|
* @return true if Via has a cached UserConnection for this player
|
||||||
|
*/
|
||||||
|
boolean isInjected(UUID playerUUID);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of the plugin
|
* Get the version of the plugin
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
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 injected 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
|
||||||
|
* When ViaVersion is reloaded, this method may not return some players.
|
||||||
|
* May not contain ProtocolSupport players.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
* When ViaVersion is reloaded, this method may not return some players.
|
||||||
|
* May not return ProtocolSupport players.
|
||||||
|
*/
|
||||||
|
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||||
|
return clients.get(clientIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all UserConnections which are registered
|
||||||
|
* May contain duplicated UUIDs on multiple ProtocolInfo.
|
||||||
|
* May contain frontend, backend and/or client-sided connections.
|
||||||
|
* When ViaVersion is reloaded, this method may not return some players.
|
||||||
|
* May not contain ProtocolSupport players.
|
||||||
|
*/
|
||||||
|
public Set<UserConnection> getConnections() {
|
||||||
|
return Collections.unmodifiableSet(connections);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClientConnected(UUID playerId) {
|
||||||
|
return clients.containsKey(playerId);
|
||||||
|
}
|
||||||
|
}
|
@ -166,4 +166,6 @@ public interface ViaPlatform<T> {
|
|||||||
* @return True if allowed
|
* @return True if allowed
|
||||||
*/
|
*/
|
||||||
boolean isOldClientsAllowed();
|
boolean isOldClientsAllowed();
|
||||||
|
|
||||||
|
ViaConnectionManager getConnectionManager();
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacket(UUID uuid, PacketWrapper wrapper) {
|
private void sendPacket(UUID uuid, PacketWrapper wrapper) {
|
||||||
if (!Via.getAPI().isPorted(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
if (!Via.getAPI().isInjected(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||||
players.remove(uuid);
|
players.remove(uuid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -2,7 +2,6 @@ package us.myles.ViaVersion;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import lombok.Getter;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import org.spongepowered.api.Game;
|
import org.spongepowered.api.Game;
|
||||||
@ -21,6 +20,7 @@ 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.platform.TaskId;
|
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.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
import us.myles.ViaVersion.sponge.VersionInfo;
|
import us.myles.ViaVersion.sponge.VersionInfo;
|
||||||
@ -31,9 +31,7 @@ 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.UUID;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@Plugin(id = "viaversion",
|
@Plugin(id = "viaversion",
|
||||||
@ -42,23 +40,18 @@ 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> {
|
||||||
@Inject
|
@Inject
|
||||||
private Game game;
|
private Game game;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PluginContainer container;
|
private PluginContainer container;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@DefaultConfig(sharedRoot = false)
|
@DefaultConfig(sharedRoot = false)
|
||||||
private File defaultConfig;
|
private File spongeConfig;
|
||||||
|
|
||||||
@Getter
|
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||||
private SpongeViaAPI api = new SpongeViaAPI();
|
private final SpongeViaAPI api = new SpongeViaAPI();
|
||||||
@Getter
|
|
||||||
private SpongeViaConfig conf;
|
private SpongeViaConfig conf;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
@ -66,7 +59,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.getParentFile());
|
||||||
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!");
|
||||||
@ -186,7 +179,7 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean kickPlayer(UUID uuid, String message) {
|
public boolean kickPlayer(UUID uuid, String message) {
|
||||||
return game.getServer().getPlayer(uuid).map(player -> {
|
return game.getServer().getPlayer(uuid).map(player -> {
|
||||||
player.kick(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
|
player.kick(TextSerializers.formattingCode('§').deserialize(message));
|
||||||
return true;
|
return true;
|
||||||
}).orElse(false);
|
}).orElse(false);
|
||||||
}
|
}
|
||||||
@ -203,7 +196,7 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getDataFolder() {
|
public File getDataFolder() {
|
||||||
return defaultConfig.getParentFile();
|
return spongeConfig.getParentFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -234,4 +227,24 @@ public class SpongePlugin implements ViaPlatform {
|
|||||||
public boolean isOldClientsAllowed() {
|
public boolean isOldClientsAllowed() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViaConnectionManager getConnectionManager() {
|
||||||
|
return connectionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpongeViaAPI getApi() {
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpongeViaConfig getConf() {
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
|||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -20,21 +19,19 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(Player player) {
|
public int getPlayerVersion(Player player) {
|
||||||
if (!isPorted(player.getUniqueId()))
|
return getPlayerVersion(player.getUniqueId());
|
||||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
|
||||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(UUID uuid) {
|
public int getPlayerVersion(UUID uuid) {
|
||||||
if (!isPorted(uuid))
|
if (!isInjected(uuid))
|
||||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPorted(UUID playerUUID) {
|
public boolean isInjected(UUID playerUUID) {
|
||||||
return getPortedPlayers().containsKey(playerUUID);
|
return Via.getManager().isClientConnected(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,8 +41,8 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||||
UserConnection ci = getPortedPlayers().get(uuid);
|
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||||
ci.sendRawPacket(packet);
|
ci.sendRawPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +68,4 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
|||||||
|
|
||||||
return outputSet;
|
return outputSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
|
||||||
return Via.getManager().getPortedPlayers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import com.velocitypowered.api.plugin.PluginContainer;
|
|||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import lombok.Getter;
|
|
||||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
@ -21,6 +20,7 @@ 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.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.platform.TaskId;
|
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.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
@ -33,9 +33,7 @@ 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.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Plugin(
|
@Plugin(
|
||||||
@ -46,20 +44,21 @@ 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> {
|
||||||
|
public static ProxyServer PROXY;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ProxyServer proxy;
|
private ProxyServer proxy;
|
||||||
@Inject
|
@Inject
|
||||||
public static ProxyServer PROXY;
|
|
||||||
@Inject
|
|
||||||
private Logger loggerslf4j;
|
private Logger loggerslf4j;
|
||||||
private java.util.logging.Logger logger;
|
|
||||||
@Inject
|
@Inject
|
||||||
@DataDirectory
|
@DataDirectory
|
||||||
private Path configDir;
|
private Path configDir;
|
||||||
|
|
||||||
private VelocityViaAPI api;
|
private VelocityViaAPI api;
|
||||||
|
private java.util.logging.Logger logger;
|
||||||
private VelocityViaConfig conf;
|
private VelocityViaConfig conf;
|
||||||
|
private ViaConnectionManager connectionManager;
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInit(ProxyInitializeEvent e) {
|
public void onProxyInit(ProxyInitializeEvent e) {
|
||||||
@ -69,6 +68,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
|||||||
api = new VelocityViaAPI();
|
api = new VelocityViaAPI();
|
||||||
conf = new VelocityViaConfig(configDir.toFile());
|
conf = new VelocityViaConfig(configDir.toFile());
|
||||||
logger = new LoggerWrapper(loggerslf4j);
|
logger = new LoggerWrapper(loggerslf4j);
|
||||||
|
connectionManager = new ViaConnectionManager();
|
||||||
Via.init(ViaManager.builder()
|
Via.init(ViaManager.builder()
|
||||||
.platform(this)
|
.platform(this)
|
||||||
.commandHandler(commandHandler)
|
.commandHandler(commandHandler)
|
||||||
@ -84,11 +84,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 = connectionManager.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 +188,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 +225,14 @@ 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 ViaConnectionManager getConnectionManager() {
|
||||||
|
return connectionManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package us.myles.ViaVersion.velocity.platform;
|
package us.myles.ViaVersion.velocity.platform;
|
||||||
|
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
|
||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.VelocityPlugin;
|
import us.myles.ViaVersion.VelocityPlugin;
|
||||||
@ -14,7 +12,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
|||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -22,25 +20,20 @@ import java.util.UUID;
|
|||||||
public class VelocityViaAPI implements ViaAPI<Player> {
|
public class VelocityViaAPI implements ViaAPI<Player> {
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(Player player) {
|
public int getPlayerVersion(Player player) {
|
||||||
if (!isPorted(player.getUniqueId()))
|
if (!isInjected(player.getUniqueId()))
|
||||||
return player.getProtocolVersion().getProtocol();
|
return player.getProtocolVersion().getProtocol();
|
||||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
return Via.getManager().getConnection(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(UUID uuid) {
|
public int getPlayerVersion(UUID uuid) {
|
||||||
if (!isPorted(uuid)) {
|
return getPlayerVersion(VelocityPlugin.PROXY.getPlayer(uuid).orElseThrow(NoSuchElementException::new));
|
||||||
return VelocityPlugin.PROXY.getPlayer(uuid)
|
|
||||||
.map(InboundConnection::getProtocolVersion)
|
|
||||||
.map(ProtocolVersion::getProtocol)
|
|
||||||
.orElse(ProtocolRegistry.SERVER_PROTOCOL);
|
|
||||||
}
|
|
||||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPorted(UUID playerUUID) {
|
public boolean isInjected(UUID playerUUID) {
|
||||||
return getPortedPlayers().containsKey(playerUUID);
|
return Via.getManager().isClientConnected(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,8 +43,8 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||||
UserConnection ci = getPortedPlayers().get(uuid);
|
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||||
ci.sendRawPacket(packet);
|
ci.sendRawPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +71,4 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
|||||||
return outputSet;
|
return outputSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
|
||||||
return Via.getManager().getPortedPlayers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren