Throwing a snowball gives the damaged entity a potion effect?

Discussion in 'Plugin Development' started by aliano99, Aug 3, 2014.

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

    aliano99

    Hey
    I'm trying to make it so that if you throw a snowball at another player it gives them slowness. This is what I've made so far but I'm really stuck as it doesn't work.
    Code:
    @SuppressWarnings("deprecation")
    @EventHandler (priority = EventPriority.NORMAL)
    public void onEntityDamageByEntity2 (EntityDamageByEntityEvent event) {
        if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
            Player attacker = (Player) event.getDamager();
            Player damaged = (Player) event.getEntity();
            if(plugin.Wizard.contains(attacker.getName())){
            if (attacker.getItemInHand().getTypeId() == Material.SNOW_BALL.getId()) {
                PotionEffect potionEffect = new PotionEffect(PotionEffectType.SLOW, 50, 5);
                potionEffect.apply(damaged); 

    Any idea how I can do this?
    Thanks!
     
  2. Offline

    Pizza371

    aliano99 events registered?
    are you sure Wizard contains the attacker's name? (check)
     
  3. Offline

    aliano99

    Edit:
    Never mind, SNOW_BALL works

    I'll test it once more

    Update: Still doesn't work. I removed the
    Code:
     if(plugin.Wizard.contains(attacker.getName())){
    for testing purposes and it still doesn't work.
    I'm pretty sure the event is registered because every other event in the event class does work except the snowball.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    Wingas

    aliano99 you need code or explanation?
     
  5. Offline

    aliano99

    Code please, mine doesn't work
     
  6. Offline

    Wingas

    Code:java
    1. f (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {


    You trying to make if damager instance of Player, damager is not player, damager is snowball
    Code:java
    1. if (e.getDamager().getType() == EntityType.Snowball)

    Then you need only leave
    Code:java
    1. if(e.getEntity() instanceof Player)
     
  7. Offline

    aliano99

    Ah I see, thanks!
    I'll test it out
     
Thread Status:
Not open for further replies.

Share This Page