Solved Stomper (FallDamage) Bug

Discussion in 'Plugin Development' started by Wiesel000, Sep 28, 2014.

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

    Wiesel000

    So many of you may know, the Stomper kit is a kit that where you fall from any height, you get a maximum of 2 hearts of fall damage, and the damage you normally would've gotten is transferred to the players in a 5,5,5 radius.

    So this is my code:

    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageEvent e) {
    3. if(e.getEntity() instanceof Player) {
    4. if(e.getCause().equals(DamageCause.FALL)) { //making sure its fall damage
    5. Player stomper = (Player) e.getEntity();
    6. if(plugin.list.stomper.contains(stomper.getName())) { //making sure the player is using the stomper kit
    7. List<Entity> list = stomper.getNearbyEntities(5, 5, 5);
    8. for(Entity ent : list) {
    9. ((Player) ent).damage(e.getDamage()); //damageing the surrounding entities with the (fall)damage taken
    10.  
    11. if(e.getDamage() > 4.0) { //if the fall damage is higher than 2 hearts, setting it to 2 hearts.
    12. e.setDamage(4.0);
    13. }
    14. }
    15. }
    16. }
    17. }
    18. }


    It didn't work, I die of fall damage. Anyone know how to fix this?
    + I don't have an alternate account so I don't even know if the players next to me would even take damage.

    Thanks,
    Wiesel~
     
  2. Offline

    Jimfutsu

    You are putting the check inside the for loop.
     
  3. Offline

    d3v1n302418

    Wiesel000 As Jimfutsu said, you put the check for 2 hearts of damage in the for loop which means it never occurs. Also your casting without checking so you will get an error if there is a creeper or something in the 5x5x5 radius.
     
  4. Offline

    Wiesel000

    Thanks Jimfutsu and d3v1n302418 i got it figured out now, thanks for the info about the for loop, i didnt know that, i will now use the forloop without the opening bracket (for (Stuff stuff : more_stuff). .... ) which works aswell.
     
  5. Offline

    Jimfutsu

    Wiesel000
    Please change the prefix to solved :)
     
  6. Offline

    Wiesel000

Thread Status:
Not open for further replies.

Share This Page