Search in sources :

Example 1 with StorableObject

use of com.viaversion.viaversion.api.connection.StorableObject 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

StorableObject (com.viaversion.viaversion.api.connection.StorableObject)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 ClientEntityIdChangeListener (com.viaversion.viaversion.api.data.entity.ClientEntityIdChangeListener)1 EntityTracker (com.viaversion.viaversion.api.data.entity.EntityTracker)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 EventHandler (net.md_5.bungee.event.EventHandler)1