use of com.velocitypowered.proxy.connection.MinecraftConnection 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();
}
});
}
use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.
the class LimboImpl method spawnPlayer.
@Override
public void spawnPlayer(Player apiPlayer, LimboSessionHandler handler) {
ConnectedPlayer player = (ConnectedPlayer) apiPlayer;
MinecraftConnection connection = player.getConnection();
Class<? extends LimboSessionHandler> handlerClass = handler.getClass();
if (this.limboName == null) {
this.limboName = handlerClass.getSimpleName();
}
connection.eventLoop().execute(() -> {
ChannelPipeline pipeline = connection.getChannel().pipeline();
if (Settings.IMP.MAIN.LOGGING_ENABLED) {
this.plugin.getLogger().info(player.getUsername() + " (" + player.getRemoteAddress() + ") has connected to the " + this.limboName + " Limbo");
}
if (!pipeline.names().contains("prepared-encoder")) {
// and an error occurs that "minecraft-encoder" doesn't exist.
if (!pipeline.names().contains(Connections.MINECRAFT_ENCODER)) {
connection.close();
return;
}
pipeline.addAfter(Connections.MINECRAFT_ENCODER, "prepared-encoder", new PreparedPacketEncoder(connection.getProtocolVersion()));
}
RegisteredServer previousServer = null;
if (connection.getState() != LimboProtocol.getLimboRegistry()) {
connection.setState(LimboProtocol.getLimboRegistry());
VelocityServerConnection server = player.getConnectedServer();
if (server != null) {
server.disconnect();
player.setConnectedServer(null);
previousServer = server.getServer();
this.plugin.setLimboJoined(player);
}
}
if (this.plugin.isLimboJoined(player)) {
if (connection.getType() == ConnectionTypes.LEGACY_FORGE) {
connection.delayedWrite(this.safeRejoinPackets);
} else {
connection.delayedWrite(this.fastRejoinPackets);
}
} else {
connection.delayedWrite(this.joinPackets);
}
connection.delayedWrite(this.postJoinPackets);
connection.delayedWrite(this.getBrandMessage(handlerClass));
this.plugin.setLimboJoined(player);
LimboSessionHandlerImpl sessionHandler = new LimboSessionHandlerImpl(this.plugin, player, handler, connection.getSessionHandler(), previousServer, () -> this.limboName);
connection.setSessionHandler(sessionHandler);
connection.flush();
if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_18_2) >= 0) {
this.plugin.getServer().getScheduler().buildTask(this.plugin, () -> connection.eventLoop().execute(() -> this.proceed(player, sessionHandler))).delay(Settings.IMP.MAIN.RECEIVER_LEVEL_1_18_2_FIXER_DELAY, TimeUnit.MILLISECONDS).schedule();
} else {
this.proceed(player, sessionHandler);
}
});
}
Aggregations