use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.
the class LimboImpl method respawnPlayer.
@Override
public void respawnPlayer(Player player) {
MinecraftConnection connection = ((ConnectedPlayer) player).getConnection();
connection.write(this.spawnPosition);
if (this.chunks != null) {
connection.write(this.chunks);
}
}
use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.
the class LimboSessionHandlerImpl method disconnected.
@Override
public void disconnected() {
this.callback.onDisconnect();
if (this.keepAliveTask != null) {
this.keepAliveTask.cancel();
}
if (Settings.IMP.MAIN.LOGGING_ENABLED) {
this.plugin.getLogger().info(this.player.getUsername() + " (" + this.player.getRemoteAddress() + ") has disconnected from the " + this.limboName.get() + " Limbo");
}
MinecraftConnection connection = this.player.getConnection();
if (connection.isClosed()) {
try {
teardown.invoke(this.player);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return;
}
if (!(this.originalHandler instanceof LoginSessionHandler) && !(this.originalHandler instanceof LimboSessionHandlerImpl)) {
connection.eventLoop().execute(() -> connection.setSessionHandler(this.originalHandler));
}
ChannelPipeline pipeline = connection.getChannel().pipeline();
if (pipeline.names().contains("prepared-encoder")) {
pipeline.remove(PreparedPacketEncoder.class);
}
}
use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.
the class LoginTasksQueue method finish.
private void finish() {
this.plugin.removeLoginQueue(this.player);
MinecraftConnection connection = this.player.getConnection();
this.server.getEventManager().fire(new GameProfileRequestEvent(this.inbound, this.player.getGameProfile(), this.player.isOnlineMode())).thenAcceptAsync(gameProfile -> this.server.getEventManager().fire(new SafeGameProfileRequestEvent(gameProfile.getGameProfile(), gameProfile.isOnlineMode())).thenAcceptAsync(safeGameProfile -> {
try {
profile.set(this.player, safeGameProfile.getGameProfile());
// From Velocity.
this.server.getEventManager().fire(new PermissionsSetupEvent(this.player, (PermissionProvider) defaultPermissions.get(null))).thenAcceptAsync(event -> {
if (!connection.isClosed()) {
// Wait for permissions to load, then set the players' permission function.
final PermissionFunction function = event.createFunction(this.player);
if (function == null) {
this.plugin.getLogger().error("A plugin permission provider {} provided an invalid permission function" + " for player {}. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", event.getProvider().getClass().getName(), this.player.getUsername());
} else {
try {
setPermissionFunction.invoke(this.player, function);
} catch (IllegalAccessException | InvocationTargetException ex) {
this.plugin.getLogger().error("Exception while completing injection to {}", this.player, ex);
}
}
try {
this.initialize(connection);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
} catch (IllegalAccessException ex) {
this.plugin.getLogger().error("Exception while completing injection to {}", this.player, ex);
}
}, connection.eventLoop()), connection.eventLoop());
}
use of com.velocitypowered.proxy.connection.MinecraftConnection 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.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.
the class LoginListener method hookPlaySession.
@Subscribe
public void hookPlaySession(ServerConnectedEvent event) {
ConnectedPlayer player = (ConnectedPlayer) event.getPlayer();
MinecraftConnection connection = player.getConnection();
connection.eventLoop().execute(() -> {
if (!(connection.getSessionHandler() instanceof ClientPlaySessionHandler)) {
ClientPlaySessionHandler playHandler = new ClientPlaySessionHandler(this.server, player);
try {
spawned.set(playHandler, this.plugin.isLimboJoined(player));
} catch (IllegalAccessException ex) {
this.plugin.getLogger().error("Exception while hooking into ClientPlaySessionHandler of {}", player, ex);
}
connection.setSessionHandler(playHandler);
}
});
}
Aggregations