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();
}
}
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);
}
}
}
Aggregations