Add SessionInitialize event (#3691)

* Add SessionInitialize event

* Move to using GeyserConnection instead of BedrockServerSession

* Remove redundent re-expose

* Rename geyserSession to just session
This commit is contained in:
rtm516 2023-04-23 11:42:02 +01:00 committed by GitHub
parent f39e689b83
commit 2ac7eb83c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View file

@ -32,6 +32,8 @@ import org.cloudburstmc.protocol.bedrock.BedrockPeer;
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.netty.initializer.BedrockServerInitializer;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.bedrock.SessionInitializeEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nonnull;
@ -49,7 +51,9 @@ public class GeyserServerInitializer extends BedrockServerInitializer {
public void initSession(@Nonnull BedrockServerSession bedrockServerSession) {
try {
bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(this.geyser, new GeyserSession(this.geyser, bedrockServerSession, this.eventLoopGroup.next())));
GeyserSession session = new GeyserSession(this.geyser, bedrockServerSession, this.eventLoopGroup.next());
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(this.geyser, session));
this.geyser.eventBus().fire(new SessionInitializeEvent(session));
} catch (Throwable e) {
// Error must be caught or it will be swallowed
this.geyser.getLogger().error("Error occurred while initializing player!", e);