use of com.velocitypowered.api.event.connection.DisconnectEvent in project LimboAPI by Elytrium.
the class LoginTasksQueue method initialize.
// Ported from Velocity.
// TODO: Пофиксить ситуацию когда при подключении после лимбы внутренний сервер кикает и причину не пишет клиенту
private void initialize(MinecraftConnection connection) throws IllegalAccessException {
association.set(connection, this.player);
state.set(connection, StateRegistry.PLAY);
connection.getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.PLAY);
connection.getChannel().pipeline().get(MinecraftDecoder.class).setState(StateRegistry.PLAY);
this.server.getEventManager().fire(new LoginEvent(this.player)).thenAcceptAsync(event -> {
if (connection.isClosed()) {
// The player was disconnected
this.server.getEventManager().fireAndForget(new DisconnectEvent(this.player, DisconnectEvent.LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE));
return;
}
Optional<Component> reason = event.getResult().getReasonComponent();
if (reason.isPresent()) {
this.player.disconnect0(reason.get(), true);
} else {
if (!this.server.registerConnection(this.player)) {
this.player.disconnect0(Component.translatable("velocity.error.already-connected-proxy"), true);
return;
}
try {
connection.setSessionHandler(initialCtor.newInstance(this.player));
this.server.getEventManager().fire(new PostLoginEvent(this.player)).thenAccept((ignored) -> {
try {
// go back i want to be ~~monke~~ original mcConnection
loginConnectionField.set(this.handler, connection);
connectToInitialServer.invoke(this.handler, this.player);
} catch (IllegalAccessException | InvocationTargetException ex) {
this.plugin.getLogger().error("Exception while connecting {} to initial server", this.player, ex);
}
});
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
}, connection.eventLoop()).exceptionally((ex) -> {
this.plugin.getLogger().error("Exception while completing login initialisation phase for {}", this.player, ex);
return null;
});
}
Aggregations