Canceling Villager Trade

Discussion in 'Plugin Development' started by itunes89, Jun 25, 2013.

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

    itunes89

    I need to cancel trading with villagers.

    I really don't know how. I know it's possible. My friend who isn't available right now did it.

    Thanks :D
     
  2. Offline

    skipperguy12

    Code:
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event){
        if(event.getRightClicked().getType != EntityType.VILLAGER) return;
        event.setCancelled(true);
    }
     
    itunes89 likes this.
  3. Offline

    itunes89

    Okay works great! Would be nice to explain it more though. :(
     
  4. Offline

    skipperguy12

    itunes89
    Code:
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event){
        if(event.getRightClicked().getType != EntityType.VILLAGER) return;
        event.setCancelled(true);
    }
    Alright, here's the method I was listening to:
    http://jd.bukkit.org/rb/apidocs/org/bukkit/event/player/PlayerInteractEntityEvent.html

    I do a check to see if the entity that was right clicked, and return (or stop the code from running) if it's not a Villager.

    The last part simply cancels the event, so no GUI is ever opened, thus stopping trade with villagers.
     
  5. Offline

    itunes89

    Okay thanks. Works great.
     
Thread Status:
Not open for further replies.

Share This Page