public void onPlayerRespawn(final PlayerRespawnEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
		{
			return;
		}

		if (ess.getSettings().getRespawnAtHome())
		{
			Location home;
			final Location bed = user.getBedSpawnLocation();
			if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK)
			{
				home = bed;
			}
			else
			{
				home = user.getHome(user.getLocation());
			}
			if (home != null)
			{
				event.setRespawnLocation(home);
				return;
			}
		}
		final Location spawn = spawns.getSpawn(user.getGroup());
		if (spawn != null)
		{
			event.setRespawnLocation(spawn);
		}
	}
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityExplode(final EntityExplodeEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight();

    if (event.getEntity() instanceof EnderDragon
        && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) {
      event.setCancelled(true);
      if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) {
        event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
      }
      return;
    } else if (event.getEntity() instanceof Creeper
        && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
            || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
            || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) {
      // Nicccccccccce plaaacccccccccce..
      event.setCancelled(true);
      event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
      return;
    } else if (event.getEntity() instanceof TNTPrimed
        && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) {
      event.setCancelled(true);
      return;
    } else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
        && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) {
      event.setCancelled(true);
      return;
    }
    // This code will prevent explosions near protected rails, signs or protected chests
    // TODO: Use protect db instead of this code

    for (Block block : event.blockList()) {
      if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
              || block.getType() == Material.RAILS
              || block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
              || block.getType() == Material.POWERED_RAIL
              || block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
              || block.getType() == Material.DETECTOR_RAIL)
          && prot.getSettingBool(ProtectConfig.protect_rails)) {
        event.setCancelled(true);
        return;
      }
      if ((block.getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
              || block.getType() == Material.SIGN_POST
              || block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
          && prot.getSettingBool(ProtectConfig.protect_signs)) {
        event.setCancelled(true);
        return;
      }
    }
  }
	@Override
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (!user.isNew() || user.getBedSpawnLocation() != null)
		{
			return;
		}
		user.setNew(false);
		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user));
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
		}
	}
  public void reloadConfig() {
    if (storage != null) {
      storage.onPluginDeactivation();
    }
    for (ProtectConfig protectConfig : ProtectConfig.values()) {
      if (protectConfig.isList()) {
        settingsList.put(
            protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
      } else if (protectConfig.isString()) {
        settingsString.put(
            protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName()));
      } else {
        settingsBoolean.put(
            protectConfig,
            ess.getSettings()
                .getProtectBoolean(
                    protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
      }
    }

    if (getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql")) {
      try {
        storage =
            new ProtectedBlockMySQL(
                getSettingString(ProtectConfig.mysqlDB),
                getSettingString(ProtectConfig.dbUsername),
                getSettingString(ProtectConfig.dbPassword));
      } catch (PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
      }
    } else {
      try {
        storage = new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db");
      } catch (PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
      }
    }
    if (getSettingBool(ProtectConfig.memstore)) {
      storage = new ProtectedBlockMemory(storage, this);
    }
  }
	@Override
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (user.hasPlayedBefore())
		{
			LOGGER.log(Level.FINE, "Old player join");
			return;
		}		
		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
		}
		
		LOGGER.log(Level.FINE, "New player join");
	}
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		if (event.getPlayer().hasPlayedBefore())
		{
			LOGGER.log(Level.FINE, "Old player join");
			return;
		}

		final User user = ess.getUser(event.getPlayer());

		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess);
			final SimpleTextPager pager = new SimpleTextPager(output);
			ess.broadcastMessage(user, pager.getString(0));
		}

		final String kitName = ess.getSettings().getNewPlayerKit();
		if (!kitName.isEmpty())
		{
			try
			{
				final Map<String, Object> kit = ess.getSettings().getKit(kitName.toLowerCase(Locale.ENGLISH));
				final List<String> items = Kit.getItems(user, kit);
				Kit.expandItems(ess, user, items);
			}
			catch (Exception ex)
			{
				LOGGER.log(Level.WARNING, ex.getMessage());
			}
		}

		LOGGER.log(Level.FINE, "New player join");
	}
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onCreatureSpawn(final CreatureSpawnEvent event) {
   if (event.getEntity() instanceof Player) {
     return;
   }
   if (event.isCancelled()) {
     return;
   }
   final CreatureType creature = event.getCreatureType();
   if (creature == null) {
     return;
   }
   final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH);
   if (creatureName == null || creatureName.isEmpty()) {
     return;
   }
   if (ess.getSettings().getProtectPreventSpawn(creatureName)) {
     event.setCancelled(true);
   }
 }
	@Override
	public void onPlayerRespawn(final PlayerRespawnEvent event)
	{		
		final User user = ess.getUser(event.getPlayer());

		if (ess.getSettings().getRespawnAtHome())
		{
			Location home = user.getHome(user.getLocation());
			if (home == null)
			{
				home = user.getBedSpawnLocation();
			}
			if (home != null)
			{
				event.setRespawnLocation(home);
				return;
			}
		}
		final Location spawn = spawns.getSpawn(user.getGroup());
		if (spawn != null)
		{
			event.setRespawnLocation(spawn);
		}
	}