From 0ac89f4880dec5f6149fe45543065c6411c96d4d Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 15 Oct 2019 21:47:28 -0500 Subject: [PATCH] Implement dimension changing and debugize 'moved too quickly' messages --- .../org/geysermc/connector/entity/Entity.java | 2 ++ .../bedrock/BedrockMovePlayerTranslator.java | 9 ++--- .../java/JavaJoinGameTranslator.java | 1 - .../java/JavaRespawnTranslator.java | 34 ++++++++++++++++--- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index af8e4e31..69dcaf0f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -82,6 +82,7 @@ public class Entity { this.valid = false; this.movePending = false; + this.dimension = 0; } public void spawnEntity(GeyserSession session) { @@ -132,6 +133,7 @@ public class Entity { public void moveAbsolute(Vector3f position, Vector3f rotation) { setPosition(position); setRotation(rotation); + this.movePending = true; } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java index 2b85bcf2..51082170 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java @@ -31,6 +31,7 @@ import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import org.geysermc.api.ChatColor; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.type.EntityType; @@ -39,12 +40,12 @@ import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.block.BlockEntry; public class BedrockMovePlayerTranslator extends PacketTranslator { + @Override public void translate(MovePlayerPacket packet, GeyserSession session) { PlayerEntity entity = session.getPlayerEntity(); if (entity == null || !session.isSpawned()) return; - // can cause invalid moves when packet queue is not empty if (!session.getUpstream().isInitialized()) { MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket(); moveEntityBack.setRuntimeEntityId(entity.getGeyserId()); @@ -57,7 +58,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator 100) { - session.getConnector().getLogger().warning(session.getName() + " moved too quickly." + + session.getConnector().getLogger().debug(ChatColor.RED + session.getName() + " moved too quickly." + " current position: " + currentPosition + ", new position: " + newPosition); return false; @@ -122,7 +123,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x) ChunkRadiusUpdatedPacket packet1 = new ChunkRadiusUpdatedPacket(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java index 30e2135b..f5f86e19 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java @@ -26,7 +26,9 @@ package org.geysermc.connector.network.translators.java; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket; +import com.nukkitx.protocol.bedrock.packet.ChangeDimensionPacket; import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -39,10 +41,34 @@ public class JavaRespawnTranslator extends PacketTranslator if (entity == null) return; - if (entity.getDimension() == packet.getDimension()) { - PlayStatusPacket playStatusPacket = new PlayStatusPacket(); - playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); - session.getUpstream().sendPacket(playStatusPacket); + if (entity.getDimension() == getDimension(packet.getDimension())) + return; + + entity.setDimension(getDimension(packet.getDimension())); + + ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket(); + changeDimensionPacket.setDimension(getDimension(packet.getDimension())); + changeDimensionPacket.setRespawn(false); + changeDimensionPacket.setPosition(entity.getPosition()); + session.getUpstream().sendPacket(changeDimensionPacket); + + SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); + playerGameTypePacket.setGamemode(packet.getGamemode().ordinal()); + session.getUpstream().sendPacket(playerGameTypePacket); + + PlayStatusPacket playStatusPacket = new PlayStatusPacket(); + playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); + session.getUpstream().sendPacket(playStatusPacket); + } + + private int getDimension(int javaDimension) { + switch (javaDimension) { + case -1: + return 1; + case 1: + return 2; } + + return javaDimension; } }