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) };
}
Aggregations