use of com.velocitypowered.proxy.protocol.packet.SetCompression in project LimboAPI by Elytrium.
the class LoginListener method hookLoginSession.
public void hookLoginSession(GameProfileRequestEvent event) throws IllegalAccessException {
// Changing mcConnection to the closed one. For what? To break the "initializePlayer"
// method (which checks mcConnection.isActive()) and to override it. :)
InitialInboundConnection inbound = (InitialInboundConnection) delegate.get(event.getConnection());
MinecraftConnection connection = inbound.getConnection();
LoginSessionHandler handler = (LoginSessionHandler) connection.getSessionHandler();
loginConnectionField.set(handler, closed);
if (connection.isClosed()) {
return;
}
connection.eventLoop().execute(() -> {
try {
// Initiate a regular connection and move over to it.
ConnectedPlayer player = ctor.newInstance(this.server, event.getGameProfile(), connection, event.getConnection().getVirtualHost().orElse(null), this.onlineMode.contains(event.getUsername()));
if (!this.server.canRegisterConnection(player)) {
player.disconnect0(Component.translatable("velocity.error.already-connected-proxy", NamedTextColor.RED), true);
return;
}
if (connection.isClosed()) {
return;
}
// Completing the Login process
int threshold = this.server.getConfiguration().getCompressionThreshold();
if (threshold >= 0 && connection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) {
connection.write(new SetCompression(threshold));
if (connection.isClosed()) {
return;
}
connection.setCompressionThreshold(threshold);
}
VelocityConfiguration configuration = this.server.getConfiguration();
UUID playerUniqueId = player.getUniqueId();
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
}
ServerLoginSuccess success = new ServerLoginSuccess();
success.setUsername(player.getUsername());
success.setUuid(playerUniqueId);
connection.write(success);
this.plugin.setInitialID(player, playerUniqueId);
connection.setState(StateRegistry.PLAY);
this.server.getEventManager().fire(new LoginLimboRegisterEvent(player)).thenAcceptAsync(limboEvent -> {
LoginTasksQueue queue = new LoginTasksQueue(this.plugin, handler, this.server, player, inbound, limboEvent.getCallbacks());
this.plugin.addLoginQueue(player, queue);
queue.next();
}, connection.eventLoop());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
});
}
Aggregations