Deal damage on impact

Discussion in 'Plugin Development' started by xLoGiiKzZo, Aug 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    xLoGiiKzZo

    Is it possible to make a falling blocks deal damage to a player on impact?
     
  2. Offline

    Lactem

    Use a damage event and check if the damage cause is a falling block.
     
  3. Offline

    The_Doctor_123

    Falling Blocks don't do damage on impact.. I'm pretty sure this guy wants something like Wasted in the Shotbow Network.

    Here's what you need to do. Listen for the EntityChangeBlockEvent. Get all entities in the world and use the distance method to compare the entity's location and the block's location. Here's an example:

    Code:java
    1. @EventHandler
    2. public void onEntityChangeBlock(EntityChangeBlockEvent event)
    3. {
    4. for (Player player : event.getBlock().getWorld().getPlayers()) // You can change it to getEntities() if you want to affect all mobs, but it puts more stress on the server
    5. {
    6. if (player.getLocation().distance(event.getBlock().getLocation()) < 2)
    7. {
    8. player.damage(5);
    9. }
    10. }
    11. }
     
    xLoGiiKzZo likes this.
Thread Status:
Not open for further replies.

Share This Page