Skip to content

Commit

Permalink
Merge Changes from upstream
Browse files Browse the repository at this point in the history
* Fix up some legacy custom skull stuff as upstream now provides this
* Merge branch 'feature/plugins' into bleeding

# Conflicts:
#	connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java
#	connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
#	connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java
#	connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java
#	connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java
#	connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockStateValues.java
#	connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/SkullBlockEntityTranslator.java
#	connector/src/main/java/org/geysermc/connector/skin/SkinManager.java
#	connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java
  • Loading branch information
bundabrg committed Dec 8, 2020
2 parents 43915d7 + 30caf2c commit 2f82640
Show file tree
Hide file tree
Showing 66 changed files with 720 additions and 461 deletions.
1 change: 0 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
path: target/site/

documentation:
if: startsWith(github.ref,'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@
@AllArgsConstructor
public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener {

private static final GeyserPendingConnection PENDING_CONNECTION = new GeyserPendingConnection();

private final ProxyServer proxyServer;

@Override
public GeyserPingInfo getPingInformation() {
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
CompletableFuture<ProxyPingEvent> future = new CompletableFuture<>();
proxyServer.getPluginManager().callEvent(new ProxyPingEvent(PENDING_CONNECTION, getPingInfo(), (event, throwable) -> {
proxyServer.getPluginManager().callEvent(new ProxyPingEvent(new GeyserPendingConnection(inetSocketAddress), getPingInfo(), (event, throwable) -> {
if (throwable != null) future.completeExceptionally(throwable);
else future.complete(event);
}));
Expand Down Expand Up @@ -89,7 +87,12 @@ private ServerPing getPingInfo() {
private static class GeyserPendingConnection implements PendingConnection {

private static final UUID FAKE_UUID = UUID.nameUUIDFromBytes("geyser!internal".getBytes());
private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69);

private final InetSocketAddress remote;

public GeyserPendingConnection(InetSocketAddress remote) {
this.remote = remote;
}

@Override
public String getName() {
Expand Down Expand Up @@ -143,7 +146,7 @@ public boolean isLegacy() {

@Override
public InetSocketAddress getAddress() {
return FAKE_REMOTE;
return remote;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.geysermc.connector.ping.IGeyserPingPassthrough;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.Iterator;

Expand All @@ -44,9 +45,9 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
private final GeyserSpigotLogger logger;

@Override
public GeyserPingInfo getPingInformation() {
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
try {
ServerListPingEvent event = new GeyserPingEvent(InetAddress.getLocalHost(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers());
ServerListPingEvent event = new GeyserPingEvent(inetSocketAddress.getAddress(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers());
Bukkit.getPluginManager().callEvent(event);
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(event.getMotd(),
new GeyserPingInfo.Players(event.getMaxPlayers(), event.getNumPlayers()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,29 @@
import org.spongepowered.api.profile.GameProfile;

import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.util.Optional;

public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough {

private static final GeyserStatusClient STATUS_CLIENT = new GeyserStatusClient();
private static final Cause CAUSE = Cause.of(EventContext.empty(), Sponge.getServer());

private static Method SpongeStatusResponse_create;

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public GeyserPingInfo getPingInformation() {
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
// come on Sponge, this is in commons, why not expose it :(
ClientPingServerEvent event;
try {
if(SpongeStatusResponse_create == null) {
if (SpongeStatusResponse_create == null) {
Class SpongeStatusResponse = Class.forName("org.spongepowered.common.network.status.SpongeStatusResponse");
Class MinecraftServer = Class.forName("net.minecraft.server.MinecraftServer");
SpongeStatusResponse_create = SpongeStatusResponse.getDeclaredMethod("create", MinecraftServer);
}

Object response = SpongeStatusResponse_create.invoke(null, Sponge.getServer());
event = SpongeEventFactory.createClientPingServerEvent(CAUSE, STATUS_CLIENT, (ClientPingServerEvent.Response) response);
event = SpongeEventFactory.createClientPingServerEvent(CAUSE, new GeyserStatusClient(inetSocketAddress), (ClientPingServerEvent.Response) response);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
Expand All @@ -76,7 +74,7 @@ public GeyserPingInfo getPingInformation() {
new GeyserPingInfo.Version(
event.getResponse().getVersion().getName(),
MinecraftConstants.PROTOCOL_VERSION) // thanks for also not exposing this sponge
);
);
event.getResponse().getPlayers().get().getProfiles().stream()
.map(GameProfile::getName)
.map(op -> op.orElseThrow(IllegalStateException::new))
Expand All @@ -87,11 +85,15 @@ public GeyserPingInfo getPingInformation() {
@SuppressWarnings("NullableProblems")
private static class GeyserStatusClient implements StatusClient {

private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69);
private final InetSocketAddress remote;

public GeyserStatusClient(InetSocketAddress remote) {
this.remote = remote;
}

@Override
public InetSocketAddress getAddress() {
return FAKE_REMOTE;
return this.remote;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ public void onEnable() {
}
} catch (IOException ex) {
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.config.failed"), ex);
System.exit(0);
if (gui == null) {
System.exit(1);
} else {
// Leave the process running so the GUI is still visible
return;
}
}
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@
@AllArgsConstructor
public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough {

private static final GeyserInboundConnection FAKE_INBOUND_CONNECTION = new GeyserInboundConnection();

private final ProxyServer server;

@Override
public GeyserPingInfo getPingInformation() {
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
ProxyPingEvent event;
try {
event = server.getEventManager().fire(new ProxyPingEvent(FAKE_INBOUND_CONNECTION, ServerPing.builder()
event = server.getEventManager().fire(new ProxyPingEvent(new GeyserInboundConnection(inetSocketAddress), ServerPing.builder()
.description(server.getConfiguration().getMotdComponent()).onlinePlayers(server.getPlayerCount())
.maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get();
} catch (ExecutionException | InterruptedException e) {
Expand All @@ -74,11 +72,15 @@ public GeyserPingInfo getPingInformation() {

private static class GeyserInboundConnection implements InboundConnection {

private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69);
private final InetSocketAddress remote;

public GeyserInboundConnection(InetSocketAddress remote) {
this.remote = remote;
}

@Override
public InetSocketAddress getRemoteAddress() {
return FAKE_REMOTE;
return this.remote;
}

@Override
Expand Down
18 changes: 11 additions & 7 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>86e1901be5</version>
<version>26201a4</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
<exclusion>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -136,21 +140,21 @@
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.github.kyoripowered.adventure</groupId>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>7acd956</version>
<version>4.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.kyoripowered.adventure</groupId>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>7acd956</version>
<version>4.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.kyoripowered.adventure</groupId>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>7acd956</version>
<version>4.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
import org.geysermc.connector.network.translators.collision.CollisionTranslator;
import org.geysermc.connector.network.translators.world.block.entity.SkullBlockEntityTranslator;
import org.geysermc.connector.event.events.geyser.GeyserStopEvent;
import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.LanguageUtils;
Expand Down Expand Up @@ -197,6 +198,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
authType = AuthType.getByName(config.getRemote().getAuthType());

DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls();

// https://github.com/GeyserMC/Geyser/issues/957
RakNetConstants.MAXIMUM_MTU_SIZE = (short) config.getMtu();
Expand All @@ -215,7 +217,6 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {

if (config.getMetrics().isEnabled()) {
metrics = new Metrics(this, "GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger(""));
metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1));
metrics.addCustomChart(new Metrics.SingleLineChart("players", players::size));
// Prevent unwanted words best we can
metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> AuthType.getByName(config.getRemote().getAuthType()).toString().toLowerCase()));
Expand Down Expand Up @@ -396,7 +397,7 @@ public void registerPluginChannel(String channel) {
}

registeredPluginChannels.add(channel);
for ( GeyserSession session : players) {
for (GeyserSession session : players) {
session.registerPluginChannel(channel);
}
}
Expand All @@ -415,7 +416,7 @@ public void unregisterPluginChannel(String channel) {
}

registeredPluginChannels.remove(channel);
for ( GeyserSession session : players ) {
for (GeyserSession session : players) {
session.unregisterPluginChannel(channel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
@JsonProperty("cache-chunks")
private boolean cacheChunks = false;

@JsonProperty("allow-custom-skulls")
private boolean allowCustomSkulls;

@JsonProperty("cache-images")
private int cacheImages = 0;

@JsonProperty("allow-custom-skulls")
private boolean allowCustomSkulls = true;

@JsonProperty("above-bedrock-nether-building")
private boolean aboveBedrockNetherBuilding = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import net.kyori.adventure.text.Component;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
Expand All @@ -50,7 +51,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
metadata.put(EntityData.COMMAND_BLOCK_COMMAND, entityMetadata.getValue());
}
if (entityMetadata.getId() == 14) {
metadata.put(EntityData.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage(entityMetadata.getValue().toString()));
metadata.put(EntityData.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage((Component) entityMetadata.getValue()));
}
super.updateBedrockMetadata(entityMetadata, session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
import com.github.steveice10.mc.protocol.data.message.Message;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3f;
Expand All @@ -45,6 +44,7 @@
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import org.geysermc.connector.entity.attribute.Attribute;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.entity.living.ArmorStandEntity;
Expand Down Expand Up @@ -317,11 +317,11 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}
break;
case 2: // custom name
if (entityMetadata.getValue() instanceof Message) {
Message message = (Message) entityMetadata.getValue();
if (entityMetadata.getValue() instanceof Component) {
Component message = (Component) entityMetadata.getValue();
if (message != null)
// Always translate even if it's a TextMessage since there could be translatable parameters
metadata.put(EntityData.NAMETAG, MessageTranslator.convertMessage(message.toString(), session.getLocale()));
metadata.put(EntityData.NAMETAG, MessageTranslator.convertMessage(message, session.getLocale()));
}
break;
case 3: // is custom name visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
// Relies on EntityData.OWNER_EID being set in TameableEntity.java
if (entityMetadata.getId() == 19 && !metadata.getFlags().getFlag(EntityFlag.ANGRY)) {
metadata.put(EntityData.COLOR, collarColor = (byte) (int) entityMetadata.getValue());
if (!metadata.containsKey(EntityData.OWNER_EID)) {
// If a color is set and there is no owner entity ID, set one.
// Otherwise, the entire wolf is set to that color: https://user-images.githubusercontent.com/9083212/99209989-92691200-2792-11eb-911d-9a315c955be9.png
metadata.put(EntityData.OWNER_EID, session.getPlayerEntity().getGeyserId());
}
}

// Wolf anger (1.16+)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.message.TextMessage;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
Expand All @@ -39,11 +38,11 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.LivingEntity;
import org.geysermc.connector.entity.attribute.Attribute;
Expand All @@ -54,8 +53,6 @@
import org.geysermc.connector.scoreboard.Team;
import org.geysermc.connector.utils.AttributeUtils;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.utils.SkinProvider;
import org.geysermc.connector.utils.SkinUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -69,7 +66,6 @@ public class PlayerEntity extends LivingEntity {
private UUID uuid;
private String username;
private String displayName;
private long lastSkinUpdate = -1;
private boolean playerList = true; // Player is in the player list

/**
Expand Down Expand Up @@ -259,9 +255,9 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s

if (entityMetadata.getId() == 2) {
String username = this.username;
TextMessage name = (TextMessage) entityMetadata.getValue();
Component name = (Component) entityMetadata.getValue();
if (name != null) {
username = MessageTranslator.convertMessage(name.toString());
username = MessageTranslator.convertMessage(name);
}
Team team = session.getWorldCache().getScoreboard().getTeamFor(username);
if (team != null) {
Expand Down
Loading

0 comments on commit 2f82640

Please sign in to comment.