translator) {
- BEDROCK.MAP.put(clazz, translator);
+ public static void registerBedrock(Class extends BedrockPacket> targetPacket, PacketTranslator extends BedrockPacket> translator) {
+ BEDROCK.MAP.put(targetPacket, translator);
}
+ @SuppressWarnings("unchecked")
public boolean translate(Class extends P> clazz, P packet, GeyserSession session) {
if (!session.getUpstream().isClosed() && !session.isClosed()) {
try {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Translator.java b/connector/src/main/java/org/geysermc/connector/network/translators/Translator.java
new file mode 100644
index 000000000..8e097ba4d
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/Translator.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019-2020 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;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface Translator {
+ Class> packet();
+
+}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java b/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java
new file mode 100644
index 000000000..d4e5dae8b
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2019-2020 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;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.geysermc.connector.GeyserConnector;
+import org.geysermc.connector.network.translators.block.BlockTranslator;
+import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
+import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
+import org.geysermc.connector.network.translators.item.ItemTranslator;
+import org.reflections.Reflections;
+
+import com.github.steveice10.packetlib.packet.Packet;
+import com.nukkitx.nbt.CompoundTagBuilder;
+import com.nukkitx.nbt.NbtUtils;
+import com.nukkitx.nbt.stream.NBTOutputStream;
+import com.nukkitx.nbt.tag.CompoundTag;
+import com.nukkitx.protocol.bedrock.BedrockPacket;
+
+import lombok.Getter;
+
+public class Translators {
+
+ @Getter
+ private static ItemTranslator itemTranslator;
+
+ @Getter
+ private static InventoryTranslator inventoryTranslator = new GenericInventoryTranslator();
+
+ private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
+ public static final byte[] EMPTY_LEVEL_CHUNK_DATA;
+
+ static {
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+ outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size
+
+ try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) {
+ stream.write(EMPTY_TAG);
+ }
+
+ EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray();
+ }catch (IOException e) {
+ throw new AssertionError("Unable to generate empty level chunk data");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void start() {
+ Reflections ref = new Reflections("org.geysermc.connector.network.translators");
+
+ for (Class> clazz : ref.getTypesAnnotatedWith(Translator.class)) {
+ Class> packet = clazz.getAnnotation(Translator.class).packet();
+
+ GeyserConnector.getInstance().getLogger().debug("Found annotated translator: " + clazz.getCanonicalName() + " : " + packet.getSimpleName());
+
+ try {
+ if (Packet.class.isAssignableFrom(packet)) {
+ Class extends Packet> targetPacket = (Class extends Packet>) packet;
+ PacketTranslator extends Packet> translator = (PacketTranslator extends Packet>) clazz.newInstance();
+
+ Registry.registerJava(targetPacket, translator);
+
+ } else if (BedrockPacket.class.isAssignableFrom(packet)) {
+ Class extends BedrockPacket> targetPacket = (Class extends BedrockPacket>) packet;
+ PacketTranslator extends BedrockPacket> translator = (PacketTranslator extends BedrockPacket>) clazz.newInstance();
+
+ Registry.registerBedrock(targetPacket, translator);
+
+ } else {
+ GeyserConnector.getInstance().getLogger().error("Class " + clazz.getCanonicalName() + " is annotated as a translator but has an invalid target packet.");
+ }
+ } catch (InstantiationException | IllegalAccessException e) {
+ GeyserConnector.getInstance().getLogger().error("Could not instantiate annotated translator " + clazz.getCanonicalName() + ".");
+ }
+ }
+
+ itemTranslator = new ItemTranslator();
+ BlockTranslator.init();
+
+ registerInventoryTranslators();
+ }
+
+ private static void registerInventoryTranslators() {
+ /*inventoryTranslators.put(WindowType.GENERIC_9X1, new GenericInventoryTranslator());
+ inventoryTranslators.put(WindowType.GENERIC_9X2, new GenericInventoryTranslator());
+ inventoryTranslators.put(WindowType.GENERIC_9X3, new GenericInventoryTranslator());
+ inventoryTranslators.put(WindowType.GENERIC_9X4, new GenericInventoryTranslator());
+ inventoryTranslators.put(WindowType.GENERIC_9X5, new GenericInventoryTranslator());
+ inventoryTranslators.put(WindowType.GENERIC_9X6, new GenericInventoryTranslator());*/
+ }
+}
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
deleted file mode 100644
index 3cba0151f..000000000
--- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (c) 2019-2020 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;
-
-import com.github.steveice10.mc.protocol.packet.ingame.server.*;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.*;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.*;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.world.*;
-import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket;
-import com.nukkitx.nbt.CompoundTagBuilder;
-import com.nukkitx.nbt.NbtUtils;
-import com.nukkitx.nbt.stream.NBTOutputStream;
-import com.nukkitx.nbt.tag.CompoundTag;
-import com.nukkitx.protocol.bedrock.packet.*;
-import lombok.Getter;
-import org.geysermc.connector.network.translators.bedrock.*;
-import org.geysermc.connector.network.translators.block.BlockTranslator;
-import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
-import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
-import org.geysermc.connector.network.translators.item.ItemTranslator;
-import org.geysermc.connector.network.translators.java.*;
-import org.geysermc.connector.network.translators.java.entity.*;
-import org.geysermc.connector.network.translators.java.entity.player.*;
-import org.geysermc.connector.network.translators.java.entity.spawn.*;
-import org.geysermc.connector.network.translators.java.inventory.OpenWindowPacketTranslator;
-import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator;
-import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator;
-import org.geysermc.connector.network.translators.java.scoreboard.JavaTeamTranslator;
-import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator;
-import org.geysermc.connector.network.translators.java.window.JavaOpenWindowTranslator;
-import org.geysermc.connector.network.translators.java.window.JavaSetSlotTranslator;
-import org.geysermc.connector.network.translators.java.window.JavaWindowItemsTranslator;
-import org.geysermc.connector.network.translators.java.world.*;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-public class TranslatorsInit {
-
- @Getter
- private static ItemTranslator itemTranslator;
-
- @Getter
- private static InventoryTranslator inventoryTranslator = new GenericInventoryTranslator();
-
- private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
- public static final byte[] EMPTY_LEVEL_CHUNK_DATA;
-
- static {
- try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
- outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size
-
- try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) {
- stream.write(EMPTY_TAG);
- }
-
- EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray();
- }catch (IOException e) {
- throw new AssertionError("Unable to generate empty level chunk data");
- }
- }
-
- public static void start() {
- Registry.registerJava(LoginPluginRequestPacket.class, new JavaLoginPluginMessageTranslator());
-
- Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator());
- Registry.registerJava(ServerPluginMessagePacket.class, new JavaPluginMessageTranslator());
- Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator());
- Registry.registerJava(ServerTitlePacket.class, new JavaTitleTranslator());
- Registry.registerJava(ServerUpdateTimePacket.class, new JavaUpdateTimeTranslator());
- Registry.registerJava(ServerRespawnPacket.class, new JavaRespawnTranslator());
- Registry.registerJava(ServerSpawnPositionPacket.class, new JavaSpawnPositionTranslator());
- Registry.registerJava(ServerDifficultyPacket.class, new JavaDifficultyTranslator());
-
- Registry.registerJava(ServerEntityAnimationPacket.class, new JavaEntityAnimationTranslator());
- Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator());
- Registry.registerJava(ServerEntityPositionRotationPacket.class, new JavaEntityPositionRotationTranslator());
- Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator());
- Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator());
- Registry.registerJava(ServerEntityPropertiesPacket.class, new JavaEntityPropertiesTranslator());
- Registry.registerJava(ServerEntityRotationPacket.class, new JavaEntityRotationTranslator());
- Registry.registerJava(ServerEntityHeadLookPacket.class, new JavaEntityHeadLookTranslator());
- Registry.registerJava(ServerEntityMetadataPacket.class, new JavaEntityMetadataTranslator());
- Registry.registerJava(ServerEntityStatusPacket.class, new JavaEntityStatusTranslator());
- Registry.registerJava(ServerEntityEquipmentPacket.class, new JavaEntityEquipmentTranslator());
- Registry.registerJava(ServerBossBarPacket.class, new JavaBossBarTranslator());
-
- Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator());
- Registry.registerJava(ServerSpawnGlobalEntityPacket.class, new JavaSpawnGlobalEntityTranslator());
- Registry.registerJava(ServerSpawnMobPacket.class, new JavaSpawnMobTranslator());
- Registry.registerJava(ServerSpawnObjectPacket.class, new JavaSpawnObjectTranslator());
- Registry.registerJava(ServerSpawnPaintingPacket.class, new JavaSpawnPaintingTranslator());
- Registry.registerJava(ServerSpawnPlayerPacket.class, new JavaSpawnPlayerTranslator());
- Registry.registerJava(ServerPlayerListEntryPacket.class, new JavaPlayerListEntryTranslator());
-
- Registry.registerJava(ServerPlayerPositionRotationPacket.class, new JavaPlayerPositionRotationTranslator());
- Registry.registerJava(ServerPlayerSetExperiencePacket.class, new JavaPlayerSetExperienceTranslator());
- Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
- Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
-
- Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
-
- Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
- Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
- Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator());
- Registry.registerJava(ServerWindowItemsPacket.class, new JavaWindowItemsTranslator());
- Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator());
- Registry.registerJava(ServerSetSlotPacket.class, new JavaSetSlotTranslator());
- Registry.registerJava(ServerScoreboardObjectivePacket.class, new JavaScoreboardObjectiveTranslator());
- Registry.registerJava(ServerDisplayScoreboardPacket.class, new JavaDisplayScoreboardTranslator());
- Registry.registerJava(ServerUpdateScorePacket.class, new JavaUpdateScoreTranslator());
- Registry.registerJava(ServerTeamPacket.class, new JavaTeamTranslator());
- Registry.registerJava(ServerBlockChangePacket.class, new JavaBlockChangeTranslator());
- Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator());
- Registry.registerJava(ServerUnloadChunkPacket.class, new JavaUnloadChunkTranslator());
-
- Registry.registerJava(ServerUpdateViewPositionPacket.class, new JavaUpdateViewPositionTranslator());
- Registry.registerJava(ServerUpdateViewDistancePacket.class, new JavaUpdateViewDistanceTranslator());
-
- Registry.registerJava(ServerOpenWindowPacket.class, new OpenWindowPacketTranslator());
-
- Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
- Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
- Registry.registerBedrock(InventoryTransactionPacket.class, new BedrockInventoryTransactionTranslator());
- Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator());
- Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
- Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
- Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator());
- Registry.registerBedrock(InteractPacket.class, new BedrockInteractTranslator());
- Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
- Registry.registerBedrock(RespawnPacket.class, new BedrockRespawnTranslator());
- Registry.registerBedrock(ShowCreditsPacket.class, new BedrockShowCreditsTranslator());
-
- itemTranslator = new ItemTranslator();
- BlockTranslator.init();
-
- registerInventoryTranslators();
- }
-
- private static void registerInventoryTranslators() {
- /*inventoryTranslators.put(WindowType.GENERIC_9X1, new GenericInventoryTranslator());
- inventoryTranslators.put(WindowType.GENERIC_9X2, new GenericInventoryTranslator());
- inventoryTranslators.put(WindowType.GENERIC_9X3, new GenericInventoryTranslator());
- inventoryTranslators.put(WindowType.GENERIC_9X4, new GenericInventoryTranslator());
- inventoryTranslators.put(WindowType.GENERIC_9X5, new GenericInventoryTranslator());
- inventoryTranslators.put(WindowType.GENERIC_9X6, new GenericInventoryTranslator());*/
- }
-}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java
index 98a580ee3..ebc45ff08 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java
@@ -25,6 +25,13 @@
package org.geysermc.connector.network.translators.bedrock;
+import java.util.concurrent.TimeUnit;
+
+import org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
@@ -36,12 +43,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
-import org.geysermc.connector.entity.Entity;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
-
-import java.util.concurrent.TimeUnit;
+@Translator(packet = PlayerActionPacket.class)
public class BedrockActionTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java
index a3b500806..7ccb24262 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java
@@ -25,20 +25,29 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket;
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
+import java.util.concurrent.TimeUnit;
+
+@Translator(packet = AnimatePacket.class)
public class BedrockAnimateTranslator extends PacketTranslator {
@Override
public void translate(AnimatePacket packet, GeyserSession session) {
switch (packet.getAction()) {
case SWING_ARM:
- ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND);
- session.getDownstream().getSession().send(swingArmPacket);
+ // Delay so entity damage can be processed first
+ session.getConnector().getGeneralThreadPool().schedule(() ->
+ session.getDownstream().getSession().send(new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)),
+ 25,
+ TimeUnit.MILLISECONDS
+ );
break;
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java
index 19d1a55f6..28cbf4c41 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java
@@ -25,20 +25,25 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.common.PlatformType;
+import org.geysermc.connector.GeyserConnector;
+import org.geysermc.connector.command.GeyserCommandMap;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
-import org.geysermc.connector.GeyserConnector;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
-
+@Translator(packet = CommandRequestPacket.class)
public class BedrockCommandRequestTranslator extends PacketTranslator {
@Override
public void translate(CommandRequestPacket packet, GeyserSession session) {
String command = packet.getCommand().replace("/", "");
- if (GeyserConnector.getInstance().getCommandMap().getCommands().containsKey(command)) {
- GeyserConnector.getInstance().getCommandMap().runCommand(session, command);
+ GeyserCommandMap commandMap = GeyserConnector.getInstance().getCommandMap();
+ if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandMap.getCommands().containsKey(command.split(" ")[1])) {
+ commandMap.runCommand(session, command);
} else {
ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand());
session.getDownstream().getSession().send(chatPacket);
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java
index ab73e9bb1..012ef90ea 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java
@@ -25,16 +25,17 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
-import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.InteractPacket;
-import org.geysermc.connector.entity.Entity;
-import org.geysermc.connector.entity.PlayerEntity;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
+@Translator(packet = InteractPacket.class)
public class BedrockInteractTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java
index 8b4364a7e..de23b8a05 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java
@@ -25,6 +25,11 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
@@ -36,10 +41,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
-import org.geysermc.connector.entity.Entity;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
+@Translator(packet = InventoryTransactionPacket.class)
public class BedrockInventoryTransactionTranslator extends PacketTranslator {
@Override
@@ -58,7 +61,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator {
@Override
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 0f13eff8b..0b5ab02bb 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
@@ -25,6 +25,14 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.common.ChatColor;
+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.Translator;
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
import com.nukkitx.math.GenericMath;
import com.nukkitx.math.vector.Vector3f;
@@ -32,13 +40,7 @@ import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
-import org.geysermc.common.ChatColor;
-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;
-
+@Translator(packet = MovePlayerPacket.class)
public class BedrockMovePlayerTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java
index a2422d342..fda2cade2 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java
@@ -25,14 +25,15 @@
package org.geysermc.connector.network.translators.bedrock;
-import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;
-
-import org.geysermc.common.AuthType;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.SkinUtils;
+import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;
+
+@Translator(packet = SetLocalPlayerAsInitializedPacket.class)
public class BedrockPlayerInitializedTranslator extends PacketTranslator {
@Override
public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession session) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java
index 298914ad4..3c7e85ecf 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java
@@ -25,13 +25,16 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.ClientRequest;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
+@Translator(packet = RespawnPacket.class)
public class BedrockRespawnTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java
index 9bd104b21..161397b66 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.bedrock;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.ClientRequest;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
+@Translator(packet = ShowCreditsPacket.class)
public class BedrockShowCreditsTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java
index f33f3fbd9..1c8416310 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.bedrock;
-import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
-import com.nukkitx.protocol.bedrock.packet.TextPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
+import com.nukkitx.protocol.bedrock.packet.TextPacket;
+
+@Translator(packet = TextPacket.class)
public class BedrockTextTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java
index 8308db2ed..c782e099a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java
@@ -32,9 +32,14 @@ import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.ListTag;
-import gnu.trove.map.TObjectIntMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import it.unimi.dsi.fastutil.ints.*;
+import it.unimi.dsi.fastutil.ints.Int2IntMap;
+import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import it.unimi.dsi.fastutil.objects.Object2IntMap;
+import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.Toolbox;
@@ -78,7 +83,8 @@ public class BlockTranslator {
} catch (Exception e) {
throw new AssertionError("Unable to load Java block mappings", e);
}
- TObjectIntMap addedStatesMap = new TObjectIntHashMap<>(512, 0.5f, -1);
+ Object2IntMap addedStatesMap = new Object2IntOpenHashMap<>();
+ addedStatesMap.defaultReturnValue(-1);
List paletteList = new ArrayList<>();
int waterRuntimeId = -1;
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java
index 754d05c67..f7be13c39 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java
@@ -32,7 +32,7 @@ import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket;
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.TranslatorsInit;
+import org.geysermc.connector.network.translators.Translators;
public class GenericInventoryTranslator extends InventoryTranslator {
@@ -54,7 +54,7 @@ public class GenericInventoryTranslator extends InventoryTranslator {
public void updateInventory(GeyserSession session, Inventory inventory) {
ItemData[] bedrockItems = new ItemData[inventory.getItems().length];
for (int i = 0; i < bedrockItems.length; i++) {
- bedrockItems[i] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
+ bedrockItems[i] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
}
InventoryContentPacket contentPacket = new InventoryContentPacket();
@@ -67,7 +67,7 @@ public class GenericInventoryTranslator extends InventoryTranslator {
public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
InventorySlotPacket slotPacket = new InventorySlotPacket();
slotPacket.setContainerId(inventory.getId());
- slotPacket.setItem(TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[slot]));
+ slotPacket.setItem(Translators.getItemTranslator().translateToBedrock(inventory.getItems()[slot]));
slotPacket.setSlot(slot);
session.getUpstream().sendPacket(slotPacket);
}
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 bfde6f74c..3c1452a53 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
@@ -25,16 +25,19 @@
package org.geysermc.connector.network.translators.java;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.utils.MessageUtils;
+
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerBossBarPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.packet.AddEntityPacket;
import com.nukkitx.protocol.bedrock.packet.BossEventPacket;
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.utils.MessageUtils;
+@Translator(packet = ServerBossBarPacket.class)
public class JavaBossBarTranslator extends PacketTranslator {
@Override
public void translate(ServerBossBarPacket packet, GeyserSession session) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java
index 58c17b712..226bd9714 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java
@@ -25,14 +25,16 @@
package org.geysermc.connector.network.translators.java;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.utils.MessageUtils;
+
import com.github.steveice10.mc.protocol.data.message.TranslationMessage;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.nukkitx.protocol.bedrock.packet.TextPacket;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.utils.MessageUtils;
-
+@Translator(packet = ServerChatPacket.class)
public class JavaChatTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java
index 6741cd7ec..1abf8e461 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.java;
-import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDifficultyPacket;
-import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDifficultyPacket;
+import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket;
+
+@Translator(packet = ServerDifficultyPacket.class)
public class JavaDifficultyTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java
index 51758011e..0d6caaed0 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java
@@ -25,16 +25,21 @@
package org.geysermc.connector.network.translators.java;
-import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
-
-import com.nukkitx.protocol.bedrock.data.PlayerPermission;
-import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.utils.DimensionUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
+import com.nukkitx.protocol.bedrock.data.PlayerPermission;
+import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
+import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
+import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
+import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
+
+@Translator(packet = ServerJoinGamePacket.class)
public class JavaJoinGameTranslator extends PacketTranslator {
@Override
@@ -44,7 +49,7 @@ public class JavaJoinGameTranslator extends PacketTranslator {
@Override
public void translate(LoginPluginRequestPacket packet, GeyserSession session) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java
index f60d405ef..60227aa4a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.java;
-import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
+import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
+
+@Translator(packet = ServerPluginMessagePacket.class)
public class JavaPluginMessageTranslator extends PacketTranslator {
@Override
public void translate(ServerPluginMessagePacket packet, GeyserSession session) {
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 285f9d855..185aab540 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
@@ -25,14 +25,17 @@
package org.geysermc.connector.network.translators.java;
-import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
-import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.DimensionUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
+import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
+
+@Translator(packet = ServerRespawnPacket.class)
public class JavaRespawnTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java
index 852c1af81..7334f8f8b 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.java;
-import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
-import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.MessageUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
+import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
+
+@Translator(packet = ServerTitlePacket.class)
public class JavaTitleTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java
index 28c3e1f6d..9d8853e75 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket;
-import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket;
+import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
+
+@Translator(packet = ServerEntityAnimationPacket.class)
public class JavaEntityAnimationTranslator extends PacketTranslator {
@Override
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
index 848b823de..98da3892c 100644
--- 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
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
+
+@Translator(packet = ServerEntityDestroyPacket.class)
public class JavaEntityDestroyTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java
new file mode 100644
index 000000000..be54e967f
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019-2020 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 org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.utils.EntityUtils;
+
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket;
+import com.nukkitx.protocol.bedrock.packet.MobEffectPacket;
+
+@Translator(packet = ServerEntityEffectPacket.class)
+public class JavaEntityEffectTranslator extends PacketTranslator {
+
+ @Override
+ public void translate(ServerEntityEffectPacket packet, GeyserSession session) {
+ Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
+ if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
+ entity = session.getPlayerEntity();
+ }
+ if (entity == null)
+ return;
+
+ MobEffectPacket mobEffectPacket = new MobEffectPacket();
+ mobEffectPacket.setAmplifier(packet.getAmplifier());
+ mobEffectPacket.setDuration(packet.getDuration());
+ mobEffectPacket.setEvent(MobEffectPacket.Event.ADD);
+ mobEffectPacket.setRuntimeEntityId(entity.getGeyserId());
+ mobEffectPacket.setParticles(packet.isShowParticles());
+ mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect()));
+ session.getUpstream().sendPacket(mobEffectPacket);
+ }
+}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java
index 5efe8e4e3..70c171425 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java
@@ -25,14 +25,17 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket;
-import com.nukkitx.protocol.bedrock.data.ItemData;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.LivingEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.network.translators.TranslatorsInit;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.network.translators.Translators;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket;
+import com.nukkitx.protocol.bedrock.data.ItemData;
+
+@Translator(packet = ServerEntityEquipmentPacket.class)
public class JavaEntityEquipmentTranslator extends PacketTranslator {
@Override
@@ -52,7 +55,7 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java
index d8d28fb71..dd097b7da 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
+
+@Translator(packet = ServerEntityMetadataPacket.class)
public class JavaEntityMetadataTranslator extends PacketTranslator {
@Override
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 7319c5612..581f16e36 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
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
+
+@Translator(packet = ServerEntityPositionRotationPacket.class)
public class JavaEntityPositionRotationTranslator extends PacketTranslator {
@Override
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 ae404d80d..b0ae3595e 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
@@ -25,12 +25,14 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
-
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
+
+@Translator(packet = ServerEntityPositionPacket.class)
public class JavaEntityPositionTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java
index c5c71f753..aedbf1a18 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java
@@ -25,14 +25,17 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.AttributeUtils;
+import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
+
+@Translator(packet = ServerEntityPropertiesPacket.class)
public class JavaEntityPropertiesTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java
new file mode 100644
index 000000000..fd8be52cb
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2019-2020 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 org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.utils.EntityUtils;
+
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRemoveEffectPacket;
+import com.nukkitx.protocol.bedrock.packet.MobEffectPacket;
+
+@Translator(packet = ServerEntityRemoveEffectPacket.class)
+public class JavaEntityRemoveEffectTranslator extends PacketTranslator {
+
+ @Override
+ public void translate(ServerEntityRemoveEffectPacket packet, GeyserSession session) {
+ Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
+ if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
+ entity = session.getPlayerEntity();
+ }
+ if (entity == null)
+ return;
+
+ MobEffectPacket mobEffectPacket = new MobEffectPacket();
+ mobEffectPacket.setEvent(MobEffectPacket.Event.REMOVE);
+ mobEffectPacket.setRuntimeEntityId(entity.getGeyserId());
+ mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect()));
+ session.getUpstream().sendPacket(mobEffectPacket);
+ }
+}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java
index c0cde6d3e..24ca5bb4a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java
@@ -25,15 +25,18 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
-import com.nukkitx.math.vector.Vector3f;
-import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
-import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import org.geysermc.connector.entity.Entity;
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.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
+import com.nukkitx.math.vector.Vector3f;
+import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
+import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
+
+@Translator(packet = ServerEntityRotationPacket.class)
public class JavaEntityRotationTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java
index 2865b14c7..d3e3973ce 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java
@@ -25,13 +25,16 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
-import com.nukkitx.protocol.bedrock.data.EntityEventType;
-import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
+import com.nukkitx.protocol.bedrock.data.EntityEventType;
+import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
+
+@Translator(packet = ServerEntityStatusPacket.class)
public class JavaEntityStatusTranslator extends PacketTranslator {
@Override
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 a08e4866f..febfc9ce3 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
@@ -25,13 +25,15 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
-import com.nukkitx.math.vector.Vector3f;
-
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
+import com.nukkitx.math.vector.Vector3f;
+
+@Translator(packet = ServerEntityTeleportPacket.class)
public class JavaEntityTeleportTranslator extends PacketTranslator {
@Override
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 8c3c26d8a..2bb8f6157 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
@@ -25,13 +25,16 @@
package org.geysermc.connector.network.translators.java.entity;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
-import com.nukkitx.math.vector.Vector3f;
-import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
+import com.nukkitx.math.vector.Vector3f;
+import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
+
+@Translator(packet = ServerEntityVelocityPacket.class)
public class JavaEntityVelocityTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java
index f27be49bf..dcf6371de 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java
@@ -25,19 +25,23 @@
package org.geysermc.connector.network.translators.java.entity.player;
+import java.util.Set;
+
+import org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
-import org.geysermc.connector.entity.Entity;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
-import java.util.HashSet;
-import java.util.Set;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+@Translator(packet = ServerPlayerAbilitiesPacket.class)
public class JavaPlayerAbilitiesTranslator extends PacketTranslator {
@Override
@@ -54,7 +58,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator playerFlags = new HashSet<>();
+ Set playerFlags = new ObjectOpenHashSet<>();
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
if (packet.isCanFly())
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
@@ -63,7 +67,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java
index bfae527b9..8dc432565 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java
@@ -25,13 +25,16 @@
package org.geysermc.connector.network.translators.java.entity.player;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
-import com.nukkitx.protocol.bedrock.packet.SetHealthPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
+import com.nukkitx.protocol.bedrock.packet.SetHealthPacket;
+
+@Translator(packet = ServerPlayerHealthPacket.class)
public class JavaPlayerHealthTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java
index 48f20dbdd..5ac759b48 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java
@@ -25,16 +25,19 @@
package org.geysermc.connector.network.translators.java.entity.player;
+import org.geysermc.connector.entity.PlayerEntity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.utils.SkinUtils;
+
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
-import org.geysermc.connector.entity.PlayerEntity;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.utils.SkinUtils;
+@Translator(packet = ServerPlayerListEntryPacket.class)
public class JavaPlayerListEntryTranslator extends PacketTranslator {
@Override
public void translate(ServerPlayerListEntryPacket packet, GeyserSession session) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java
index dccd6f54a..9d4e158c8 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java
@@ -25,21 +25,22 @@
package org.geysermc.connector.network.translators.java.entity.player;
-import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
-import com.nukkitx.math.vector.Vector3f;
-import com.nukkitx.protocol.bedrock.data.EntityEventType;
-import com.nukkitx.protocol.bedrock.packet.*;
-
-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.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.utils.ChunkUtils;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
+import com.nukkitx.math.vector.Vector3f;
+import com.nukkitx.protocol.bedrock.data.EntityEventType;
+import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
+import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
+import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
+import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
+
+@Translator(packet = ServerPlayerPositionRotationPacket.class)
public class JavaPlayerPositionRotationTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java
index 05eccbaa3..ace7a2b8e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.java.entity.player;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket;
+
+@Translator(packet = ServerPlayerSetExperiencePacket.class)
public class JavaPlayerSetExperienceTranslator extends PacketTranslator {
@Override
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
index b1a10f7b6..79ba3e0f5 100644
--- 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
@@ -25,14 +25,17 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
-import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ExpOrbEntity;
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.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
+import com.nukkitx.math.vector.Vector3f;
+
+@Translator(packet = ServerSpawnExpOrbPacket.class)
public class JavaSpawnExpOrbTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java
index b9c3d65bd..da2e59afe 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java
@@ -25,13 +25,16 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket;
-import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.Entity;
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.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket;
+import com.nukkitx.math.vector.Vector3f;
+
+@Translator(packet = ServerSpawnGlobalEntityPacket.class)
public class JavaSpawnGlobalEntityTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java
index ee01323b0..d955ecfdb 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java
@@ -25,18 +25,20 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
-import com.nukkitx.math.vector.Vector3f;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import org.geysermc.connector.entity.Entity;
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.Translator;
import org.geysermc.connector.utils.EntityUtils;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
+import com.nukkitx.math.vector.Vector3f;
+@Translator(packet = ServerSpawnMobPacket.class)
public class JavaSpawnMobTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java
index 88a64b500..15741c98e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java
@@ -25,19 +25,21 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
-import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket;
-import com.nukkitx.math.vector.Vector3f;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import org.geysermc.connector.entity.Entity;
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.Translator;
import org.geysermc.connector.utils.EntityUtils;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
+import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket;
+import com.nukkitx.math.vector.Vector3f;
+@Translator(packet = ServerSpawnObjectPacket.class)
public class JavaSpawnObjectTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java
index 3da528531..5fe3847f1 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java
@@ -25,15 +25,17 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
-import com.nukkitx.math.vector.Vector3f;
-
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.PaintingEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.PaintingType;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
+import com.nukkitx.math.vector.Vector3f;
+
+@Translator(packet = ServerSpawnPaintingPacket.class)
public class JavaSpawnPaintingTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java
index f737a13c3..331eb0945 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java
@@ -25,16 +25,18 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
-import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
-import com.nukkitx.math.vector.Vector3f;
-
import org.geysermc.connector.GeyserConnector;
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.Translator;
import org.geysermc.connector.utils.SkinUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
+import com.nukkitx.math.vector.Vector3f;
+
+@Translator(packet = ServerSpawnPlayerPacket.class)
public class JavaSpawnPlayerTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java
index 1b6ab8dc9..2719a72a0 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java
@@ -1,20 +1,20 @@
package org.geysermc.connector.network.translators.java.inventory;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
-import com.nukkitx.protocol.bedrock.data.ContainerId;
-import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
-import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.network.translators.TranslatorsInit;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.network.translators.Translators;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
+
+@Translator(packet = ServerOpenWindowPacket.class)
public class OpenWindowPacketTranslator extends PacketTranslator {
@Override
public void translate(ServerOpenWindowPacket packet, GeyserSession session) {
System.out.println("debug: " + packet.getType());
- InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
+ InventoryTranslator translator = Translators.getInventoryTranslator();
translator.openInventory(session, new Inventory(packet.getName(), packet.getWindowId(), packet.getType(), 54));
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java
index 49bfc4ba9..5a722953a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java
@@ -25,10 +25,13 @@
package org.geysermc.connector.network.translators.java.scoreboard;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket;
+
+@Translator(packet = ServerDisplayScoreboardPacket.class)
public class JavaDisplayScoreboardTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java
index eac126866..d852e652a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java
@@ -25,15 +25,18 @@
package org.geysermc.connector.network.translators.java.scoreboard;
-import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.ScoreboardCache;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.scoreboard.Objective;
import org.geysermc.connector.scoreboard.Scoreboard;
import org.geysermc.connector.utils.MessageUtils;
+import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction;
+import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket;
+
+@Translator(packet = ServerScoreboardObjectivePacket.class)
public class JavaScoreboardObjectiveTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java
index 48a553048..c9d1ccfe2 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java
@@ -25,19 +25,22 @@
package org.geysermc.connector.network.translators.java.scoreboard;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket;
+import java.util.Arrays;
+import java.util.Set;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.scoreboard.Scoreboard;
import org.geysermc.connector.scoreboard.UpdateType;
import org.geysermc.connector.utils.MessageUtils;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
+import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+
+@Translator(packet = ServerTeamPacket.class)
public class JavaTeamTranslator extends PacketTranslator {
@Override
@@ -49,12 +52,14 @@ public class JavaTeamTranslator extends PacketTranslator {
case CREATE:
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
+ .setColor(packet.getColor())
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()));
break;
case UPDATE:
scoreboard.getTeam(packet.getTeamName())
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
+ .setColor(packet.getColor())
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()))
.setUpdateType(UpdateType.UPDATE);
@@ -73,6 +78,6 @@ public class JavaTeamTranslator extends PacketTranslator {
}
private Set toPlayerSet(String[] players) {
- return new HashSet<>(Arrays.asList(players));
+ return new ObjectOpenHashSet<>(Arrays.asList(players));
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java
index 5232823d0..eac2ed049 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java
@@ -25,15 +25,17 @@
package org.geysermc.connector.network.translators.java.scoreboard;
-import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction;
-import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket;
-
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.scoreboard.Objective;
import org.geysermc.connector.scoreboard.Scoreboard;
+import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction;
+import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket;
+
+@Translator(packet = ServerUpdateScorePacket.class)
public class JavaUpdateScoreTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java
index a22998d53..9495bed48 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.java.window;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.InventoryUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
+
+@Translator(packet = ServerOpenWindowPacket.class)
public class JavaOpenWindowTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java
index 18e309d80..93df65e82 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java
@@ -25,14 +25,17 @@
package org.geysermc.connector.network.translators.java.window;
-import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.InventoryCache;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.InventoryUtils;
+import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
+import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
+
+@Translator(packet = ServerSetSlotPacket.class)
public class JavaSetSlotTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java
index b5cd605e6..f2287f6dc 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java
@@ -25,13 +25,16 @@
package org.geysermc.connector.network.translators.java.window;
-import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.InventoryCache;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.InventoryUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
+
+@Translator(packet = ServerWindowItemsPacket.class)
public class JavaWindowItemsTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java
index 913552fa4..b79525a9d 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.java.world;
-import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.ChunkUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
+
+@Translator(packet = ServerBlockChangePacket.class)
public class JavaBlockChangeTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java
index 936f422df..bb73c5f02 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java
@@ -25,6 +25,16 @@
package org.geysermc.connector.network.translators.java.world;
+import org.geysermc.connector.GeyserConnector;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.BiomeTranslator;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import org.geysermc.connector.utils.ChunkUtils;
+import org.geysermc.connector.world.chunk.ChunkSection;
+
+import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
+import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
@@ -32,13 +42,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import org.geysermc.connector.GeyserConnector;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.BiomeTranslator;
-import org.geysermc.connector.network.translators.PacketTranslator;
-import org.geysermc.connector.utils.ChunkUtils;
-import org.geysermc.connector.world.chunk.ChunkSection;
-
+@Translator(packet = ServerChunkDataPacket.class)
public class JavaChunkDataTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java
index e36019317..64733a027 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java
@@ -25,12 +25,15 @@
package org.geysermc.connector.network.translators.java.world;
-import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
-import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.ChunkUtils;
+import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
+import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket;
+
+@Translator(packet = ServerMultiBlockChangePacket.class)
public class JavaMultiBlockChangeTranslator extends PacketTranslator {
@Override
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 490a66437..6c7eeaf92 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
@@ -25,6 +25,14 @@
package org.geysermc.connector.network.translators.java.world;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+
+import org.geysermc.connector.entity.Entity;
+import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+
import com.github.steveice10.mc.protocol.data.game.ClientRequest;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.world.notify.EnterCreditsValue;
@@ -35,15 +43,15 @@ import com.nukkitx.protocol.bedrock.data.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
-import com.nukkitx.protocol.bedrock.packet.*;
-import org.geysermc.connector.entity.Entity;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.PacketTranslator;
+import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
+import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
+import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
+import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
+import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ThreadLocalRandom;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+@Translator(packet = ServerNotifyClientPacket.class)
public class JavaNotifyClientTranslator extends PacketTranslator {
@Override
@@ -68,7 +76,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator playerFlags = new HashSet<>();
+ Set playerFlags = new ObjectOpenHashSet<>();
GameMode gameMode = (GameMode) packet.getValue();
if (gameMode == GameMode.ADVENTURE)
playerFlags.add(AdventureSettingsPacket.Flag.IMMUTABLE_WORLD);
@@ -90,7 +98,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java
index 330a4d61b..02c693d87 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java
@@ -25,11 +25,14 @@
package org.geysermc.connector.network.translators.java.world;
-import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.world.chunk.ChunkPosition;
+import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket;
+
+@Translator(packet = ServerUnloadChunkPacket.class)
public class JavaUnloadChunkTranslator extends PacketTranslator {
@Override
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 e2173e2ca..ccb69856c 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
@@ -25,18 +25,21 @@
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;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
+import com.nukkitx.protocol.bedrock.packet.SetTimePacket;
+
+@Translator(packet = ServerUpdateTimePacket.class)
public class JavaUpdateTimeTranslator extends PacketTranslator {
@Override
public void translate(ServerUpdateTimePacket packet, GeyserSession session) {
+ // https://minecraft.gamepedia.com/Day-night_cycle#24-hour_Minecraft_day
SetTimePacket setTimePacket = new SetTimePacket();
- setTimePacket.setTime((int) Math.abs(packet.getTime()));
-
+ setTimePacket.setTime((int) Math.abs(packet.getTime()) % 24000);
session.getUpstream().sendPacket(setTimePacket);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java
index 1b339b1cf..823ce1998 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java
@@ -25,10 +25,13 @@
package org.geysermc.connector.network.translators.java.world;
-import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
+import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket;
+
+@Translator(packet = ServerUpdateViewDistancePacket.class)
public class JavaUpdateViewDistanceTranslator extends PacketTranslator {
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java
index ef0df721e..63ade1533 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java
@@ -25,12 +25,16 @@
package org.geysermc.connector.network.translators.java.world;
-import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket;
-import com.nukkitx.math.vector.Vector3i;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
+import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.ChunkUtils;
+import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket;
+import com.nukkitx.math.vector.Vector3i;
+import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
+
+@Translator(packet = ServerUpdateViewPositionPacket.class)
public class JavaUpdateViewPositionTranslator extends PacketTranslator {
@Override
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 48fe492f4..03ccb2fd3 100644
--- a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java
+++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java
@@ -30,6 +30,7 @@ import com.nukkitx.protocol.bedrock.data.ScoreInfo;
import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket;
import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket;
import com.nukkitx.protocol.bedrock.packet.SetScorePacket;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.Getter;
import org.geysermc.connector.network.session.GeyserSession;
@@ -113,7 +114,7 @@ public class Scoreboard {
}
public void onUpdate() {
- Set changedObjectives = new HashSet<>();
+ Set changedObjectives = new ObjectOpenHashSet<>();
List addScores = new ArrayList<>();
List removeScores = new ArrayList<>();
@@ -133,7 +134,7 @@ public class Scoreboard {
boolean hasUpdate = globalUpdate;
List handledScores = new ArrayList<>();
- for (String identifier : new HashSet<>(objective.getScores().keySet())) {
+ for (String identifier : new ObjectOpenHashSet<>(objective.getScores().keySet())) {
Score score = objective.getScores().get(identifier);
Team team = score.getTeam();
diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java
index d72fb60fd..c2fcc02c8 100644
--- a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java
+++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java
@@ -25,12 +25,13 @@
package org.geysermc.connector.scoreboard;
+import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -44,9 +45,9 @@ public class Team {
private UpdateType updateType = UpdateType.ADD;
private String name;
private String prefix;
+ private TeamColor color;
private String suffix;
- private Set entities = new HashSet<>();
-
+ private Set entities = new ObjectOpenHashSet<>();
public Team(Scoreboard scoreboard, String id) {
this.scoreboard = scoreboard;
diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java
index 743e934b2..a35b2cc58 100644
--- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java
+++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java
@@ -35,7 +35,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.TranslatorsInit;
+import org.geysermc.connector.network.translators.Translators;
import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.world.chunk.ChunkSection;
@@ -125,7 +125,7 @@ public class ChunkUtils {
data.setChunkX(chunkX + x);
data.setChunkZ(chunkZ + z);
data.setSubChunksLength(0);
- data.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA);
+ data.setData(Translators.EMPTY_LEVEL_CHUNK_DATA);
data.setCachingEnabled(false);
session.getUpstream().sendPacket(data);
diff --git a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java
index 79f85ac67..ec1ff4512 100644
--- a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java
+++ b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java
@@ -25,20 +25,32 @@
package org.geysermc.connector.utils;
+import com.github.steveice10.mc.protocol.data.game.entity.Effect;
import com.github.steveice10.mc.protocol.data.game.entity.type.MobType;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
import org.geysermc.connector.entity.type.EntityType;
public class EntityUtils {
- public static MobType toJavaEntity(EntityType type) {
- try {
- return MobType.valueOf(type.name());
- } catch (IllegalArgumentException ex) {
- return null;
+ public static int toBedrockEffectId(Effect effect) {
+ switch (effect) {
+ case GLOWING:
+ case LUCK:
+ case UNLUCK:
+ case DOLPHINS_GRACE:
+ case BAD_OMEN:
+ case HERO_OF_THE_VILLAGE:
+ return 0;
+ case LEVITATION:
+ return 24;
+ case CONDUIT_POWER:
+ return 26;
+ case SLOW_FALLING:
+ return 27;
+ default:
+ return effect.ordinal() + 1;
}
}
-
public static EntityType toBedrockEntity(MobType type) {
try {
return EntityType.valueOf(type.name());
diff --git a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java
index 56b59584d..045b81d16 100644
--- a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java
+++ b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java
@@ -37,7 +37,7 @@ import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.TranslatorsInit;
+import org.geysermc.connector.network.translators.Translators;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import java.util.List;
@@ -52,17 +52,17 @@ public class InventoryUtils {
ItemData[] contents = new ItemData[40];
// Inventory
for (int i = 9; i < 36; i++) {
- contents[i] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
+ contents[i] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
}
// Hotbar
for (int i = 36; i < 45; i++) {
- contents[i - 36] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
+ contents[i - 36] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
}
// Armor
for (int i = 5; i < 9; i++) {
- contents[i + 31] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
+ contents[i + 31] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]);
}
inventoryContentPacket.setContents(contents);
@@ -74,7 +74,7 @@ public class InventoryUtils {
session.getInventoryCache().getInventories().put(packet.getWindowId(), inventory);
session.getInventoryCache().setOpenInventory(inventory);
- InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
+ InventoryTranslator translator = Translators.getInventoryTranslator();
translator.prepareInventory(session, inventory);
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
List packets = session.getInventoryCache().getCachedPackets().get(inventory.getId());
@@ -99,7 +99,7 @@ public class InventoryUtils {
if (packet.getWindowId() != openInventory.getId())
return;
- InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
+ InventoryTranslator translator = Translators.getInventoryTranslator();
if (translator == null) {
session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
@@ -120,7 +120,7 @@ public class InventoryUtils {
if (packet.getWindowId() != openInventory.getId())
return;
- InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
+ InventoryTranslator translator = Translators.getInventoryTranslator();
if (translator == null) {
session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java
index 00dc98369..7b4c84a7e 100644
--- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java
+++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java
@@ -25,6 +25,7 @@
package org.geysermc.connector.utils;
+import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
import com.github.steveice10.mc.protocol.data.message.ChatColor;
import com.github.steveice10.mc.protocol.data.message.ChatFormat;
import com.github.steveice10.mc.protocol.data.message.Message;
@@ -36,20 +37,19 @@ import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
public class MessageUtils {
public static List getTranslationParams(Message[] messages) {
- List strings = new ArrayList();
- for (int i = 0; i < messages.length; i++) {
- if (messages[i] instanceof TranslationMessage) {
- TranslationMessage translation = (TranslationMessage) messages[i];
+ List strings = new ArrayList<>();
+ for (Message message : messages) {
+ if (message instanceof TranslationMessage) {
+ TranslationMessage translation = (TranslationMessage) message;
- StringBuilder builder = new StringBuilder("");
- builder.append("%");
- builder.append(translation.getTranslationKey());
- strings.add(builder.toString());
+ String builder = "%" + translation.getTranslationKey();
+ strings.add(builder);
if (translation.getTranslationKey().equals("commands.gamemode.success.other")) {
strings.add("");
@@ -59,15 +59,12 @@ public class MessageUtils {
strings.add(" - no permission or invalid command!");
}
- for (int j = 0; j < getTranslationParams(translation.getTranslationParams()).size(); j++) {
- strings.add(getTranslationParams(translation.getTranslationParams()).get(j));
- }
+ strings.addAll(getTranslationParams(translation.getTranslationParams()));
} else {
- StringBuilder builder = new StringBuilder("");
- builder.append(getFormat(messages[i].getStyle().getFormats()));
- builder.append(getColor(messages[i].getStyle().getColor()));
- builder.append(getBedrockMessage(messages[i]));
- strings.add(builder.toString());
+ String builder = getFormat(message.getStyle().getFormats()) +
+ getColor(message.getStyle().getColor()) +
+ getBedrockMessage(message);
+ strings.add(builder);
}
}
@@ -75,12 +72,8 @@ public class MessageUtils {
}
public static String getTranslationText(TranslationMessage message) {
- StringBuilder builder = new StringBuilder("");
- builder.append(getFormat(message.getStyle().getFormats()));
- builder.append(getColor(message.getStyle().getColor()));
- builder.append("%");
- builder.append(message.getTranslationKey());
- return builder.toString();
+ return getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor())
+ + "%" + message.getTranslationKey();
}
public static String getBedrockMessage(Message message) {
@@ -98,7 +91,6 @@ public class MessageUtils {
builder.append(getBedrockMessage(msg));
}
}
-
return builder.toString();
}
@@ -154,17 +146,18 @@ public class MessageUtils {
base += "f";
break;
case RESET:
+ case NONE:
base += "r";
break;
default:
- break;
+ return "";
}
return base;
}
private static String getFormat(List formats) {
- String str = "";
+ StringBuilder str = new StringBuilder();
for (ChatFormat cf : formats) {
String base = "\u00a7";
switch (cf) {
@@ -184,13 +177,13 @@ public class MessageUtils {
base += "o";
break;
default:
- break;
+ return "";
}
- str += base;
+ str.append(base);
}
- return str;
+ return str.toString();
}
public static boolean isMessage(String text) {
@@ -205,7 +198,6 @@ public class MessageUtils {
} catch (Exception ex) {
return false;
}
-
return true;
}
@@ -230,7 +222,20 @@ public class MessageUtils {
formatJson((JsonObject) a.get(i));
}
}
-
return object;
}
+
+ public static String toChatColor(TeamColor teamColor) {
+ for (ChatColor color : ChatColor.values()) {
+ if (color.name().equals(teamColor.name())) {
+ return getColor(color);
+ }
+ }
+ for (ChatFormat format : ChatFormat.values()) {
+ if (format.name().equals(teamColor.name())) {
+ return getFormat(Collections.singletonList(format));
+ }
+ }
+ return "";
+ }
}
diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
index 27c0fd617..45802196b 100644
--- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
+++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
@@ -48,7 +48,7 @@ public class Toolbox {
public static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
public static final CompoundTag BIOMES;
- public static final Collection ITEMS = new ArrayList<>();
+ public static final List ITEMS = new ArrayList<>();
public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();