Solved Detect Door Opening

Discussion in 'Plugin Development' started by sunnydan, Sep 30, 2013.

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

    sunnydan

    I'm writing a plugin that adds a lot of new mechanics to NPC villages, and I'd like to be able to detect whenever an NPC villager goes through a door. How would I accomplish this?
     
  2. Offline

    bigbeno37

    Hm...this is an interesting question. Perhaps try experimenting with EntityInteractEvent: http://jd.bukkit.org/dev/doxygen/d4..._1event_1_1entity_1_1EntityInteractEvent.html

    Perhaps listen for this and then see if it is a villager. If it is, then we carry on, assuming that the interact event was with the door.

    Anyway, just my two-cents. I'm nowhere near a good Bukkit programmer, but Bukkit javadocs is a good place to go when you're wondering about events.
     
  3. Offline

    Bammerbom

    bigbeno37 I don't know. But entityInteract is if a player right click an entity
     
  4. Offline

    waicool20

    sunnydan
    Blockphysicsevent is your event
     
  5. Offline

    bigbeno37

    How would you go about using this?
     
  6. Offline

    Mathias Eklund

  7. Offline

    bigbeno37

    Ooh, okay, so you could make an if statement and if the block changed is a door...but how do you know it was a villager then?
     
  8. Offline

    Henzz

    sunnydan

    Edit: And from there, you can check the current data in comparison with an open/closed door's data, might want to also check for what direction it is facing as well.

    Could it be this, not sure as I've not tested it.
    PHP:
      @SuppressWarnings("deprecation")
      @
    EventHandler
        
    public void onInteract(EntityInteractEvent event) {
            if (
    event.getEntity().getType() == EntityType.VILLAGER) {
                
    Villager villager = (Villagerevent.getEntity();
                if (
    villager.getTargetBlock(null50).getType() == Material.WOODEN_DOOR) {
                    
    // he interacted with a wooden door
                
    }
            }
        }
     
  9. Offline

    bigbeno37

    Wouldn't that only occur if a player opened a door?
     
  10. Offline

    waicool20

    Why not do this:
    Create arraylist
    When villager entity spawns add it to arraylist
    When entity moves/door opens
    Loop through the arraylist and get the location of the entity
    If the locations block is a door do your code

    Dont know if this will work but its an idea
     
  11. Offline

    Henzz

    bigbeno37
    Oh shit, that was a big typo lol.
     
  12. Offline

    sunnydan

    I ended up solving it a different way. I created a BukkitRunnable that runs every other tick, and checks all villagers to see if their location is also that of a door. If true, call a custom event.
     
Thread Status:
Not open for further replies.

Share This Page