Search in sources :

Example 1 with AdventureSettingsPacket

use of org.dragonet.protocol.packets.AdventureSettingsPacket 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)

Example 2 with AdventureSettingsPacket

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

the class PCNotifyClientPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerNotifyClientPacket packet) {
    switch(packet.getNotification()) {
        case CHANGE_GAMEMODE:
            GameMode gm = (GameMode) packet.getValue();
            SetPlayerGameTypePacket pkgm = new SetPlayerGameTypePacket();
            pkgm.gamemode = gm == GameMode.CREATIVE ? 1 : 0;
            AdventureSettingsPacket adv = new AdventureSettingsPacket();
            adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, gm.equals(GameMode.ADVENTURE));
            adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, gm.equals(GameMode.CREATIVE) || gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.NO_CLIP, gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !gm.equals(GameMode.SPECTATOR) || !gm.equals(GameMode.ADVENTURE));
            adv.setFlag(AdventureSettingsPacket.FLYING, gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.MUTED, false);
            adv.eid = session.getEntityCache().getClientEntity().proxyEid;
            adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
            adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
            session.sendPacket(pkgm);
            session.sendPacket(adv);
            if (gm == GameMode.CREATIVE)
                session.sendCreativeInventory();
            break;
        case START_RAIN:
            LevelEventPacket evtStartRain = new LevelEventPacket();
            evtStartRain.eventId = LevelEventPacket.EVENT_START_RAIN;
            return new PEPacket[] { evtStartRain };
        case STOP_RAIN:
            LevelEventPacket evtStopRain = new LevelEventPacket();
            evtStopRain.eventId = LevelEventPacket.EVENT_STOP_RAIN;
            return new PEPacket[] { evtStopRain };
    }
    return null;
}
Also used : SetPlayerGameTypePacket(org.dragonet.protocol.packets.SetPlayerGameTypePacket) GameMode(com.github.steveice10.mc.protocol.data.game.entity.player.GameMode) AdventureSettingsPacket(org.dragonet.protocol.packets.AdventureSettingsPacket) LevelEventPacket(org.dragonet.protocol.packets.LevelEventPacket) PEPacket(org.dragonet.protocol.PEPacket)

Aggregations

AdventureSettingsPacket (org.dragonet.protocol.packets.AdventureSettingsPacket)2 SetPlayerGameTypePacket (org.dragonet.protocol.packets.SetPlayerGameTypePacket)2 GameMode (com.github.steveice10.mc.protocol.data.game.entity.player.GameMode)1 ArrayList (java.util.ArrayList)1 PEPacket (org.dragonet.protocol.PEPacket)1 LevelEventPacket (org.dragonet.protocol.packets.LevelEventPacket)1 PlayStatusPacket (org.dragonet.protocol.packets.PlayStatusPacket)1 SetDifficultyPacket (org.dragonet.protocol.packets.SetDifficultyPacket)1 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1