Skip to content

Commit abf14e6

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/master' into feature/1.21.4
# Conflicts: # core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java # core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java # gradle/libs.versions.toml
2 parents b469a61 + 2019e53 commit abf14e6

22 files changed

+52
-96
lines changed

bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ private void workAroundWeirdBug(GeyserBootstrap bootstrap) {
178178
MinecraftProtocol protocol = new MinecraftProtocol();
179179
LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().address(),
180180
bootstrap.getGeyserConfig().getRemote().port(), this.serverSocketAddress,
181-
InetAddress.getLoopbackAddress().getHostAddress(), protocol, protocol.createHelper());
181+
InetAddress.getLoopbackAddress().getHostAddress(), protocol, Runnable::run);
182182
session.connect();
183-
session.disconnect("");
184183
}
185184

186185
@Override

core/src/main/java/org/geysermc/geyser/GeyserImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,6 @@ private void startInstance() {
414414
}
415415
}
416416

417-
// Ensure that PacketLib does not create an event loop for handling packets; we'll do that ourselves
418-
TcpSession.USE_EVENT_LOOP_FOR_PACKETS = false;
419-
420417
pendingMicrosoftAuthentication = new PendingMicrosoftAuthentication(config.getPendingAuthenticationTimeout());
421418

422419
this.newsHandler = new NewsHandler(BRANCH, this.buildNumber());

core/src/main/java/org/geysermc/geyser/network/GameProtocol.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.checkerframework.checker.nullness.qual.Nullable;
2929
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
3030
import org.cloudburstmc.protocol.bedrock.codec.v748.Bedrock_v748;
31-
import org.cloudburstmc.protocol.bedrock.codec.v765.Bedrock_v765;
31+
import org.cloudburstmc.protocol.bedrock.codec.v766.Bedrock_v766;
3232
import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec;
3333
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
3434
import org.geysermc.mcprotocollib.protocol.codec.PacketCodec;
@@ -46,9 +46,8 @@ public final class GameProtocol {
4646
* Default Bedrock codec that should act as a fallback. Should represent the latest available
4747
* release of the game that Geyser supports.
4848
*/
49-
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = CodecProcessor.processCodec(Bedrock_v765.CODEC.toBuilder()
49+
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = CodecProcessor.processCodec(Bedrock_v766.CODEC.toBuilder()
5050
.minecraftVersion("1.21.50")
51-
.protocolVersion(766)
5251
.build());
5352

5453
/**

core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public UpstreamPacketHandler(GeyserImpl geyser, GeyserSession session) {
9696
}
9797

9898
private PacketSignal translateAndDefault(BedrockPacket packet) {
99-
Registries.BEDROCK_PACKET_TRANSLATORS.translate(packet.getClass(), packet, session);
99+
Registries.BEDROCK_PACKET_TRANSLATORS.translate(packet.getClass(), packet, session, false);
100100
return PacketSignal.HANDLED; // PacketSignal.UNHANDLED will log a WARN publicly
101101
}
102102

core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.net.InetSocketAddress;
6060
import java.net.SocketAddress;
6161
import java.util.concurrent.CompletableFuture;
62+
import java.util.concurrent.Executor;
6263
import java.util.concurrent.TimeUnit;
6364

6465
/**
@@ -72,11 +73,11 @@ public final class LocalSession extends TcpSession {
7273
private final String clientIp;
7374
private final PacketCodecHelper codecHelper;
7475

75-
public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, MinecraftCodecHelper codecHelper) {
76-
super(host, port, protocol);
76+
public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, Executor packetHandlerExecutor) {
77+
super(host, port, protocol, packetHandlerExecutor);
7778
this.targetAddress = targetAddress;
7879
this.clientIp = clientIp;
79-
this.codecHelper = codecHelper;
80+
this.codecHelper = protocol.createHelper();
8081
}
8182

8283
@Override

core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ protected PacketTranslatorRegistry() {
5656
}
5757

5858
@SuppressWarnings("unchecked")
59-
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session) {
59+
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session, boolean canRunImmediately) {
6060
if (session.getUpstream().isClosed() || session.isClosed()) {
6161
return false;
6262
}
6363

6464
PacketTranslator<P> translator = (PacketTranslator<P>) this.mappings.get(clazz);
6565
if (translator != null) {
66-
EventLoop eventLoop = session.getEventLoop();
67-
if (!translator.shouldExecuteInEventLoop() || eventLoop.inEventLoop()) {
66+
EventLoop eventLoop = session.getTickEventLoop();
67+
if (canRunImmediately || !translator.shouldExecuteInEventLoop() || eventLoop.inEventLoop()) {
6868
translate0(session, translator, packet);
6969
} else {
7070
eventLoop.execute(() -> translate0(session, translator, packet));

core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.cloudburstmc.nbt.NbtType;
4646
import org.cloudburstmc.nbt.NbtUtils;
4747
import org.cloudburstmc.protocol.bedrock.codec.v748.Bedrock_v748;
48-
import org.cloudburstmc.protocol.bedrock.codec.v765.Bedrock_v765;
48+
import org.cloudburstmc.protocol.bedrock.codec.v766.Bedrock_v766;
4949
import org.cloudburstmc.protocol.bedrock.data.BlockPropertyData;
5050
import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition;
5151
import org.geysermc.geyser.GeyserImpl;
@@ -124,7 +124,7 @@ private static void nullifyBlocksNbt() {
124124
private static void registerBedrockBlocks() {
125125
var blockMappers = ImmutableMap.<ObjectIntPair<String>, Remapper>builder()
126126
.put(ObjectIntPair.of("1_21_40", Bedrock_v748.CODEC.getProtocolVersion()), Conversion766_748::remapBlock)
127-
.put(ObjectIntPair.of("1_21_50", Bedrock_v765.CODEC.getProtocolVersion()), tag -> tag)
127+
.put(ObjectIntPair.of("1_21_50", Bedrock_v766.CODEC.getProtocolVersion()), tag -> tag)
128128
.build();
129129

130130
// We can keep this strong as nothing should be garbage collected

core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import org.cloudburstmc.nbt.NbtType;
4747
import org.cloudburstmc.nbt.NbtUtils;
4848
import org.cloudburstmc.protocol.bedrock.codec.v748.Bedrock_v748;
49-
import org.cloudburstmc.protocol.bedrock.codec.v765.Bedrock_v765;
49+
import org.cloudburstmc.protocol.bedrock.codec.v766.Bedrock_v766;
5050
import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition;
5151
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
5252
import org.cloudburstmc.protocol.bedrock.data.definitions.SimpleItemDefinition;
@@ -108,7 +108,6 @@ interface Remapper {
108108
}
109109

110110
public static void populate() {
111-
112111
Map<Item, Item> itemFallbacks = new HashMap<>();
113112
itemFallbacks.put(Items.PALE_OAK_PLANKS, Items.BIRCH_PLANKS);
114113
itemFallbacks.put(Items.PALE_OAK_FENCE, Items.BIRCH_FENCE);
@@ -147,7 +146,7 @@ public static void populate() {
147146

148147
List<PaletteVersion> paletteVersions = new ArrayList<>(2);
149148
paletteVersions.add(new PaletteVersion("1_21_40", Bedrock_v748.CODEC.getProtocolVersion(), itemFallbacks, (item, mapping) -> mapping));
150-
paletteVersions.add(new PaletteVersion("1_21_50", Bedrock_v765.CODEC.getProtocolVersion()));
149+
paletteVersions.add(new PaletteVersion("1_21_50", Bedrock_v766.CODEC.getProtocolVersion()));
151150

152151
GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap();
153152

core/src/main/java/org/geysermc/geyser/registry/populator/TagRegistryPopulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
3535
import it.unimi.dsi.fastutil.objects.ObjectIntPair;
3636
import org.cloudburstmc.protocol.bedrock.codec.v748.Bedrock_v748;
37-
import org.cloudburstmc.protocol.bedrock.codec.v765.Bedrock_v765;
37+
import org.cloudburstmc.protocol.bedrock.codec.v766.Bedrock_v766;
3838
import org.geysermc.geyser.GeyserBootstrap;
3939
import org.geysermc.geyser.GeyserImpl;
4040
import org.geysermc.geyser.item.type.Item;
@@ -68,7 +68,7 @@ public boolean equals(int[] a, int[] b) {
6868

6969
List<ObjectIntPair<String>> paletteVersions = List.of(
7070
ObjectIntPair.of("1_21_40", Bedrock_v748.CODEC.getProtocolVersion()),
71-
ObjectIntPair.of("1_21_50", Bedrock_v765.CODEC.getProtocolVersion())
71+
ObjectIntPair.of("1_21_50", Bedrock_v766.CODEC.getProtocolVersion())
7272
);
7373
Type type = new TypeToken<Map<String, List<String>>>() {}.getType();
7474

core/src/main/java/org/geysermc/geyser/session/GeyserSession.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
253253
* The loop where all packets and ticking is processed to prevent concurrency issues.
254254
* If this is manually called, ensure that any exceptions are properly handled.
255255
*/
256-
private final EventLoop eventLoop;
256+
private final EventLoop tickEventLoop;
257257
@Setter
258258
private AuthData authData;
259259
private BedrockClientData clientData;
@@ -658,10 +658,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
658658

659659
private MinecraftProtocol protocol;
660660

661-
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
661+
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop tickEventLoop) {
662662
this.geyser = geyser;
663663
this.upstream = new UpstreamSession(bedrockServerSession);
664-
this.eventLoop = eventLoop;
664+
this.tickEventLoop = tickEventLoop;
665665

666666
this.erosionHandler = new GeyserboundHandshakePacketHandler(this);
667667

@@ -952,17 +952,17 @@ private void connectDownstream() {
952952
boolean floodgate = this.remoteServer.authType() == AuthType.FLOODGATE;
953953

954954
// Start ticking
955-
tickThread = eventLoop.scheduleAtFixedRate(this::tick, 50, 50, TimeUnit.MILLISECONDS);
955+
tickThread = tickEventLoop.scheduleAtFixedRate(this::tick, 50, 50, TimeUnit.MILLISECONDS);
956956

957957
TcpSession downstream;
958958
if (geyser.getBootstrap().getSocketAddress() != null) {
959959
// We're going to connect through the JVM and not through TCP
960960
downstream = new LocalSession(this.remoteServer.address(), this.remoteServer.port(),
961961
geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(),
962-
this.protocol, this.protocol.createHelper());
962+
this.protocol, tickEventLoop);
963963
this.downstream = new DownstreamSession(downstream);
964964
} else {
965-
downstream = new TcpClientSession(this.remoteServer.address(), this.remoteServer.port(), this.protocol);
965+
downstream = new TcpClientSession(this.remoteServer.address(), this.remoteServer.port(), "0.0.0.0", 0, this.protocol, null, tickEventLoop);
966966
this.downstream = new DownstreamSession(downstream);
967967

968968
boolean resolveSrv = false;
@@ -1148,7 +1148,7 @@ public void disconnected(DisconnectedEvent event) {
11481148

11491149
@Override
11501150
public void packetReceived(Session session, Packet packet) {
1151-
Registries.JAVA_PACKET_TRANSLATORS.translate(packet.getClass(), packet, GeyserSession.this);
1151+
Registries.JAVA_PACKET_TRANSLATORS.translate(packet.getClass(), packet, GeyserSession.this, true);
11521152
}
11531153

11541154
@Override
@@ -1218,26 +1218,19 @@ public void disconnect(String reason) {
12181218
* Moves task to the session event loop if already not in it. Otherwise, the task is automatically ran.
12191219
*/
12201220
public void ensureInEventLoop(Runnable runnable) {
1221-
if (eventLoop.inEventLoop()) {
1222-
runnable.run();
1221+
if (tickEventLoop.inEventLoop()) {
1222+
executeRunnable(runnable);
12231223
return;
12241224
}
1225+
12251226
executeInEventLoop(runnable);
12261227
}
12271228

12281229
/**
12291230
* Executes a task and prints a stack trace if an error occurs.
12301231
*/
12311232
public void executeInEventLoop(Runnable runnable) {
1232-
eventLoop.execute(() -> {
1233-
try {
1234-
runnable.run();
1235-
} catch (ErosionCancellationException e) {
1236-
geyser.getLogger().debug("Caught ErosionCancellationException");
1237-
} catch (Throwable e) {
1238-
geyser.getLogger().error("Error thrown in " + this.bedrockUsername() + "'s event loop!", e);
1239-
}
1240-
});
1233+
tickEventLoop.execute(() -> executeRunnable(runnable));
12411234
}
12421235

12431236
/**
@@ -1246,19 +1239,25 @@ public void executeInEventLoop(Runnable runnable) {
12461239
* The task will not run if the session is closed.
12471240
*/
12481241
public ScheduledFuture<?> scheduleInEventLoop(Runnable runnable, long duration, TimeUnit timeUnit) {
1249-
return eventLoop.schedule(() -> {
1250-
try {
1242+
return tickEventLoop.schedule(() -> {
1243+
executeRunnable(() -> {
12511244
if (!closed) {
12521245
runnable.run();
12531246
}
1254-
} catch (ErosionCancellationException e) {
1255-
geyser.getLogger().debug("Caught ErosionCancellationException");
1256-
} catch (Throwable e) {
1257-
geyser.getLogger().error("Error thrown in " + this.bedrockUsername() + "'s event loop!", e);
1258-
}
1247+
});
12591248
}, duration, timeUnit);
12601249
}
12611250

1251+
private void executeRunnable(Runnable runnable) {
1252+
try {
1253+
runnable.run();
1254+
} catch (ErosionCancellationException e) {
1255+
geyser.getLogger().debug("Caught ErosionCancellationException");
1256+
} catch (Throwable e) {
1257+
geyser.getLogger().error("Error thrown in " + this.bedrockUsername() + "'s event loop!", e);
1258+
}
1259+
}
1260+
12621261
/**
12631262
* Called every 50 milliseconds - one Minecraft tick.
12641263
*/

0 commit comments

Comments
 (0)