From a7bd9da6448a532f20d8cdcea0fa20410279386f Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 5 Oct 2019 00:29:33 +0200 Subject: [PATCH] Bugfixes --- .../org/geysermc/connector/entity/Entity.java | 2 +- .../geysermc/connector/entity/PlayerEntity.java | 13 +++++++++++++ .../network/session/UpstreamSession.java | 17 +++++++++++++++++ .../network/translators/TranslatorsInit.java | 2 +- .../bedrock/BedrockMovePlayerTranslator.java | 10 ++++++++-- ... => BedrockPlayerInitializedTranslator.java} | 2 +- .../translators/java/JavaBossBarTranslator.java | 2 +- .../connector/scoreboard/Scoreboard.java | 2 +- 8 files changed, 43 insertions(+), 7 deletions(-) rename connector/src/main/java/org/geysermc/connector/network/translators/bedrock/{BedrockPlayerInitialized.java => BedrockPlayerInitializedTranslator.java} (82%) 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 fb3c3d5c8..d70478a04 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -137,7 +137,7 @@ public class Entity { public EntityDataDictionary getMetadata() { EntityFlags flags = new EntityFlags(); - flags.setFlag(EntityFlag.HAS_GRAVITY, true); + flags.setFlag(EntityFlag.HAS_GRAVITY, !is(PlayerEntity.class) || as(PlayerEntity.class).isGravity()); flags.setFlag(EntityFlag.HAS_COLLISION, true); flags.setFlag(EntityFlag.CAN_SHOW_NAME, true); flags.setFlag(EntityFlag.CAN_CLIMB, true); diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index a108d988f..0b9f41801 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -30,6 +30,7 @@ import com.github.steveice10.mc.auth.data.GameProfile; import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import lombok.Getter; import lombok.Setter; import org.geysermc.connector.entity.type.EntityType; @@ -44,6 +45,7 @@ public class PlayerEntity extends Entity { private String username; private long lastSkinUpdate = -1; private boolean playerList = true; + private boolean gravity = false; private ItemData helmet; private ItemData chestplate; @@ -74,6 +76,17 @@ public class PlayerEntity extends Entity { session.getUpstream().sendPacket(armorEquipmentPacket); } + public void enableGravity(GeyserSession session) { + if (!gravity && session.getPlayerEntity().getGeyserId() == getGeyserId()) { + gravity = true; + + SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); + entityDataPacket.setRuntimeEntityId(geyserId); + entityDataPacket.getMetadata().putAll(getMetadata()); + session.getUpstream().sendPacket(entityDataPacket); + } + } + @Override public boolean despawnEntity(GeyserSession session) { super.despawnEntity(session); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java b/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java index ab3a0e0c5..af475e5c8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java @@ -16,6 +16,7 @@ public class UpstreamSession { @Getter private final BedrockServerSession session; private Queue packets = new ConcurrentLinkedQueue<>(); @Getter private boolean frozen = false; + private boolean queueCleared = true; public void sendPacket(@NonNull BedrockPacket packet) { if (frozen || !packets.isEmpty()) { @@ -55,4 +56,20 @@ public class UpstreamSession { public InetSocketAddress getAddress() { return session.getAddress(); } + + public boolean hasQueue() { + return !packets.isEmpty(); + } + + /** + * @return true the first time this method is called after the queue is empty.
+ * This will enable gravity because now the client is ready to explore + */ + public boolean isQueueCleared() { + if (!hasQueue() && queueCleared) { + queueCleared = false; + return true; + } + return false; + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 8c80ac3b4..5f3569dcf 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -153,7 +153,7 @@ public class TranslatorsInit { Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator()); Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator()); Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator()); - Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitialized()); + Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator()); Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator()); itemTranslator = new ItemTranslator(); 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 3891af6f8..ad7645a4a 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,18 +31,24 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.item.BedrockItem; public class BedrockMovePlayerTranslator extends PacketTranslator { - @Override public void translate(MovePlayerPacket packet, GeyserSession session) { - Entity entity = session.getPlayerEntity(); + PlayerEntity entity = session.getPlayerEntity(); if (entity == null || !session.isSpawned()) return; + // can cause invalid moves when packet queue is not empty + if (session.getUpstream().hasQueue()) return; + if (session.getUpstream().isQueueCleared()) { + entity.enableGravity(session); + } + if (!isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) { session.getConnector().getLogger().info("Recalculating position..."); recalculatePosition(session, entity, entity.getPosition()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitialized.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java similarity index 82% rename from connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitialized.java rename to connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java index 63f4d94bf..c4f5a0793 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitialized.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java @@ -4,7 +4,7 @@ import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; -public class BedrockPlayerInitialized extends PacketTranslator { +public class BedrockPlayerInitializedTranslator extends PacketTranslator { @Override public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession session) { if (session.getPlayerEntity().getGeyserId() == packet.getRuntimeEntityId()) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java index be8cdd728..8b89e3be3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java @@ -34,7 +34,7 @@ public class JavaBossBarTranslator extends PacketTranslator bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle())); break; case UPDATE_HEALTH: - bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE); + bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE); bossEventPacket.setHealthPercentage(packet.getHealth()); break; case REMOVE: diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java index 948da13ae..bb014ad4f 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java @@ -142,7 +142,7 @@ public class Scoreboard { boolean teamAdd = team != null && (team.getUpdateType() == ADD || team.getUpdateType() == UPDATE); boolean teamRemove = team != null && (team.getUpdateType() == REMOVE || team.getUpdateType() == UPDATE); - if (team != null && (team.getUpdateType() == REMOVE || inTeam)) score.setTeam(null); + if (team != null && (team.getUpdateType() == REMOVE || !inTeam)) score.setTeam(null); boolean add = (hasUpdate || globalAdd || teamAdd || teamRemove || score.getUpdateType() == ADD || score.getUpdateType() == UPDATE) && (score.getUpdateType() != REMOVE); boolean remove = hasUpdate || globalRemove || teamAdd || teamRemove || score.getUpdateType() == REMOVE || score.getUpdateType() == UPDATE;