gt: 				if (nearestFloor == floor) {
context: /*
   * This file is part of HeavySpleef.
   * Copyright (c) 2014-2016 Matthias Werning
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program. If not, see <http://www.gnu.org/licenses/>.
   */
  package de.xaniox.heavyspleef.flag.defaults;
  
  import com.google.common.collect.ImmutableList;
  import com.google.common.collect.Lists;
  import com.google.common.collect.Maps;
  import com.sk89q.worldedit.regions.Region;
  import de.xaniox.heavyspleef.core.HeavySpleef;
  import de.xaniox.heavyspleef.core.config.ConfigType;
  import de.xaniox.heavyspleef.core.config.DefaultConfig;
  import de.xaniox.heavyspleef.core.config.FlagSection;
  import de.xaniox.heavyspleef.core.event.PlayerLeaveGameEvent;
  import de.xaniox.heavyspleef.core.event.Subscribe;
  import de.xaniox.heavyspleef.core.flag.Flag;
  import de.xaniox.heavyspleef.core.flag.FlagInit;
  import de.xaniox.heavyspleef.core.floor.Floor;
  import de.xaniox.heavyspleef.core.game.Game;
  import de.xaniox.heavyspleef.core.game.GameManager;
  import de.xaniox.heavyspleef.core.game.GameState;
  import de.xaniox.heavyspleef.core.game.QuitCause;
  import de.xaniox.heavyspleef.core.i18n.I18N;
  import de.xaniox.heavyspleef.core.i18n.I18NManager;
  import de.xaniox.heavyspleef.core.i18n.Messages;
  import de.xaniox.heavyspleef.core.player.SpleefPlayer;
  import de.xaniox.heavyspleef.flag.presets.BaseFlag;
  import org.bukkit.Bukkit;
  import org.bukkit.Location;
  import org.bukkit.event.EventHandler;
  import org.bukkit.event.player.PlayerEvent;
  import org.bukkit.event.player.PlayerKickEvent;
  import org.bukkit.event.player.PlayerQuitEvent;
  import org.bukkit.scheduler.BukkitScheduler;
  import org.bukkit.scheduler.BukkitTask;
  
  import java.util.*;
  
  @Flag(name = "anticamping")
  public class FlagAntiCamping extends BaseFlag {
  
  	private static final long ONE_SECOND_INTERVAL = 20L;
  	private static AntiCampingTask task;
  	private static BukkitTask bukkitTask;
  	
  	@FlagInit
  	public static void initTask(HeavySpleef heavySpleef) {
  		BukkitScheduler scheduler = Bukkit.getScheduler();
  		
  		task = new AntiCampingTask(heavySpleef);
  		bukkitTask = scheduler.runTaskTimer(heavySpleef.getPlugin(), task, ONE_SECOND_INTERVAL, ONE_SECOND_INTERVAL);
  	}
  	
  	public static void stopTask(HeavySpleef heavySpleef) {
  		if (bukkitTask == null) {
  			return;
  		}
  		
  		bukkitTask.cancel();
  		bukkitTask = null;
  		task = null;
  	}
  	
  	@Override
  	public void getDescription(List<String> description) {
  		description.add("Enables the anticamping feature for a Spleef game");
  	}
  	
  	@Subscribe
  	public void onPlayerLeaveGame(PlayerLeaveGameEvent event) {
  		if (task == null) {
  			return;
  		}
  		
  		Game game = event.getGame();
  		if (game.getGameState() != GameState.INGAME) {
  			return;
  		}
  		
  		SpleefPlayer player = event.getPlayer();
  		task.resetPlayerData(player);
  	}
  	
  	private static class AntiCampingTask implements Runnable {
  	
  		private static final Comparator<Floor> COMPARATOR = new FloorComparator();
  		private final HeavySpleef heavySpleef;
  		private final I18N i18n = I18NManager.getGlobal();
  		private GameManager gameManager;
  		private DefaultConfig config;
  		private Map<SpleefPlayer, Location> recentLocations = Maps.newHashMap();
  		private Map<SpleefPlayer, Integer> secondsCamping = Maps.newHashMap();
  		
  		public AntiCampingTask(HeavySpleef heavySpleef) {
  			this.heavySpleef = heavySpleef;
  			this.gameManager = heavySpleef.getGameManager();
  			
  			config = heavySpleef.getConfiguration(ConfigType.DEFAULT_CONFIG);
  		}
  		
  		@Override
  		public void run() {
  			final FlagSection flagSection = config.getFlagSection();
  			final int anticampingWarn = flagSection.getAnticampingWarn();
  			final int anticampingTeleport = flagSection.getAnticampingTeleport();
  			final boolean warn = flagSection.isAnticampingDoWarn();
  			
  			for (Game game : gameManager.getGames()) {
  				if (game.getGameState() != GameState.INGAME) {
  					continue;
  				}
  				
  				if (!game.isFlagPresent(FlagAntiCamping.class)) {
  					continue;
  				}
  						
  				ImmutableList<SpleefPlayer> ingame = ImmutableList.copyOf(game.getPlayers());
  				for (SpleefPlayer player : ingame) {
  					if (recentLocations.containsKey(player)) {
  						Location recent = recentLocations.get(player);
  						Location now = player.getBukkitPlayer().getLocation();
  						
  						double dx = Math.abs(now.getX() - recent.getX());
  						double dz = Math.abs(now.getZ() - recent.getZ());
  						
  						if ((dx < 1D && dz < 1D) || player.getBukkitPlayer().isSneaking()) {
  							int seconds = secondsCamping.containsKey(player) ? secondsCamping.get(player) + 1 : 1;
  							
  							if (seconds == anticampingWarn && warn) {
  								player.sendMessage(i18n.getString(Messages.Player.ANTICAMPING_WARN));
  							}
  							
  							if (seconds == anticampingTeleport) {
  								if (teleport(player, game)) {
  									player.sendMessage(i18n.getString(Messages.Player.ANTICAMPING_TELEPORT));
  									secondsCamping.remove(player);
  								}
  							} else {
  								secondsCamping.put(player, seconds);
  							}
  						} else {
  							secondsCamping.remove(player);
  						}
  					}
  					
  					recentLocations.put(player, player.getBukkitPlayer().getLocation());
  				}
  			}
  		}
  		
  		private boolean teleport(SpleefPlayer player, Game game) {
  			Location location = player.getBukkitPlayer().getLocation();
  			double y = location.getY();
  			
  			Collection<Floor> floorsCollection = game.getFloors();
  			List<Floor> floors = Lists.newArrayList(floorsCollection);
  			
  			Floor nearestFloor = null;
  
  			// Calculate the nearest floor
  			for (Floor floor : floors) {
  				Region region = floor.getRegion();
  				int minrY = region.getMinimumPoint().getBlockY();
  				int maxrY = region.getMaximumPoint().getBlockY();
  				double dyMinR = Math.abs(y - minrY);
  				double dyMaxR = Math.abs(y - maxrY);
  				
  				if (nearestFloor == null) {
  					nearestFloor = floor;
  					continue;
  				}
  
  				Region nearestFloorRegion = nearestFloor.getRegion();
  				int minnrY = nearestFloorRegion.getMinimumPoint().getBlockY();
  				int maxnrY = nearestFloorRegion.getMaximumPoint().getBlockY();
  				double dyMinNr = Math.abs(y - minnrY);
  				double dyMaxNr = Math.abs(y - maxnrY);
  				
  				if ((dyMinR < dyMinNr && dyMinR < dyMaxNr) || (dyMaxR < dyMinNr && dyMaxR < dyMaxNr)) {
  					nearestFloor = floor;
  				}
  			}
  
  			if (nearestFloor == null) {
  				return false;
  			}
  
  			Collections.sort(floors, COMPARATOR);
  			
  			for (int i = 0; i < floors.size(); i++) {
  				Floor floor = floors.get(i);
  				
  				// Check if the player is at the last floor
  