2019-07-17 18:00:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 GeyserMC. http://geysermc.org
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2019-07-11 22:39:28 +00:00
|
|
|
package org.geysermc.connector.network.translators;
|
|
|
|
|
2019-07-29 22:20:48 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
|
2019-09-16 22:28:29 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.*;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*;
|
2019-09-30 22:18:29 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket;
|
2019-08-06 06:38:03 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
|
2019-08-03 06:51:05 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
|
2019-08-06 06:38:03 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket;
|
2019-09-16 22:28:29 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.*;
|
2019-08-04 01:01:16 +00:00
|
|
|
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.ServerUpdateScorePacket;
|
2019-07-29 22:20:48 +00:00
|
|
|
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;
|
2019-09-14 15:26:49 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.*;
|
2019-07-20 22:35:14 +00:00
|
|
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
2019-07-17 01:05:10 +00:00
|
|
|
import com.nukkitx.nbt.NbtUtils;
|
|
|
|
import com.nukkitx.nbt.stream.NBTOutputStream;
|
|
|
|
import com.nukkitx.nbt.tag.CompoundTag;
|
2019-09-16 22:28:29 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.*;
|
2019-07-29 22:20:48 +00:00
|
|
|
import lombok.Getter;
|
2019-09-16 22:28:29 +00:00
|
|
|
import org.geysermc.connector.network.translators.bedrock.*;
|
2019-09-16 00:04:54 +00:00
|
|
|
import org.geysermc.connector.network.translators.block.BlockTranslator;
|
2019-07-29 22:20:48 +00:00
|
|
|
import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
2019-07-24 20:12:42 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.JavaChatTranslator;
|
2019-09-21 04:11:17 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.JavaDifficultyTranslator;
|
2019-07-24 20:12:42 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator;
|
2019-08-10 00:15:06 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.JavaRespawnTranslator;
|
2019-09-16 22:28:29 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.JavaTitleTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.entity.*;
|
2019-09-30 22:18:29 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerActionAckTranslator;
|
2019-08-06 06:38:03 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerHealthTranslator;
|
2019-08-03 06:51:05 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerPositionRotationTranslator;
|
2019-08-06 06:38:03 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerSetExperienceTranslator;
|
2019-09-16 22:28:29 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.entity.spawn.*;
|
2019-08-04 03:24:53 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator;
|
2019-08-04 01:01:16 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator;
|
2019-07-29 22:28:01 +00:00
|
|
|
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;
|
2019-09-16 22:28:29 +00:00
|
|
|
import org.geysermc.connector.network.translators.java.world.*;
|
2019-07-11 22:39:28 +00:00
|
|
|
|
2019-07-17 01:05:10 +00:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2019-07-20 22:35:14 +00:00
|
|
|
import java.io.IOException;
|
2019-07-29 22:20:48 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2019-07-17 01:05:10 +00:00
|
|
|
|
2019-07-11 22:39:28 +00:00
|
|
|
public class TranslatorsInit {
|
2019-07-21 22:22:56 +00:00
|
|
|
|
2019-07-29 22:20:48 +00:00
|
|
|
@Getter
|
|
|
|
private static ItemTranslator itemTranslator;
|
|
|
|
|
2019-09-16 00:04:54 +00:00
|
|
|
@Getter
|
|
|
|
private static BlockTranslator blockTranslator;
|
|
|
|
|
2019-07-29 22:20:48 +00:00
|
|
|
@Getter
|
|
|
|
private static Map<WindowType, InventoryTranslator> inventoryTranslators = new HashMap<WindowType, InventoryTranslator>();
|
|
|
|
|
2019-07-20 22:35:14 +00:00
|
|
|
private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
|
2019-07-24 20:12:42 +00:00
|
|
|
public static final byte[] EMPTY_LEVEL_CHUNK_DATA;
|
2019-07-20 22:35:14 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 22:39:28 +00:00
|
|
|
public static void start() {
|
2019-07-24 20:12:42 +00:00
|
|
|
Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator());
|
|
|
|
Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator());
|
|
|
|
Registry.registerJava(ServerTitlePacket.class, new JavaTitleTranslator());
|
|
|
|
Registry.registerJava(ServerUpdateTimePacket.class, new JavaUpdateTimeTranslator());
|
2019-08-10 00:15:06 +00:00
|
|
|
Registry.registerJava(ServerRespawnPacket.class, new JavaRespawnTranslator());
|
|
|
|
Registry.registerJava(ServerSpawnPositionPacket.class, new JavaSpawnPositionTranslator());
|
2019-09-21 04:11:17 +00:00
|
|
|
Registry.registerJava(ServerDifficultyPacket.class, new JavaDifficultyTranslator());
|
2019-08-03 06:51:05 +00:00
|
|
|
|
2019-09-15 04:19:13 +00:00
|
|
|
Registry.registerJava(ServerEntityAnimationPacket.class, new JavaEntityAnimationTranslator());
|
2019-07-24 20:12:42 +00:00
|
|
|
Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator());
|
|
|
|
Registry.registerJava(ServerEntityPositionRotationPacket.class, new JavaEntityPositionRotationTranslator());
|
|
|
|
Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator());
|
|
|
|
Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator());
|
2019-08-03 06:51:05 +00:00
|
|
|
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(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());
|
2019-09-16 22:28:29 +00:00
|
|
|
Registry.registerJava(ServerPlayerListEntryPacket.class, new JavaPlayerListEntryTranslator());
|
2019-08-03 06:51:05 +00:00
|
|
|
|
|
|
|
Registry.registerJava(ServerPlayerPositionRotationPacket.class, new JavaPlayerPositionRotationTranslator());
|
2019-08-06 06:38:03 +00:00
|
|
|
Registry.registerJava(ServerPlayerSetExperiencePacket.class, new JavaPlayerSetExperienceTranslator());
|
|
|
|
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
2019-09-30 22:18:29 +00:00
|
|
|
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
2019-08-03 06:51:05 +00:00
|
|
|
|
2019-07-24 20:12:42 +00:00
|
|
|
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
2019-09-08 20:46:10 +00:00
|
|
|
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
2019-07-25 05:03:59 +00:00
|
|
|
Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator());
|
2019-07-29 22:20:48 +00:00
|
|
|
Registry.registerJava(ServerWindowItemsPacket.class, new JavaWindowItemsTranslator());
|
|
|
|
Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator());
|
|
|
|
Registry.registerJava(ServerSetSlotPacket.class, new JavaSetSlotTranslator());
|
2019-08-04 01:01:16 +00:00
|
|
|
Registry.registerJava(ServerScoreboardObjectivePacket.class, new JavaScoreboardObjectiveTranslator());
|
2019-08-04 03:24:53 +00:00
|
|
|
Registry.registerJava(ServerDisplayScoreboardPacket.class, new JavaDisplayScoreboardTranslator());
|
2019-08-04 01:01:16 +00:00
|
|
|
Registry.registerJava(ServerUpdateScorePacket.class, new JavaUpdateScoreTranslator());
|
2019-09-14 15:26:49 +00:00
|
|
|
Registry.registerJava(ServerBlockChangePacket.class, new JavaBlockChangeTranslator());
|
2019-09-15 04:23:14 +00:00
|
|
|
Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator());
|
2019-07-24 20:12:42 +00:00
|
|
|
|
|
|
|
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
|
|
|
|
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
|
|
|
|
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
2019-08-05 20:16:45 +00:00
|
|
|
Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator());
|
2019-08-10 00:15:06 +00:00
|
|
|
Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
|
2019-09-14 00:37:06 +00:00
|
|
|
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
|
2019-09-29 23:25:42 +00:00
|
|
|
Registry.registerBedrock(InventoryTransactionPacket.class, new BedrockInventoryTransactionTranslator());
|
2019-07-29 22:20:48 +00:00
|
|
|
|
|
|
|
itemTranslator = new ItemTranslator();
|
2019-09-16 00:04:54 +00:00
|
|
|
blockTranslator = new BlockTranslator();
|
2019-07-29 22:20:48 +00:00
|
|
|
|
|
|
|
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());
|
2019-07-23 16:47:20 +00:00
|
|
|
}
|
2019-07-11 22:39:28 +00:00
|
|
|
}
|