Package org.spout.api.entity

Examples of org.spout.api.entity.Entity


import org.spout.vanilla.event.entity.EntityHealthChangeEvent;

public class ScoreboardListener implements Listener {
  @EventHandler (order = Order.LATEST)
  public void entityDeath(EntityDeathEvent event) {
    Entity entity = event.getEntity();
    Engine engine = Spout.getEngine();

    // kill count criteria
    Object lastDamager = event.getLastDamager();
    if (lastDamager instanceof Player) {
View Full Code Here


    evaluateCriteria(player.getName(), 1, true, Objective.CRITERIA_DEATH_COUNT);
  }

  @EventHandler (order = Order.LATEST)
  public void entityHealth(EntityHealthChangeEvent event) {
    Entity entity = event.getEntity();
    Engine engine = Spout.getEngine();
    if (!(entity instanceof Player) || !(engine instanceof Server)) {
      return;
    }
View Full Code Here

  @EventHandler
  public void syncEntity(EntityUpdateEvent event) {
    if (Spout.getPlatform() != Platform.SERVER || !event.isFullSync()) {
      return;
    }
    Entity e = event.getEntity();
    if (e != null && !(e.getNetwork() instanceof VanillaNetworkProtocol)) {
      return;
    }
    Transform liveTransform = event.getTransform();
    boolean self = (e == getOwner());
    boolean spawn = event.getAction() == EntityUpdateEvent.UpdateAction.ADD;
    boolean destroy = event.getAction() == EntityUpdateEvent.UpdateAction.REMOVE;
    boolean update = !spawn && !destroy;
    EntityProtocol ep = ((VanillaNetworkProtocol) e.getNetwork()).getEntityProtocol();
    if (ep == null) {
      if (spawn) {
        // For debugging purposes: log all entities with a missing protocol
        // Only do it for spawning - update is called too often
        Spout.getLogger().warning("Failure to spawn entity due to no EntityProtocol. Dropping entity toString...");
        Spout.getLogger().warning(e.toString());
      }
      // Do not send any messages - no protocol to do so
      return;
    }
    if (self && !(ep instanceof PlayerEntityProtocol)) {
      if (spawn) {
        // For debugging purposes: Log all Player entities that can't synchronize to self
        // Only do it for spawning - update is called too often
        Spout.getLogger().warning("Failure to spawn Player entity to self: No PlayerEntityProtocol is used. Dropping entity toString...");
        Spout.getLogger().warning(e.toString());
      }
      // Do not send any messages - no protocol to do so
      return;
    }
    if (self) {
      // Sync using vanilla Player 'self' protocol
      // Note: No messages gathered because all update methods send to the Player
      PlayerEntityProtocol pep = (PlayerEntityProtocol) ep;
      Player player = (Player) e;
      if (destroy) {
        pep.doSelfDestroy(player);
      }
      if (spawn) {
        pep.doSelfSpawn(player, getRepositionManager());
      }
      if (update) {
        boolean force = shouldForce(e.getId());
        pep.doSelfUpdate(player, liveTransform, getRepositionManager(), force);
      }
    } else {
      // Sync using vanilla protocol
      List<Message> messages = new ArrayList<Message>();
      if (destroy) {
        messages.addAll(ep.getDestroyMessages(e));
      }
      if (spawn) {
        messages.addAll(ep.getSpawnMessages(e, getRepositionManager()));
      }
      if (update) {
        boolean force = shouldForce(e.getId());
        messages.addAll(ep.getUpdateMessages(e, liveTransform, getRepositionManager(), force));
      }
      // Send all messages gathered
      for (Message message : messages) {
        getSession().send(message);
View Full Code Here

  @Override
  @SuppressWarnings("unchecked")
  public Minecart spawnEntity(Point position) {
    Class<? extends Minecart> component = this.getSpawnedComponent();
    Entity spawned = position.getWorld().createAndSpawnEntity(position, LoadOption.NO_LOAD, component, getMinecartType());
    return spawned.add(component);
  }
View Full Code Here

        list.add(paintingType);
      }
    }
    PaintingType paintingType = list.get(GenericMath.getRandom().nextInt(list.size() - 1));

    Entity e = world.createEntity(paintingType.getCenter(against, block.getPosition()), Painting.class);
    Painting painting = e.add(Painting.class);
    painting.setType(paintingType);
    painting.setFace(against);
    world.spawnEntity(e);
  }
View Full Code Here

  @Override
  public void setAttachedFace(Block block, BlockFace attachedFace, Cause<?> cause) {
    if (attachedFace == BlockFace.BOTTOM) {
      short data = 0;
      if (cause instanceof EntityCause) {
        Entity entity = ((EntityCause) cause).getSource();
        float yaw = entity.getPhysics().getRotation().getAxesAngleDeg().getY() * -1.0f;
        float rotation = (yaw + 180F) * 16F / 360F;
        data = (short) (rotation + 0.5F);
        data &= 15;
      }
      block.setMaterial(VanillaMaterials.SIGN_POST, data, cause);
View Full Code Here

      return;
    }

    World world = block.getWorld();
    Point pos = block.getPosition();
    Entity e = world.createEntity(new Point(world, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), ItemFrame.class);
    ItemFrame frame = e.add(ItemFrame.class);
    frame.setOrientation(face);
    world.spawnEntity(e);
  }
View Full Code Here

    Player player = session.getPlayer();
    World world = player.getWorld();

    int entityId = message.getEntityId();

    Entity entity = world.getEntity(entityId);
    if (entity == null) {
      player.getEngine().getLogger().warning("EntityMetadataHandler entity doesn't exist");
      return;
    }

    MetadataComponent metadataComponent = entity.get(MetadataComponent.class);
    if (metadataComponent != null) {
      for (Parameter<?> parameter : message.getParameters()) {
        metadataComponent.setParameter(parameter);
      }
    }
View Full Code Here

public class PlayerUseEntityHandler extends MessageHandler<PlayerUseEntityMessage> {
  @Override
  public void handleServer(ServerSession session, PlayerUseEntityMessage message) {
    Player playerEnt = session.getPlayer();
    Human player = playerEnt.get(Human.class);
    Entity clickedEntity = playerEnt.getWorld().getEntity(message.getTarget());
    if (clickedEntity == null || player == null) {
      return;
    }
    Slot held = PlayerUtil.getHeldSlot(playerEnt);
    if (held == null) {
      return;
    }
    ItemStack holding = held.get();
    Material holdingMat = holding == null ? VanillaMaterials.AIR : holding.getMaterial();
    if (holdingMat == null) {
      holdingMat = VanillaMaterials.AIR;
    }
    //TODO VanillaPlayerInteractEntityEvent maybe?
    PlayerInteractEntityEvent event;

    if (message.isPunching()) {
      event = new PlayerInteractEntityEvent(playerEnt, clickedEntity, clickedEntity.getPhysics().getPosition(), Action.LEFT_CLICK);
      if (Spout.getEventManager().callEvent(event).isCancelled()) {
        return;
      }
      holdingMat.onInteract(playerEnt, clickedEntity, Action.LEFT_CLICK);
      clickedEntity.interact(event);

      if (clickedEntity.get(Human.class) != null && !VanillaConfiguration.PLAYER_PVP_ENABLED.getBoolean()) {
        return;
      }

      Living clicked = clickedEntity.get(Living.class);
      if (clicked != null) {
        //TODO: Reimplement exhaustion values

        int damage = 1;
        if (holding != null && holdingMat instanceof VanillaMaterial) {
          damage = ((VanillaMaterial) holdingMat).getDamage();
          if (holdingMat instanceof Tool) {
            // This is a bit of a hack due to the way Tool hierarchy is now (Only Swords can have a damage modifier, but Sword must be an interface and therefore is not able to contain getDamageModifier without code duplication)
            damage += ((Tool) holdingMat).getDamageBonus(clickedEntity, holding);
            //            player.getInventory().getQuickbar().getCurrentSlotInventory().addData(1); TODO: Reimplement durability change
          }
        }

        //Potion modification
        if (holdingMat.equals(VanillaMaterials.AIR)) {
          Effects effect = playerEnt.add(Effects.class);
          if (effect.contains(EntityEffectType.STRENGTH)) {
            damage += 3;
          }
          if (effect.contains(EntityEffectType.WEAKNESS)) {
            damage -= 2;
          }
        }
        //END Potion modification

        // Damage the clicked entity
        if (damage > 0 && !PlayerUtil.isCreativePlayer(clickedEntity) && !clicked.getHealth().isDead()) {
          clicked.getHealth().damage(damage, new PlayerDamageCause(playerEnt, DamageType.ATTACK), damage > 0);
        }
      }
    } else {
      event = new PlayerInteractEntityEvent(playerEnt, clickedEntity, clickedEntity.getPhysics().getPosition(), Action.LEFT_CLICK);
      if (Spout.getEventManager().callEvent(event).isCancelled()) {
        return;
      }
      holdingMat.onInteract(playerEnt, clickedEntity, Action.RIGHT_CLICK);
      clickedEntity.interact(event);
    }
  }
View Full Code Here

  @Override
  public void handleClient(ClientSession session, EntityAnimationMessage message) {
    Player player = session.getPlayer();

    Entity entity = player.getWorld().getEntity(message.getEntityId());

    ModelComponent models = entity.get(ModelComponent.class);
    if (models == null) {
      return;
    }

    AnimationComponent animations = entity.get(AnimationComponent.class);
    if (animations == null) {
      return;
    }

    //This code launch the first animation finded on the first model
View Full Code Here

TOP

Related Classes of org.spout.api.entity.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.