Search in sources :

Example 36 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.

the class BungeeServerHandler method onServerConnect.

// Set the handshake version every time someone connects to any server
@EventHandler(priority = 120)
public void onServerConnect(ServerConnectEvent e) {
    if (e.isCancelled()) {
        return;
    }
    UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
    if (user == null)
        return;
    if (!user.has(BungeeStorage.class)) {
        user.put(new BungeeStorage(e.getPlayer()));
    }
    int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName());
    List<ProtocolPathEntry> protocols = Via.getManager().getProtocolManager().getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId);
    // Check if ViaVersion can support that version
    try {
        // Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
        Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection());
        setProtocol.invoke(handshake, protocols == null ? user.getProtocolInfo().getProtocolVersion() : protocolId);
    } catch (InvocationTargetException | IllegalAccessException e1) {
        e1.printStackTrace();
    }
}
Also used : ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) BungeeStorage(com.viaversion.viaversion.bungee.storage.BungeeStorage) StorableObject(com.viaversion.viaversion.api.connection.StorableObject) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) EventHandler(net.md_5.bungee.event.EventHandler)

Example 37 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.

the class BungeeServerHandler method onServerSwitch.

@EventHandler(priority = -120)
public void onServerSwitch(ServerSwitchEvent e) {
    // Update entity id
    UserConnection userConnection = Via.getManager().getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
    if (userConnection == null)
        return;
    int playerId;
    try {
        playerId = Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(userConnection);
    } catch (Exception ex) {
        // Ignored
        return;
    }
    for (EntityTracker tracker : userConnection.getEntityTrackers()) {
        tracker.setClientEntityId(playerId);
    }
    // For ViaRewind
    for (StorableObject object : userConnection.getStoredObjects().values()) {
        if (object instanceof ClientEntityIdChangeListener) {
            ((ClientEntityIdChangeListener) object).setClientEntityId(playerId);
        }
    }
}
Also used : EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) ClientEntityIdChangeListener(com.viaversion.viaversion.api.data.entity.ClientEntityIdChangeListener) StorableObject(com.viaversion.viaversion.api.connection.StorableObject) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

UserConnection (com.viaversion.viaversion.api.connection.UserConnection)37 UserConnectionImpl (com.viaversion.viaversion.connection.UserConnectionImpl)20 ProtocolPipelineImpl (com.viaversion.viaversion.protocol.ProtocolPipelineImpl)20 SocketChannel (io.netty.channel.socket.SocketChannel)16 Inject (org.spongepowered.asm.mixin.injection.Inject)15 FabricDecodeHandler (com.viaversion.fabric.common.handler.FabricDecodeHandler)14 FabricEncodeHandler (com.viaversion.fabric.common.handler.FabricEncodeHandler)14 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)5 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)3 EventHandler (net.md_5.bungee.event.EventHandler)3 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)2 Via (com.viaversion.viaversion.api.Via)2 StorableObject (com.viaversion.viaversion.api.connection.StorableObject)2 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)2 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)2 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)2 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)2 ClientboundPacketType (com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType)2 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)2