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 (Text):
    1. @EventHandler
    2.   public void onEntityPortalEnter(EntityPortalEnterEvent event) {
    3.       Location portLoc = event.getLocation();
    4.      
    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 (Double.compare(DtoGate, 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.
     
  2. Offline

    phondeux

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

Share This Page