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