Search in sources :

Example 1 with SetDifficultyPacket

use of org.dragonet.protocol.packets.SetDifficultyPacket in project DragonProxy by DragonetMC.

the class PCRespawnPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerRespawnPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.dimention != packet.getDimension()) {
        // the player have changed dimention
        DragonProxy.getInstance().getLogger().info(session.getUsername() + " change dim " + entity.dimention + " to " + packet.getDimension());
        // entity.dimention = packet.getDimension();
        // purge and despawn
        session.getEntityCache().reset(true);
        session.getChunkCache().purge();
        // send new world gamemode
        SetPlayerGameTypePacket pkgm = new SetPlayerGameTypePacket();
        pkgm.gamemode = packet.getGameMode() == GameMode.CREATIVE ? 1 : 0;
        session.sendPacket(pkgm);
        // send new adventure settings
        AdventureSettingsPacket adv = new AdventureSettingsPacket();
        adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, packet.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, packet.getGameMode().equals(GameMode.CREATIVE) || packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.NO_CLIP, packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !packet.getGameMode().equals(GameMode.SPECTATOR) || !packet.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.FLYING, packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.MUTED, false);
        adv.eid = entity.proxyEid;
        adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
        adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
        session.sendPacket(adv);
        // send entity attributes
        UpdateAttributesPacket attr = new UpdateAttributesPacket();
        attr.rtid = entity.proxyEid;
        if (entity.attributes.isEmpty()) {
            attr.entries = new ArrayList();
            attr.entries.addAll(PEEntityAttribute.getDefault());
        } else
            attr.entries = entity.attributes.values();
        session.sendPacket(attr);
        // set world difficulty
        session.sendPacket(new SetDifficultyPacket(packet.getDifficulty()));
        if (packet.getGameMode().equals(GameMode.CREATIVE))
            session.sendCreativeInventory();
        return null;
    } else
        return new PEPacket[] { new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN) };
}
Also used : SetPlayerGameTypePacket(org.dragonet.protocol.packets.SetPlayerGameTypePacket) SetDifficultyPacket(org.dragonet.protocol.packets.SetDifficultyPacket) PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket) AdventureSettingsPacket(org.dragonet.protocol.packets.AdventureSettingsPacket) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 AdventureSettingsPacket (org.dragonet.protocol.packets.AdventureSettingsPacket)1 PlayStatusPacket (org.dragonet.protocol.packets.PlayStatusPacket)1 SetDifficultyPacket (org.dragonet.protocol.packets.SetDifficultyPacket)1 SetPlayerGameTypePacket (org.dragonet.protocol.packets.SetPlayerGameTypePacket)1 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1