use of com.velocitypowered.api.event.connection.LoginEvent in project LibertyBans by A248.
the class ConnectionListenerTest method allowed.
@Test
public void allowed() {
allowedResult();
Player player = mockPlayer();
LoginEvent event = new LoginEvent(player);
var originalResult = event.getResult();
listener.handler.executeAndWait(event);
assertEquals(originalResult.getReasonComponent(), event.getResult().getReasonComponent());
}
use of com.velocitypowered.api.event.connection.LoginEvent 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;
});
}
use of com.velocitypowered.api.event.connection.LoginEvent in project LibertyBans by A248.
the class ConnectionListenerTest method deniedByOtherPlugin.
@Test
public void deniedByOtherPlugin() {
allowedResult();
Player player = mockPlayer();
LoginEvent event = new LoginEvent(player);
var denial = ResultedEvent.ComponentResult.denied(Component.text("denial"));
event.setResult(denial);
listener.handler.executeAndWait(event);
assertEquals(denial.getReasonComponent(), event.getResult().getReasonComponent());
}
use of com.velocitypowered.api.event.connection.LoginEvent in project LibertyBans by A248.
the class ConnectionListenerTest method denied.
@Test
public void denied() {
deniedResult("denied");
Player player = mockPlayer();
LoginEvent event = new LoginEvent(player);
listener.handler.executeAndWait(event);
assertEquals("denied", event.getResult().getReasonComponent().map(PlainComponentSerializer.plain()::serialize).orElse(null));
}
Aggregations