Merge pull request #11 from RyanHecht/master

Refactor Java packets to follow package structure of MCProtocolLib
This commit is contained in:
Redned 2019-07-25 00:11:27 -05:00 committed by GitHub
commit 43aa81d257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 38 additions and 18 deletions

View File

@ -28,10 +28,8 @@ package org.geysermc.connector.network.translators;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
import com.nukkitx.nbt.CompoundTagBuilder;
@ -45,14 +43,12 @@ import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslat
import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator;
import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator;
import org.geysermc.connector.network.translators.java.JavaChatTranslator;
import org.geysermc.connector.network.translators.java.JavaEntityPositionRotationTranslator;
import org.geysermc.connector.network.translators.java.JavaEntityPositionTranslator;
import org.geysermc.connector.network.translators.java.JavaEntityTeleportTranslator;
import org.geysermc.connector.network.translators.java.JavaEntityVelocityTranslator;
import org.geysermc.connector.network.translators.java.entity.*;
import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator;
import org.geysermc.connector.network.translators.java.JavaNotifyClientTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnExpOrbTranslator;
import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator;
import org.geysermc.connector.network.translators.java.JavaTitleTranslator;
import org.geysermc.connector.network.translators.java.JavaUpdateTimeTranslator;
import org.geysermc.connector.network.translators.java.world.JavaUpdateTimeTranslator;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -86,6 +82,8 @@ public class TranslatorsInit {
Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator());
Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator());
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator());
Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator());
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());

View File

@ -23,20 +23,23 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java;
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
import com.nukkitx.protocol.bedrock.packet.SetTimePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaTimeTranslator extends PacketTranslator<ServerUpdateTimePacket> {
public class JavaEntityDestroyTranslator extends PacketTranslator<ServerEntityDestroyPacket> {
@Override
public void translate(ServerUpdateTimePacket packet, GeyserSession session) {
SetTimePacket setTimePacket = new SetTimePacket();
setTimePacket.setTime((int) Math.abs(packet.getTime()));
public void translate(ServerEntityDestroyPacket packet, GeyserSession session) {
for (int entityId : packet.getEntityIds()) {
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
removeEntityPacket.setUniqueEntityId(entityId);
session.getUpstream().sendPacket(setTimePacket);
session.getUpstream().sendPacket(removeEntityPacket);
}
}
}

View File

@ -0,0 +1,19 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaSpawnExpOrbTranslator extends PacketTranslator<ServerSpawnExpOrbPacket> {
@Override
public void translate(ServerSpawnExpOrbPacket packet, GeyserSession session) {
SpawnExperienceOrbPacket spawnExperienceOrbPacket = new SpawnExperienceOrbPacket();
spawnExperienceOrbPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ()));
spawnExperienceOrbPacket.setAmount(packet.getExp());
session.getUpstream().sendPacket(spawnExperienceOrbPacket);
}
}