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.data.MappingDataLoader;
|
||||
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;
|
||||
@ -21,13 +22,11 @@ import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
||||
import java.util.*;
|
||||
|
||||
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player> {
|
||||
private static ViaVersionPlugin instance;
|
||||
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
|
||||
private final BukkitCommandHandler commandHandler;
|
||||
private final BukkitViaConfig conf;
|
||||
private final ViaAPI<Player> api = new BukkitViaAPI(this);
|
||||
@ -279,4 +278,9 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
||||
public static ViaVersionPlugin getInstance() {
|
||||
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.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -34,9 +33,9 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
if (!isPorted(uuid))
|
||||
if (!isInjected(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) {
|
||||
@ -48,8 +47,8 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,8 +58,8 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -70,12 +69,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);
|
||||
}
|
||||
|
||||
@ -106,7 +105,4 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
return plugin.isProtocolSupport();
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getPortedPlayers();
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
registerListener(new Listener() {
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
Via.getManager().removePortedClient(e.getPlayer().getUniqueId());
|
||||
Via.getManager().handleDisconnect(e.getPlayer().getUniqueId());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
@ -24,16 +26,13 @@ import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.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 BungeeViaConfig config;
|
||||
private BungeeCommandHandler commandHandler;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -51,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
|
||||
@ -129,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;
|
||||
@ -147,7 +146,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaAPI getApi() {
|
||||
public ViaAPI<ProxiedPlayer> getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
@ -172,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()));
|
||||
@ -184,13 +189,18 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaConnectionManager getConnectionManager() {
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerDisconnectEvent e) {
|
||||
UserConnection userConnection = Via.getManager().getPortedPlayers().get(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()) {
|
||||
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.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -23,24 +22,21 @@ import java.util.UUID;
|
||||
public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
@Override
|
||||
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 getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
return conn.get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||
if (!isPorted(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();
|
||||
return getPlayerVersion(ProxyServer.getInstance().getPlayer(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,8 +46,10 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) {
|
||||
throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
}
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -78,10 +76,6 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getPortedPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.ProtocolVersion;
|
||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
||||
import us.myles.ViaVersion.update.UpdateUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ViaManager {
|
||||
private final Map<UUID, UserConnection> portedPlayers = new ConcurrentHashMap<>();
|
||||
private final ViaPlatform platform;
|
||||
private final ViaPlatform<?> platform;
|
||||
private final ViaProviders providers = new ViaProviders();
|
||||
private boolean debug;
|
||||
// Internals
|
||||
private final ViaInjector injector;
|
||||
private final ViaCommandHandler commandHandler;
|
||||
private final ViaPlatformLoader loader;
|
||||
private boolean debug;
|
||||
|
||||
@Builder
|
||||
public ViaManager(ViaPlatform platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
|
||||
public ViaManager(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
|
||||
this.platform = platform;
|
||||
this.injector = injector;
|
||||
this.commandHandler = commandHandler;
|
||||
@ -112,23 +110,39 @@ public class ViaManager {
|
||||
loader.unload();
|
||||
}
|
||||
|
||||
public void addPortedClient(UserConnection info) {
|
||||
portedPlayers.put(info.get(ProtocolInfo.class).getUuid(), info);
|
||||
}
|
||||
|
||||
public void removePortedClient(UUID clientID) {
|
||||
portedPlayers.remove(clientID);
|
||||
}
|
||||
|
||||
public UserConnection getConnection(UUID playerUUID) {
|
||||
return portedPlayers.get(playerUUID);
|
||||
public Set<UserConnection> getConnections() {
|
||||
return platform.getConnectionManager().getConnections();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getConnectedClients()
|
||||
*/
|
||||
@Deprecated
|
||||
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;
|
||||
}
|
||||
|
||||
@ -155,4 +169,8 @@ public class ViaManager {
|
||||
public ViaPlatformLoader getLoader() {
|
||||
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
|
||||
* @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
|
||||
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
|
||||
|
@ -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
|
||||
*/
|
||||
boolean isOldClientsAllowed();
|
||||
|
||||
ViaConnectionManager getConnectionManager();
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class BaseProtocol1_7 extends Protocol {
|
||||
String username = wrapper.passthrough(Type.STRING);
|
||||
info.setUsername(username);
|
||||
// Add to ported clients
|
||||
Via.getManager().addPortedClient(wrapper.user());
|
||||
Via.getManager().handleLoginSuccess(wrapper.user());
|
||||
|
||||
if (info.getPipeline().pipes().size() == 2
|
||||
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_7.class
|
||||
|
@ -8,7 +8,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTra
|
||||
public class TabCompleteThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
|
||||
for (UserConnection info : Via.getManager().getConnections()) {
|
||||
if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) {
|
||||
if (info.getChannel().isOpen()) {
|
||||
info.get(TabCompleteTracker.class).sendPacketToServer();
|
||||
|
@ -9,7 +9,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
||||
public class ViaIdleThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
|
||||
for (UserConnection info : Via.getManager().getConnections()) {
|
||||
ProtocolInfo protocolInfo = info.get(ProtocolInfo.class);
|
||||
if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
|
||||
|
@ -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;
|
||||
@ -21,6 +20,7 @@ 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.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.sponge.VersionInfo;
|
||||
@ -31,9 +31,7 @@ import us.myles.ViaVersion.sponge.util.LoggerWrapper;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Plugin(id = "viaversion",
|
||||
@ -42,23 +40,18 @@ import java.util.logging.Logger;
|
||||
authors = {"_MylesC", "creeper123123321", "Gerrygames", "KennyTV", "Matsv"},
|
||||
description = "Allow newer Minecraft versions to connect to an older server version."
|
||||
)
|
||||
public class SpongePlugin implements ViaPlatform {
|
||||
public class SpongePlugin implements ViaPlatform<Player> {
|
||||
@Inject
|
||||
private Game game;
|
||||
|
||||
@Inject
|
||||
private PluginContainer container;
|
||||
|
||||
@Inject
|
||||
@DefaultConfig(sharedRoot = false)
|
||||
private File defaultConfig;
|
||||
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
|
||||
@ -66,7 +59,7 @@ public class SpongePlugin implements ViaPlatform {
|
||||
// Setup Logger
|
||||
logger = new LoggerWrapper(container.getLogger());
|
||||
// Setup Plugin
|
||||
conf = new SpongeViaConfig(container, defaultConfig.getParentFile());
|
||||
conf = new SpongeViaConfig(container, spongeConfig.getParentFile());
|
||||
SpongeCommandHandler commandHandler = new SpongeCommandHandler();
|
||||
game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
|
||||
logger.info("ViaVersion " + getPluginVersion() + " is now loaded!");
|
||||
@ -186,7 +179,7 @@ public class SpongePlugin implements ViaPlatform {
|
||||
@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);
|
||||
}
|
||||
@ -203,7 +196,7 @@ public class SpongePlugin implements ViaPlatform {
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return defaultConfig.getParentFile();
|
||||
return spongeConfig.getParentFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -234,4 +227,24 @@ public class SpongePlugin implements ViaPlatform {
|
||||
public boolean isOldClientsAllowed() {
|
||||
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 {
|
||||
@Listener
|
||||
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.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -20,21 +19,19 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(Player player) {
|
||||
if (!isPorted(player.getUniqueId()))
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return getPlayerVersion(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
if (!isPorted(uuid))
|
||||
if (!isInjected(uuid))
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,8 +41,8 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -71,8 +68,4 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
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.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,6 +20,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.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
@ -33,9 +33,7 @@ import us.myles.ViaVersion.velocity.util.LoggerWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Plugin(
|
||||
@ -46,20 +44,21 @@ import java.util.concurrent.TimeUnit;
|
||||
description = "Allow newer Minecraft versions to connect to an older server version.",
|
||||
url = "https://viaversion.com"
|
||||
)
|
||||
@Getter
|
||||
public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
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) {
|
||||
@ -69,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)
|
||||
@ -84,11 +84,11 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
|
||||
@Subscribe
|
||||
public void onQuit(DisconnectEvent e) {
|
||||
UserConnection userConnection = Via.getManager().getPortedPlayers().get(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()) {
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityViaAPI getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityViaConfig getConf() {
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
|
||||
@ -215,4 +225,14 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
public boolean isOldClientsAllowed() {
|
||||
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;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -22,25 +20,20 @@ import java.util.UUID;
|
||||
public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
@Override
|
||||
public int getPlayerVersion(Player player) {
|
||||
if (!isPorted(player.getUniqueId()))
|
||||
if (!isInjected(player.getUniqueId()))
|
||||
return player.getProtocolVersion().getProtocol();
|
||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return Via.getManager().getConnection(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
if (!isPorted(uuid)) {
|
||||
return VelocityPlugin.PROXY.getPlayer(uuid)
|
||||
.map(InboundConnection::getProtocolVersion)
|
||||
.map(ProtocolVersion::getProtocol)
|
||||
.orElse(ProtocolRegistry.SERVER_PROTOCOL);
|
||||
}
|
||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return getPlayerVersion(VelocityPlugin.PROXY.getPlayer(uuid).orElseThrow(NoSuchElementException::new));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,8 +43,8 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -78,7 +71,4 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getPortedPlayers();
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren