@EventHandler(priority = EventPriority.HIGHEST)
	public void onPlayerInteract(PlayerInteractEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());
		Block block = e.getClickedBlock();

		if (player == null)
			return;
		if (block == null)
			return;
		if (!player.isActive())
			return;
		if (e.getAction() != Action.LEFT_CLICK_BLOCK)
			return;

		Game game = player.getGame();
		if (!game.canSpleef(player, block.getLocation()))
			return;

		if (game.getFlag(FlagType.BOWSPLEEF) || game.getFlag(FlagType.SPLEGG))
			return;

		if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
			block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
		}

		block.setType(Material.AIR);
		player.addBrokenBlock(block);
	}
	@EventHandler
	public void onItemDrop(PlayerDropItemEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!player.isActive())
			return;

		e.setCancelled(true);
	}
	@EventHandler
	public void onEntityDamage(EntityDamageEvent e) {
		if (!(e.getEntity() instanceof Player))
			return;

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getEntity());

		if (player.isActive()) {
			e.setCancelled(true);
		}
	}
	private void handleQuit(PlayerEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		QueuesManager.removeFromQueue(player);

		if (!player.isActive()) {
			return;
		}

		Game game = player.getGame();
		game.leave(player, LoseCause.QUIT);
	}
	@EventHandler
	public void onFoodChange(FoodLevelChangeEvent e) {
		if (!(e.getEntity() instanceof Player)) {
			return;
		}

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getEntity());

		if (player.isActive()) {
			e.setFoodLevel(20);
		}
	}
	@EventHandler(priority = EventPriority.HIGH)
	public void onGamemodeChange(PlayerGameModeChangeEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!player.isActive()) {
			return;
		}

		if (e.getNewGameMode() == GameMode.SURVIVAL) {
			return;
		}

		player.sendMessage(I18N._("cantChangeGamemode"));
		e.setCancelled(true);
	}
	@EventHandler
	public void onCommand(PlayerCommandPreprocessEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (player == null)
			return;
		if (!QueuesManager.hasQueue(player))
			return;
		if (HeavySpleef.getSystemConfig().getQueuesSection().isAllowCommands())
			return;

		if (e.getMessage().equalsIgnoreCase("/spleef leave") || e.getMessage().equalsIgnoreCase("/spl leave"))
			return;

		e.setCancelled(true);
		player.sendMessage(I18N._("noCommandsInQueue"));
	}
	@Command(value = "spectate", minArgs = 1, onlyIngame = true)
	@CommandPermissions(value = { Permissions.SPECTATE })
	@CommandHelp(usage = "/spleef spectate <game>", description = "Spectates a game")
	public void execute(Player bukkitPlayer, Game game) {
		if (game == null) {
			bukkitPlayer.sendMessage(_("arenaDoesntExists"));
			return;
		}

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(bukkitPlayer);

		if (game.getFlag(FlagType.SPECTATE) == null) {
			player.sendMessage(_("noSpectatePoint"));
			return;
		}

		game.spectate(player);
	}
	@EventHandler
	public void onPlayerRespawn(PlayerRespawnEvent e) {
		final SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!dead.contains(player.getRawName()))
			return;

		// Player died while spleefing, restore his inventory
		Bukkit.getScheduler().scheduleSyncDelayedTask(HeavySpleef.getInstance(), new Runnable() {

			@Override
			public void run() {
				if (player.getBukkitPlayer().isOnline()) {
					player.restoreState();
				}
			}
		}, 10L);

		dead.remove(player.getRawName());
	}
	@EventHandler
	public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!player.isActive() && !player.isSpectating())
			return;
		if (e.getPlayer().hasPermission(Permissions.COMMAND_WHITELISTED.getPerm()))
			return;

		String[] split = e.getMessage().split(" ");
		String cmd = split[0];
		if (cmd.equalsIgnoreCase("/spleef") || cmd.equalsIgnoreCase("/hs") || cmd.equalsIgnoreCase("/hspleef"))
			return;
		List<String> whitelist = HeavySpleef.getSystemConfig().getGeneralSection().getCommandWhitelist();
		for (String c : whitelist) {
			if (c.equalsIgnoreCase(cmd))
				return;
		}
		e.setCancelled(true);
		e.getPlayer().sendMessage(I18N._("cantUseCommands"));
	}
	@EventHandler
	public void onSpleggGunClick(PlayerInteractEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (player == null)
			return;
		if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)
			return;
		if (!player.isActive())
			return;

		Game game = player.getGame();
		if (game.getGameState() != GameState.INGAME)
			return;
		if (!game.getFlag(FlagType.SPLEGG))
			return;
		if (player.getBukkitPlayer().getItemInHand().getType() != Material.DIAMOND_SPADE)
			return;

		// Launch egg
		player.getBukkitPlayer().launchProjectile(Egg.class);
		player.getBukkitPlayer().playSound(e.getPlayer().getLocation(), Sound.GHAST_FIREBALL, 0.4F, 2F);
	}
	@EventHandler
	public void onBlockBreak(BlockBreakEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());
		Block block = e.getBlock();

		if (!player.isActive()) {
			for (Game game : GameManager.getGames()) {
				if (game.contains(block.getLocation())) {
					if (player.getBukkitPlayer().hasPermission(Permissions.BUILD_BYPASS.getPerm()))
						return;
					if (!HeavySpleef.getSystemConfig().getGeneralSection().isProtectArenas())
						return;

					e.setCancelled(true);
					fixBlockGlitch(player.getBukkitPlayer(), block);
					player.sendMessage(I18N._("notAllowedToBuild"));
					return;
				}
			}
			return;
		}

		Game game = player.getGame();

		if (!game.canSpleef(player, block.getLocation())) {
			e.setCancelled(true);
			fixBlockGlitch(player.getBukkitPlayer(), block);
			player.sendMessage(I18N._("notAllowedToBuild"));
			return;
		}

		if (game.getFlag(FlagType.BOWSPLEEF) || game.getFlag(FlagType.SPLEGG)) {
			e.setCancelled(true);
			return;
		}

		player.addBrokenBlock(block);
	}
	// This event shouldn't be fired because player is in god mode
	// But we don't know if someone types /kill player while he's playing
	// spleef...
	@EventHandler
	public void onPlayerDeath(PlayerDeathEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getEntity());

		if (player.isActive()) {

			Game game = player.getGame();
			game.leave(player, LoseCause.UNKNOWN);

			dead.add(player.getRawName());
		} else if (player.isSpectating()) {
			player.getGame().leaveSpectate(player);
		}
	}
	@EventHandler
	public void onProjectileHit(ProjectileHitEvent e) {
		if (!(e.getEntity() instanceof Arrow) && !(e.getEntity() instanceof Egg))
			return;

		Projectile projectile = e.getEntity();

		if (!(projectile.getShooter() instanceof Player))
			return;

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(projectile.getShooter());

		if (!player.isActive())
			return;

		Game game = player.getGame();

		if (projectile instanceof Arrow) {
			Arrow arrow = (Arrow) projectile;

			if (!game.getFlag(FlagType.BOWSPLEEF))
				return;

			// Use BlockIterator to detect the hit block
			BlockIterator iterator = new BlockIterator(arrow.getWorld(), arrow.getLocation().toVector(), arrow.getVelocity().normalize(), 0, 4);
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			World world = arrow.getWorld();

			if (hitBlock.getType() == Material.TNT) {
				return;
			}

			arrow.remove();

			player.addBrokenBlock(hitBlock);
			FallingBlock block = world.spawnFallingBlock(hitBlock.getLocation(), hitBlock.getType(), hitBlock.getData());
			block.setMetadata("bowspleef", new FixedMetadataValue(HeavySpleef.getInstance(), true));

			if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
				world.playEffect(hitBlock.getLocation(), Effect.STEP_SOUND, hitBlock.getType());
			}
			hitBlock.setType(Material.AIR);
		} else if (projectile instanceof Egg) {
			Egg egg = (Egg) projectile;

			if (!game.getFlag(FlagType.SPLEGG))
				return;

			// Use BlockIterator to detect the hit block
			World world = egg.getWorld();
			BlockIterator iterator = new BlockIterator(egg.getWorld(), egg.getLocation().toVector(), egg.getVelocity().normalize(), 0, 4);

			egg.remove();
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			player.addBrokenBlock(hitBlock);
			world.playSound(hitBlock.getLocation(), Sound.CHICKEN_EGG_POP, 0.7F, 1.0F);
			FuzzyReflection.playMobSpellEffect(hitBlock.getLocation().clone().add(0.5, 0.8, 0.5), 100, 0);
			hitBlock.setType(Material.AIR);
		}
	}