help me please

Discussion in 'Plugin Development' started by chunkaymonkay, Sep 20, 2014.

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

    chunkaymonkay

    hey guys so to start off i would like to say that i did not make this code my friend dis but sadly hes on vacation for 2 moth i think it was and he cannot fix this for me so i asked him just to send me the code so i could try to fix but i couldnt xD so im here asking you guys if you could help me change this code into blocking player damage to other players not player damage to mobs
    Code:
      @EventHandler(priority=EventPriority.LOWEST)
      public void onNoAutoclick(EntityDamageByEntityEvent e)
      {
        if (((e.getEntity() instanceof LivingEntity)) &&
          ((e.getDamager() instanceof Player)))
        {
          final LivingEntity p = (LivingEntity)e.getEntity();
          if (this.nodamage.contains(p)) {
            e.setDamage(0.0D);
          }
          e.setCancelled(true);
          this.nodamage.add(p);
          new BukkitRunnable()
          {
            public void run()
            {
              Listeners.this.nodamage.remove(p);
            }
          }.runTaskLater(plugin, 2L);
        }
      }
     
  2. Offline

    teej107

    chunkaymonkay Check if the damager and the entity is a player. Then cancel it. And you don't need to use the nodamage collection. You can modify the noDamageTicks instead.
     
  3. Offline

    chunkaymonkay

    teej107 ok thanks

    teej107 like this?
    @EventHandler(priority=EventPriority.LOWEST)
    public void onNoAutoclick(EntityDamageByEntityEvent e)
    {
    if((e.getDamager() instanceof Player)))
    {
    e.setDamage(0.0D);
    }
    e.setCancelled(true);
    this.nodamage.add(p);
    new BukkitRunnable()
    {
    public void run()
    {
    Listeners.this.nodamage.remove(p);
    }
    }.runTaskLater(plugin, 2L);
    }
    }

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

    Gerov

    chunkaymonkay If I am reading this right, you might want to move the 'this.nodamage.add(p);' and the 'e.setCancelled(true);' into your if statement, or you are just blocking all damage.
     
  5. Offline

    teej107

    That and you aren't checking if the entity is a player either.
     
  6. Offline

    chunkaymonkay

    @EventHandler(priority=EventPriority.LOWEST)
    public void onNoAutoclick(EntityDamageByEntityEvent
    {
    if((e.getDamager() instanceof Player)))
    e.setCancelled(true);
    this.nodamage.add(p);

    {
    e.setDamage(0.0D);
    }
    new BukkitRunnable()
    {
    public void run()
    {
    Listeners.this.nodamage.remove(p);
    }
    }.runTaskLater(plugin, 2L);
    }
    }

    @Gerov like this ^ or like this

    @EventHandler(priority=EventPriority.LOWEST)
    public void onNoAutoclick(EntityDamageByEntityEvent
    e.setCancelled(true);
    this.nodamage.add(p);
    {
    if((e.getDamager() instanceof Player)))

    {
    e.setDamage(0.0D);
    }
    new BukkitRunnable()
    {
    public void run()
    {
    Listeners.this.nodamage.remove(p);
    }
    }.runTaskLater(plugin, 2L);
    }
    }

     
  7. Offline

    teej107

    chunkaymonkay No.
    Please learn and understand Java before you start making plugins. Java is the language you are using when you develop plugins. Bukkit is just an API. It's a lot easier to learn Java first then learn an API rather than attempting to understand both simultaneously. You should always learn the language you are writing in.
     
    Gerov likes this.
  8. Offline

    Gerov

    chunkaymonkay Just another tip, when I first got into programming, I learnt an easier language, Lua, so I could get to know the basics of programming like Strings and booleans, and if statements and all that, before I got into harder more complex langauges like Java.
     
  9. Offline

    WesJD

    If you do still need help, I may have misunderstood, but you can do this?

    Code:java
    1. if(e.getDamager instanceof Player) {
    2. e.setCancelled(true);


    ^ That may be wrong, got it off the top of my head.
     
Thread Status:
Not open for further replies.

Share This Page