Package org.spout.vanilla.component.entity.misc

Examples of org.spout.vanilla.component.entity.misc.Health


  @Permissible ("vanilla.command.kill")
  public void kill(CommandSource source, CommandArguments args) throws CommandException {
    Player player = args.popPlayerOrMe("player", source);
    args.assertCompletelyParsed();

    Health health = player.get(Health.class);
    if (health == null) {
      throw new CommandException(player.getDisplayName() + " can not be killed.");
    }
    health.kill(HealthChangeCause.COMMAND);
  }
View Full Code Here


  }

  @Override
  public void onCollided(EntityCollideEvent event) {
    if (event instanceof EntityCollideEntityEvent) {
      Health health = ((EntityCollideEntityEvent) event).getCollided().get(Health.class);
      if (health != null) {
        health.damage(0);
      }
    }
    getOwner().remove();
  }
View Full Code Here

  }

  @Override
  public void onCollided(EntityCollideEvent event) {
    if (event instanceof EntityCollideEntityEvent) {
      Health health = ((EntityCollideEntityEvent) event).getCollided().get(Health.class);
      if (health != null) {
        health.damage(0);
      }
    }
    spawnChickens(new Point(event.getContactInfo().getNormal(), getOwner().getWorld()));
    getOwner().remove();
  }
View Full Code Here

   * @param collidedPoint The point where the material was collided with the entity
   * @param block The block this entity collided with
   */
  public void onCollided(Point colliderPoint, Point collidedPoint, Block block) {
    if (getShooter() != null && getShooter() instanceof Player) {
      Health health = getShooter().get(Health.class);
      if (health != null && !health.isDead()) {
        if (!PlayerUtil.isCreativePlayer(getShooter())) {
          health.damage(5);
        }
        ((Player) getShooter()).getPhysics().setPosition(block.translate(BlockFace.TOP).getPosition());
      }
    }
    getOwner().remove();
View Full Code Here

  @Override
  public void onCollided(EntityCollideEvent event) {
    if (event instanceof EntityCollideEntityEvent) {
      Point point = ((EntityCollideEntityEvent) event).getCollided().getPhysics().getPosition();
      Health health = ((EntityCollideEntityEvent) event).getCollided().get(Health.class);
      if (health != null) {
        health.damage(getOwner().get(Damage.class).getDamageLevel(point.getWorld().getData().get(VanillaData.DIFFICULTY)).getAmount());
      }
    } else {
      //TODO: Fall damage
    }
  }
View Full Code Here

public class PlayerHealthHandler extends MessageHandler<PlayerHealthMessage> {
  @Override
  public void handleClient(ClientSession session, PlayerHealthMessage message) {
    Player player = session.getPlayer();

    Health health = player.get(Health.class);
    health.setHealth(message.getHealth(), HealthChangeCause.UNKNOWN);

    Hunger hunger = player.get(Hunger.class);
    hunger.setHunger(message.getFood());
    hunger.setFoodSaturation(message.getFoodSaturation());
  }
View Full Code Here

          entity.remove();
          continue;
        }

        // Check if entity can be damaged
        Health health = entity.get(Health.class);
        if (health == null) {
          continue;
        }
        Human human = entity.get(Human.class);
        if (human != null && human.isCreative()) {
          continue;
        }
        health.damage(getDamage(position, entity.getPhysics().getPosition(), size));
      }
    }

    //explosion packet (TODO: Limit the amount sent per tick? Don't want to lag-out clients!)
    GeneralEffects.EXPLOSION.playGlobal(position, size);
View Full Code Here

    TestVanilla.init();
    VanillaConfiguration config = TestVanilla.getInstance().getConfig();
    VanillaConfiguration.PLAYER_SURVIVAL_ENABLE_HEALTH.setConfiguration(config);

    Entity entity = EntityMocker.mockEntity();
    Health health = entity.add(Health.class);

    health.setMaxHealth(15);
    assertEquals(15.0f, health.getMaxHealth(), 0.0f);
    assertEquals(1.0f, health.getHealth(), 0.0f);

    health.setSpawnHealth(20);
    assertEquals(20.0f, health.getMaxHealth(), 0.0f);
    assertEquals(20.0f, health.getHealth(), 0.0f);

    health.damage(1.0f);
    assertEquals(19.0f, health.getHealth(), 0.0f);

    health.kill(HealthChangeCause.DAMAGE);
    assertEquals(0.0f, health.getHealth(), 0.0f);
    assertTrue(health.isDead());

    health.heal(5.0f);
    assertEquals(5.0f, health.getHealth(), 0.0f);
    assertFalse(health.isDead());

    health.setDeathTicks(30);
    assertEquals(30, health.getDeathTicks());
    assertTrue(health.isDying());

    health.setHealth(-1.0f, HealthChangeCause.UNKNOWN);
    assertTrue(health.hasInfiniteHealth());
  }
View Full Code Here

TOP

Related Classes of org.spout.vanilla.component.entity.misc.Health

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.