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-21 01:10:30 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
2019-07-11 22:39:28 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
2019-07-21 20:53:56 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
|
2019-07-22 01:11:55 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
|
2019-07-23 16:47:20 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
2019-07-21 22:36:45 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
|
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-07-24 20:12:42 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
|
|
|
import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaChatTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaEntityPositionRotationTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaEntityPositionTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaEntityTeleportTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaEntityVelocityTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaNotifyClientTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaTitleTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.java.JavaUpdateTimeTranslator;
|
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-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-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());
|
|
|
|
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(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
|
|
|
|
|
|
|
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
|
|
|
|
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
|
|
|
|
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
2019-07-23 16:47:20 +00:00
|
|
|
}
|
2019-07-11 22:39:28 +00:00
|
|
|
}
|