Solved Too many EntityPortalEnterEvent!

Discussion in 'Plugin Development' started by phondeux, Jan 31, 2013.

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


    I'm trying to create a plugin that teleports players when they step through a custom gate. This works, however when a player steps into a gate at least a dozen of these events are fired! Is there a way to just deal with the first event only? Here's the code I'm using;
    Code (Text):
    1. @EventHandler
    2.   public void onEntityPortalEnter(EntityPortalEnterEvent event) {
    3.       Location portLoc = event.getLocation();
    5.       if (event.getEntity() instanceof Player) {
    6.           // Loop through hashmap of gates and get gate within five blocks - this is the gate to use
    7.           Set<Map.Entry<String, Location>> entrySet = plugin.adminGates.entrySet();
    8.           String exitGate = "";
    9.           for (@SuppressWarnings("rawtypes") Entry entry : entrySet) {
    10.               double DtoGate = portLoc.distance((Location) entry.getValue());
    11.               if (, 5) < 0) {
    12.                   exitGate = (String) entry.getKey();
    13.               }
    14.           }
    15.           tpPlayer(event.getEntity(), exitGate);
    16.       }
    17.   }
    I'm guessing I need to throw a return in there somewhere so I exit the loop the first time I find a gate within five blocks of the player location.

    Never mind, figured it out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page