use of org.dragonet.protocol.packets.UpdateAttributesPacket in project DragonProxy by DragonetMC.
the class PCUpdateHealthPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) {
// Always round up
int newHealth = (int) Math.ceil(packet.getHealth());
SetHealthPacket h = new SetHealthPacket(newHealth);
CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
peSelfPlayer.attributes.put(PEEntityAttribute.HEALTH, PEEntityAttribute.findAttribute(PEEntityAttribute.HEALTH).setValue(newHealth));
if (peSelfPlayer.foodPacketCount == 0) {
peSelfPlayer.attributes.put(PEEntityAttribute.FOOD, PEEntityAttribute.findAttribute(PEEntityAttribute.FOOD).setValue(packet.getFood()));
}
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.rtid = peSelfPlayer.proxyEid;
pk.entries = peSelfPlayer.attributes.values();
if (newHealth <= 0)
return new PEPacket[] { h, pk, new RespawnPacket() };
return new PEPacket[] { h, pk };
}
use of org.dragonet.protocol.packets.UpdateAttributesPacket 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.UpdateAttributesPacket 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.protocol.packets.UpdateAttributesPacket 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