Solved Too many EntityPortalEnterEvent!

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

  1. Offline

    phondeux

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  2. Offline

    phondeux

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Never mind, figured it out.

Share This Page