use of org.dragonet.proxy.network.cache.CachedEntity 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.proxy.network.cache.CachedEntity 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 };
}
use of org.dragonet.proxy.network.cache.CachedEntity 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 };
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityVelocityPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityVelocityPacket 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.motionX = packet.getMotionX();
entity.motionY = packet.getMotionY();
entity.motionZ = packet.getMotionZ();
SetEntityMotionPacket pk = new SetEntityMotionPacket();
pk.rtid = entity.proxyEid;
pk.motion = new Vector3F((float) packet.getMotionX(), (float) packet.getMotionY(), (float) packet.getMotionZ());
return new PEPacket[] { pk };
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityPropertiesPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityPropertiesPacket 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;
}
}
for (Attribute attr : packet.getAttributes()) {
switch(attr.getType()) {
case GENERIC_FOLLOW_RANGE:
entity.attributes.put(PEEntityAttribute.FOLLOW_RANGE, PEEntityAttribute.findAttribute(PEEntityAttribute.FOLLOW_RANGE).setValue((float) attr.getValue()));
break;
case GENERIC_KNOCKBACK_RESISTANCE:
entity.attributes.put(PEEntityAttribute.KNOCKBACK_RESISTANCE, PEEntityAttribute.findAttribute(PEEntityAttribute.KNOCKBACK_RESISTANCE).setValue((float) attr.getValue()));
break;
case GENERIC_MOVEMENT_SPEED:
entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
break;
case GENERIC_ATTACK_DAMAGE:
entity.attributes.put(PEEntityAttribute.ATTACK_DAMAGE, PEEntityAttribute.findAttribute(PEEntityAttribute.ATTACK_DAMAGE).setValue((float) attr.getValue()));
break;
case GENERIC_FLYING_SPEED:
entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
break;
}
}
if (entity.spawned) {
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.rtid = entity.proxyEid;
pk.entries = entity.attributes.values();
return new PEPacket[] { pk };
}
return null;
}
Aggregations