Search in sources :

Example 11 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCEntityPositionPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPositionPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) {
            entity = session.getEntityCache().getClientEntity();
        } else {
            return null;
        }
    }
    entity.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
    if (entity.shouldMove) {
        MoveEntityPacket pk = new MoveEntityPacket();
        pk.rtid = entity.proxyEid;
        pk.yaw = (byte) (entity.yaw / (360d / 256d));
        pk.headYaw = (byte) (entity.headYaw / (360d / 256d));
        pk.pitch = (byte) (entity.pitch / (360d / 256d));
        pk.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
        pk.onGround = packet.isOnGround();
        entity.shouldMove = false;
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket) MoveEntityPacket(org.dragonet.protocol.packets.MoveEntityPacket)

Example 12 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class DPPluginMessageListener method processPacketForward.

private void processPacketForward(Player player, byte[] buffer) {
    final PEPacket packet = Protocol.decodeSingle(buffer);
    if (packet == null)
        return;
    BedrockPlayer bedrockPlayer = BedrockPlayer.getForPlayer(player);
    if (bedrockPlayer == null) {
        player.kickPlayer("Non-bedrock player sent packet forward packets!? ");
        return;
    }
    bedrockPlayer.process(packet);
}
Also used : PEPacket(org.dragonet.protocol.PEPacket)

Example 13 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class BatchPacket method encodePayload.

@Override
public void encodePayload() {
    byte[][] payload = new byte[packets.size() * 2][];
    int size = 0;
    for (int i = 0; i < packets.size(); i++) {
        PEPacket p = packets.get(i);
        if (!p.isEncoded()) {
            p.encode();
        }
        byte[] buf = p.getBuffer();
        payload[i * 2] = Binary.writeUnsignedVarInt(buf.length);
        payload[i * 2 + 1] = buf;
    }
    // compression should be processed async
    try {
        putByteArray(Zlib.deflate(Binary.appendBytes(payload), Deflater.BEST_SPEED));
    } catch (Exception ex) {
        Logger.getLogger(BatchPacket.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : PEPacket(org.dragonet.protocol.PEPacket)

Example 14 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCSetExperiencePacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlayerSetExperiencePacket packet) {
    CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
    peSelfPlayer.attributes.put(PEEntityAttribute.EXPERIENCE_LEVEL, PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE_LEVEL).setValue(packet.getLevel()));
    peSelfPlayer.attributes.put(PEEntityAttribute.EXPERIENCE, PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE).setValue(packet.getSlot()));
    UpdateAttributesPacket pk = new UpdateAttributesPacket();
    pk.rtid = peSelfPlayer.proxyEid;
    pk.entries = peSelfPlayer.attributes.values();
    return new PEPacket[] { pk };
}
Also used : UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket)

Example 15 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCEntityRemoveEffectPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityRemoveEffectPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) {
            entity = session.getEntityCache().getClientEntity();
        } else {
            return null;
        }
    }
    int effectId = MagicValues.value(Integer.class, packet.getEffect());
    if (!entity.effects.contains(effectId)) {
        return null;
    }
    MobEffectPacket eff = new MobEffectPacket();
    eff.rtid = entity.proxyEid;
    eff.eventId = MobEffectPacket.EVENT_REMOVE;
    return new PEPacket[] { eff };
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket) MobEffectPacket(org.dragonet.protocol.packets.MobEffectPacket)

Aggregations

PEPacket (org.dragonet.protocol.PEPacket)28 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)14 Vector3F (org.dragonet.common.maths.Vector3F)8 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 BlockPosition (org.dragonet.common.maths.BlockPosition)4 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)3 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 Timing (co.aikar.timings.Timing)1 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 GameMode (com.github.steveice10.mc.protocol.data.game.entity.player.GameMode)1 ExplodedBlockRecord (com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord)1 BuiltinSound (com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound)1 TranslationMessage (com.github.steveice10.mc.protocol.data.message.TranslationMessage)1 ServerPlaySoundPacket (com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)1 JsonParseException (com.google.gson.JsonParseException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PocketPotionEffect (org.dragonet.common.data.PocketPotionEffect)1 PEEntityAttribute (org.dragonet.common.data.entity.PEEntityAttribute)1