EntityDamageEvent not working?

Discussion in 'Plugin Development' started by Axanite, Jun 14, 2015.

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

    Axanite

    Okay, so I'm making a plugin which includes jump pads and if you use them they launch you into the air - i want it so when you use the pads you dont take damage when you hit the floor. When I make it not check if the player is in the arraylist, it works but when it has the check for the arraylist containing the player, it decides to not work?

    Code:


    Code:
    package us.smoothpvp.core.events;
    
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    
    import us.smoothpvp.core.misc.Utils;
    
    public class PlayerDamage implements Listener {
        @EventHandler
        public void onPlayerDamage(EntityDamageEvent e) {
            Entity eventEntity = e.getEntity();
            if(eventEntity instanceof Player) {
                if(e.getCause().equals(DamageCause.FALL)) {
                    if(Utils.jumperList().contains(eventEntity.getName())) {
                        e.setCancelled(true);
                        Utils.jumperList().remove(eventEntity.getName());
                    }
                }
            } else {
                return;
            }
        }
    }
    
     
  2. Offline

    Reynergodoy

    youre doing wrong '-'
    Code:
      @EventHandler(priority=EventPriority.HIGHEST)
      public void onEntityDamageSponge(EntityDamageEvent event)
      {
        if ((event.getEntity() instanceof Player))
        {
          Player player = (Player)event.getEntity();
          Location loc = player.getLocation();
          Location below = loc.subtract(0.0D, 1.0D, 0.0D);
          Block blockBelow = below.getBlock();
          if (event.getCause() == EntityDamageEvent.DamageCause.FALL)
          {
            if (blockBelow.getType() == Material.SPONGE)
            {
              jump.add(player.getName());
              event.setDamage(0.0D);
              return;
            }
            return;
          }
          return;
        }
      }
     
  3. Offline

    Axanite

    Did not work :/
     
  4. Offline

    Reynergodoy

    i'll give you the full class:
    Code:
      @EventHandler(priority=EventPriority.MONITOR)
      public void onPlayerJump(PlayerMoveEvent e)
      {
        Player p = e.getPlayer();
        if (e.getTo().getBlock().getRelative(BlockFace.DOWN).getType() == Material.SPONGE)
        {
          jump.remove(p.getName());
          Vector sponge = p.getLocation().getDirection().multiply(0).setY(2.5);
          p.setVelocity(sponge);
          p.getWorld().playSound(p.getLocation(), Sound.CHICKEN_HURT, 1.0F, 1.0F);
          jump.add(p.getName());
          jump.remove(p.getName());
          jump.add(p.getName());
          }
          return;
        }
      }
     
      @EventHandler
      public void onPlayerDamageSponge(EntityDamageEvent e)
      {
        if (!(e.getEntity() instanceof Player)) {
          return;
        }
        Player p = (Player)e.getEntity();
        if (e.getCause() == EntityDamageEvent.DamageCause.FALL) {
          return;
        }
        if (jump.contains(p.getName()))
        {
          jump.remove(p.getName());
          return;
        }
      }
     
      @EventHandler(priority=EventPriority.HIGHEST)
      public void onEntityDamageSponge(EntityDamageEvent event)
      {
        if ((event.getEntity() instanceof Player))
        {
          Player player = (Player)event.getEntity();
          Location loc = player.getLocation();
          Location below = loc.subtract(0.0D, 1.0D, 0.0D);
          Block blockBelow = below.getBlock();
          if (event.getCause() == EntityDamageEvent.DamageCause.FALL)
          {
            if (blockBelow.getType() == Material.SPONGE)
            {
              jump.add(player.getName());
              event.setDamage(0.0D);
              return;
            }
            return;
          }
          return;
        }
      }
     
      @EventHandler(priority=EventPriority.MONITOR)
      public void onPlayerSpongeDamage(EntityDamageEvent e)
      {
        if (!(e.getEntity() instanceof Player)) {
          return;
        }
        Player p = (Player)e.getEntity();
        if (e.getCause() == EntityDamageEvent.DamageCause.FALL)
        {
          if (jump.contains(p.getName()))
          {
            jump.remove(p.getName());
            e.setDamage(0.0D);
            return;
          }
          return;
        }
      }
     
  5. @Reynergodoy
    Code:
          jump.add(p.getName());
          jump.remove(p.getName());
          jump.add(p.getName());
    
    I don't even want to know what you're doing here.

    Message to the OP: When the player is launched into the air, do you add them to the jumper list? By the way, why do you use a method for jumperList? Just use a direct access, or create addJumper() and removeJumper() methods to make it cleaner.
     
  6. Offline

    Reynergodoy

    oh sorry... sometimes i dont event know what im doing... so...... you can just remove the first and the second jump...
     
  7. Offline

    Zombie_Striker

    @Reynergodoy
    Please don't completely give him the entire class. That is something even worse then spoonfeeding, you're making his plugin for him.
     
    CoolGamerXD and Konato_K like this.
  8. Offline

    CoolGamerXD

    I think it is because the event could not get the perfect Player ? I did got this problem with my plugin but I fixed it. Basically I added Player's name [String] instead of Player. Same while adding to array list add Player's name.
    Code:
    if(!(event.getEntity() instanceof Player)) return;
            EntityDamageEvent.DamageCause cause = event.getCause();
            if (cause == EntityDamageEvent.DamageCause.FALL) { 
              
                String playername = ((Player)event.getEntity()).getName();
    
                 if (!(falling.contains(playername))) return;
                 falling.remove(playername);
                
          
                event.setCancelled(true);
            } 
     
Thread Status:
Not open for further replies.

Share This Page