Getting a mob?

Discussion in 'Plugin Development' started by VictoryShot, Apr 29, 2014.

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

    VictoryShot

    Idk why but when I do this
    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageEvent e) {
    3. if(e.getEntity().equals(EntityType.VILLAGER)) {
    4. e.setCancelled(true);
    5. }


    I can still hit the villager BUT any other mobs like creeper cannot damage me or zombies,spiders,skeletons... etc.

    Someone Help?
     
  2. Offline

    Europia79

    VictoryShot

    Code:java
    1. if (e.getEntity().getType() == EntityType.VILLAGER)


    i've never done any work with Entities, so i'm not 100% sure if they have a getType() method.

    But I know that you'll have to convert your .equals() method to ==
     
  3. Offline

    thecrystalflame

    try using EntityDamageEntityEvent
    Code:java
    1.  
    2. if (e.getEntity().getType() == EntityType.VILLAGER) {
    3. }
    4. [/suntax]
     
  4. Offline

    Zach_1919

  5. Offline

    VictoryShot

  6. Offline

    Derpiee

    What're you trying to accomplish? :)
     
  7. Offline

    thecrystalflame

    Actually I'm fully aware of this but it is less efficient and it's better practise to do it our way instead and no it's not easier its around the same amount of work
     
  8. Europia79 You're right that the problem was that he wasn't checking the type. However, while I defend the use of == as opposed to .equals(), the fact is .equals() also works so you don't "have to" use == instead of .equals()

    thecrystalflame Is it actually less efficient? I haven't done or seen any tests to check that either way, have you? And if he wants to stop all damage to the villager, EntityDamageEvent would clearly be the better option.

    VictoryShot Do you have any other plugins? If you do, are they interfering with it? If you don't or if they're not, is another part of your plugin interfering with it?
     
  9. Offline

    Europia79

    AdamQpzm

    you bring up a good point... That another plugin could be interfering with his Event. I had this happen to me. I was able to fix it by changing the priority:

    Code:java
    1. @EventHandler (priority=EventPriority.HIGHEST)
    2. public void onSomeEvent(SomeEvent e) {}
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page