Solved Too many EntityPortalEnterEvent!

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

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

    phondeux

    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:
    @EventHandler
      public void onEntityPortalEnter(EntityPortalEnterEvent event) {
          Location portLoc = event.getLocation();
         
          if (event.getEntity() instanceof Player) {
              // Loop through hashmap of gates and get gate within five blocks - this is the gate to use
              Set<Map.Entry<String, Location>> entrySet = plugin.adminGates.entrySet();
              String exitGate = "";
              for (@SuppressWarnings("rawtypes") Entry entry : entrySet) {
                  double DtoGate = portLoc.distance((Location) entry.getValue());
                  if (Double.compare(DtoGate, 5) < 0) {
                      exitGate = (String) entry.getKey();
                  }
              }
              tpPlayer(event.getEntity(), exitGate);
          }
      }
    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