From 2a07e0587735ad6f9a8a634eca62016e53978e04 Mon Sep 17 00:00:00 2001 From: Ryan Hecht Date: Wed, 24 Jul 2019 21:44:15 -0700 Subject: [PATCH 1/3] Refactored Java packets to follow package structure of MCProtocolLib, removed redundant 'JavaTimeTranslator' --- .../translators/java/JavaTimeTranslator.java | 42 ------------------- .../JavaEntityPositionRotationTranslator.java | 0 .../JavaEntityPositionTranslator.java | 0 .../JavaEntityTeleportTranslator.java | 0 .../JavaEntityVelocityTranslator.java | 0 .../JavaNotifyClientTranslator.java | 0 .../{ => world}/JavaUpdateTimeTranslator.java | 0 7 files changed, 42 deletions(-) delete mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTimeTranslator.java rename connector/src/main/java/org/geysermc/connector/network/translators/java/{ => entity}/JavaEntityPositionRotationTranslator.java (100%) rename connector/src/main/java/org/geysermc/connector/network/translators/java/{ => entity}/JavaEntityPositionTranslator.java (100%) rename connector/src/main/java/org/geysermc/connector/network/translators/java/{ => entity}/JavaEntityTeleportTranslator.java (100%) rename connector/src/main/java/org/geysermc/connector/network/translators/java/{ => entity}/JavaEntityVelocityTranslator.java (100%) rename connector/src/main/java/org/geysermc/connector/network/translators/java/{ => world}/JavaNotifyClientTranslator.java (100%) rename connector/src/main/java/org/geysermc/connector/network/translators/java/{ => world}/JavaUpdateTimeTranslator.java (100%) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTimeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTimeTranslator.java deleted file mode 100644 index 52faa89da..000000000 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTimeTranslator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.network.translators.java; - -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; -import com.nukkitx.protocol.bedrock.packet.SetTimePacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; - -public class JavaTimeTranslator extends PacketTranslator { - - @Override - public void translate(ServerUpdateTimePacket packet, GeyserSession session) { - SetTimePacket setTimePacket = new SetTimePacket(); - setTimePacket.setTime((int) Math.abs(packet.getTime())); - - session.getUpstream().sendPacket(setTimePacket); - } -} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java similarity index 100% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityPositionRotationTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java similarity index 100% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityPositionTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityTeleportTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java similarity index 100% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityTeleportTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityVelocityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java similarity index 100% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/JavaEntityVelocityTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java similarity index 100% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/JavaNotifyClientTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaUpdateTimeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java similarity index 100% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/JavaUpdateTimeTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java From 39bc9baf160011c6c83c59dd7609ee103486a3e5 Mon Sep 17 00:00:00 2001 From: Ryan Hecht Date: Wed, 24 Jul 2019 22:03:59 -0700 Subject: [PATCH 2/3] Added JavaEntityDestoryTranslator and JavaSpawnExpOrbTranslator --- .../network/translators/TranslatorsInit.java | 18 ++++---- .../entity/JavaEntityDestroyTranslator.java | 45 +++++++++++++++++++ .../spawn/JavaSpawnExpOrbTranslator.java | 19 ++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java 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 d1b629d21..2e79a5ed9 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 @@ -28,10 +28,8 @@ package org.geysermc.connector.network.translators; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; import com.nukkitx.nbt.CompoundTagBuilder; @@ -45,14 +43,12 @@ import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslat import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator; import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator; import org.geysermc.connector.network.translators.java.JavaChatTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityPositionRotationTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityPositionTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityTeleportTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityVelocityTranslator; +import org.geysermc.connector.network.translators.java.entity.*; import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator; -import org.geysermc.connector.network.translators.java.JavaNotifyClientTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnExpOrbTranslator; +import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator; import org.geysermc.connector.network.translators.java.JavaTitleTranslator; -import org.geysermc.connector.network.translators.java.JavaUpdateTimeTranslator; +import org.geysermc.connector.network.translators.java.world.JavaUpdateTimeTranslator; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -86,6 +82,8 @@ public class TranslatorsInit { Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator()); Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator()); Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator()); + Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator()); + Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator()); Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java new file mode 100644 index 000000000..a9885d330 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.network.translators.java.entity; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket; +import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaEntityDestroyTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityDestroyPacket packet, GeyserSession session) { + for (int entityId : packet.getEntityIds()) { + RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket(); + removeEntityPacket.setUniqueEntityId(entityId); + + session.getUpstream().sendPacket(removeEntityPacket); + } + } +} + diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java new file mode 100644 index 000000000..c7f754dce --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java @@ -0,0 +1,19 @@ +package org.geysermc.connector.network.translators.java.entity.spawn; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; +import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaSpawnExpOrbTranslator extends PacketTranslator { + + @Override + public void translate(ServerSpawnExpOrbPacket packet, GeyserSession session) { + SpawnExperienceOrbPacket spawnExperienceOrbPacket = new SpawnExperienceOrbPacket(); + spawnExperienceOrbPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ())); + spawnExperienceOrbPacket.setAmount(packet.getExp()); + + session.getUpstream().sendPacket(spawnExperienceOrbPacket); + } +} From bbacbfdf66eadbc5150a9d10104c64d340b18438 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Thu, 25 Jul 2019 23:26:42 -0500 Subject: [PATCH 3/3] Fix invalid package declarations --- .../connector/network/translators/TranslatorsInit.java | 6 +++++- .../java/entity/JavaEntityPositionRotationTranslator.java | 2 +- .../java/entity/JavaEntityPositionTranslator.java | 2 +- .../java/entity/JavaEntityTeleportTranslator.java | 2 +- .../java/entity/JavaEntityVelocityTranslator.java | 2 +- .../translators/java/world/JavaNotifyClientTranslator.java | 2 +- .../translators/java/world/JavaUpdateTimeTranslator.java | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) 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 2e79a5ed9..0e882df1c 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 @@ -43,8 +43,12 @@ import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslat import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator; import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator; import org.geysermc.connector.network.translators.java.JavaChatTranslator; -import org.geysermc.connector.network.translators.java.entity.*; import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityDestroyTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityPositionRotationTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityPositionTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityTeleportTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityVelocityTranslator; import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnExpOrbTranslator; import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator; import org.geysermc.connector.network.translators.java.JavaTitleTranslator; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java index e8414f487..713a24323 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java; +package org.geysermc.connector.network.translators.java.entity; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java index ccdbb9d9a..a79b9d720 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java; +package org.geysermc.connector.network.translators.java.entity; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java index 694c48f9f..c5ec98fc0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java; +package org.geysermc.connector.network.translators.java.entity; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java index 43bfe3552..ef96e2f50 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java; +package org.geysermc.connector.network.translators.java.entity; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java index 8aade7e32..65c25a1d3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java; +package org.geysermc.connector.network.translators.java.world; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java index 27eb8151f..3e9cc40c8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java; +package org.geysermc.connector.network.translators.java.world; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; import com.nukkitx.protocol.bedrock.packet.SetTimePacket;