Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanwer committed May 11, 2024
2 parents bb7384e + 7801e35 commit 6413e4b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public ConnectionRequestEvent(@NonNull InetSocketAddress ip, @Nullable InetSocke
* The IP address of the client attempting to connect
*
* @return the IP address of the client attempting to connect
* @deprecated Use {@link #inetSocketAddress()} instead
*/
@NonNull
@NonNull @Deprecated(forRemoval = true)
public InetSocketAddress getInetSocketAddress() {
return ip;
}
Expand All @@ -60,12 +61,33 @@ public InetSocketAddress getInetSocketAddress() {
* The IP address of the proxy handling the connection. It will return null if there is no proxy.
*
* @return the IP address of the proxy handling the connection
* @deprecated Use {@link #proxyIp()} instead
*/
@Nullable
@Nullable @Deprecated(forRemoval = true)
public InetSocketAddress getProxyIp() {
return proxyIp;
}

/**
* The IP address of the client attempting to connect
*
* @return the IP address of the client attempting to connect
*/
@NonNull
public InetSocketAddress inetSocketAddress() {
return ip;
}

/**
* The IP address of the proxy handling the connection. It will return null if there is no proxy.
*
* @return the IP address of the proxy handling the connection
*/
@Nullable
public InetSocketAddress proxyIp() {
return proxyIp;
}

/**
* The cancel status of this event. If this event is cancelled, the connection will be rejected.
*
Expand Down
21 changes: 16 additions & 5 deletions core/src/main/java/org/geysermc/geyser/item/type/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
import java.util.Map;

public class Item {
/**
* This is a map from Java-only enchantments to their translation keys so that we can
* map these enchantments to Bedrock clients, since they don't actually exist there.
*/
private static final Map<Enchantment.JavaEnchantment, String> ENCHANTMENT_TRANSLATION_KEYS = Map.of(
Enchantment.JavaEnchantment.SWEEPING_EDGE, "enchantment.minecraft.sweeping",
Enchantment.JavaEnchantment.DENSITY, "enchantment.minecraft.density",
Enchantment.JavaEnchantment.BREACH, "enchantment.minecraft.breach",
Enchantment.JavaEnchantment.WIND_BURST, "enchantment.minecraft.wind_burst");

private final String javaIdentifier;
private int javaId = -1;
private final int stackSize;
Expand Down Expand Up @@ -227,8 +237,10 @@ public void translateNbtToJava(@NonNull NbtMap bedrockTag, @NonNull DataComponen
// TODO verify
// TODO streamline Enchantment process
Enchantment.JavaEnchantment enchantment = Enchantment.JavaEnchantment.of(enchantId);
if (enchantment == Enchantment.JavaEnchantment.SWEEPING_EDGE) {
addSweeping(session, builder, level);
String translationKey = ENCHANTMENT_TRANSLATION_KEYS.get(enchantment);
if (translationKey != null) {
String enchantmentTranslation = MinecraftLocale.getLocaleString(translationKey, session.locale());
addJavaOnlyEnchantment(session, builder, enchantmentTranslation, level);
return null;
}
if (enchantment == null) {
Expand All @@ -242,11 +254,10 @@ public void translateNbtToJava(@NonNull NbtMap bedrockTag, @NonNull DataComponen
.build();
}

private void addSweeping(GeyserSession session, BedrockItemBuilder builder, int level) {
String sweepingTranslation = MinecraftLocale.getLocaleString("enchantment.minecraft.sweeping", session.locale());
private void addJavaOnlyEnchantment(GeyserSession session, BedrockItemBuilder builder, String enchantmentName, int level) {
String lvlTranslation = MinecraftLocale.getLocaleString("enchantment.level." + level, session.locale());

builder.getOrCreateLore().add(ChatColor.RESET + ChatColor.GRAY + sweepingTranslation + " " + lvlTranslation);
builder.getOrCreateLore().add(ChatColor.RESET + ChatColor.GRAY + enchantmentName + " " + lvlTranslation);
}

/* Translation methods end */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@

package org.geysermc.geyser.network;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.DefaultThreadFactory;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.protocol.bedrock.BedrockPeer;
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec;
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.session.GeyserSession;

import java.net.InetSocketAddress;
Expand Down Expand Up @@ -72,7 +68,6 @@ public void initSession(@NonNull BedrockServerSession bedrockServerSession) {
channel.pipeline().addAfter(BedrockPacketCodec.NAME, InvalidPacketHandler.NAME, new InvalidPacketHandler(session));

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.cloudburstmc.protocol.common.util.Zlib;
import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.bedrock.SessionInitializeEvent;
import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.api.pack.PackCodec;
import org.geysermc.geyser.api.pack.ResourcePack;
Expand Down Expand Up @@ -189,6 +190,9 @@ public PacketSignal handle(LoginPacket loginPacket) {
return PacketSignal.HANDLED;
}

// Fire SessionInitializeEvent here as we now know the client data
geyser.eventBus().fire(new SessionInitializeEvent(session));

PlayStatusPacket playStatus = new PlayStatusPacket();
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
session.sendUpstreamPacket(playStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,11 @@ public void disconnect(String reason) {
if (!closed) {
loggedIn = false;

// Fire SessionDisconnectEvent
SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, reason);
geyser.getEventBus().fire(disconnectEvent);
if (authData != null && clientData != null) { // can occur if player disconnects before Bedrock auth finishes
// Fire SessionDisconnectEvent
geyser.getEventBus().fire(disconnectEvent);
}

// Disconnect downstream if necessary
if (downstream != null) {
Expand Down Expand Up @@ -1455,7 +1457,7 @@ public void requestOffhandSwap() {

@Override
public String name() {
return null;
return playerEntity != null ? javaUsername() : bedrockUsername();
}

@Override
Expand Down Expand Up @@ -1992,12 +1994,12 @@ public float getEyeHeight() {

@Override
public @MonotonicNonNull String javaUsername() {
return playerEntity.getUsername();
return playerEntity != null ? playerEntity.getUsername() : null;
}

@Override
public UUID javaUuid() {
return playerEntity.getUuid();
return playerEntity != null ? playerEntity.getUuid() : null ;
}

@Override
Expand Down

0 comments on commit 6413e4b

Please sign in to comment.