import org.spout.vanilla.protocol.msg.entity.EntityEquipmentMessage;
public final class EntityEquipmentHandler extends MessageHandler<EntityEquipmentMessage> {
@Override
public void handleClient(ClientSession session, EntityEquipmentMessage message) {
Player player = session.getPlayer();
World world = player.getWorld();
int entityId = message.getEntityId();
Entity entity = world.getEntity(entityId);
if (entity == null) {
player.getEngine().getLogger().warning("EntityEquipmentHandler entity don't exist");
return;
}
EntityInventory inventory = entity.get(EntityInventory.class);
if (inventory == null) {
player.getEngine().getLogger().warning("EntityEquipmentHandler entity haven't EntityInventory");
return;
}
ItemStack item = message.get();
switch (message.getSlot()) {
case 0:
inventory.getHeldItem().setMaterial(item.getMaterial());
inventory.getHeldItem().setAmount(item.getAmount());
return;
case 1:
inventory.getArmor().getHelmet().setMaterial(item.getMaterial());
inventory.getArmor().getHelmet().setAmount(item.getAmount());
return;
case 2:
inventory.getArmor().getChestPlate().setMaterial(item.getMaterial());
inventory.getArmor().getChestPlate().setAmount(item.getAmount());
return;
case 3:
inventory.getArmor().getLeggings().setMaterial(item.getMaterial());
inventory.getArmor().getLeggings().setAmount(item.getAmount());
return;
case 4:
inventory.getArmor().getBoots().setMaterial(item.getMaterial());
inventory.getArmor().getBoots().setAmount(item.getAmount());
return;
default:
player.getEngine().getLogger().warning("EntityEquipmentHandler slot bad value");
}
}