When A Player gets hit by a snowball that was thrown by another player

Discussion in 'Plugin Development' started by xCyclonez, Feb 8, 2017.

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

    xCyclonez

    So, I'm trying to make some guns in my plugin, and I'm trying to make the snowball do a certain amount of damage to the player that gets hit.

    @EventHandler
    public void onSnowballHit(EntityDamageEvent event) {
    DamageCause thrownEntity = event.getCause().PROJECTILE;
    if (thrownEntity.equals(Material.SNOW_BALL)) {
    if (event.getEntity() instanceof Player) {
    EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
    Player thrower = (Player) e.getDamager();
    Player hitPlayer = (Player) e.getEntity();
    event.setCancelled(true);
    hitPlayer.damage(7.5);
    }
    }
    }
    }

    This is my current code
     
  2. Offline

    Rayzr522

    Aaaaand what's the problem? Any errors?
     
  3. Offline

    xCyclonez

    It doesn't do any damage to the player that get hit. In other words, it doesn't do what i want it to do.
     
    Last edited: Feb 8, 2017
  4. Offline

    Zombie_Striker

    @xCyclonez
    When will a DamageCause instance ever be equal to a Material? Those two things are completely different. Instead, check if the damager is an instanceof Snowball.
     
    Rayzr522 likes this.
  5. Offline

    Disgastings

    @EventHandler
    public void onEntityDamage(EntityDamageByEntityEvent e) {
    if (e.getDamager() instanceof Snowball) {
     
  6. Offline

    xCyclonez

    Not sure what you mean. So are you saying to do it like this

    @EventHandler
    public void onEntityDamage(EntityDamageByEntityEvent e) {
    if (e.getDamager() instanceof Snowball) {
    p.setDamage(args0);
     
    Last edited: Feb 8, 2017
  7. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page