public class Ban extends CommandHandler {
	public Ban(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1)
			return lang.getString("Ban.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if (name.equalsIgnoreCase(admin))
			return lang.getString("Ban.Emo");
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		String uuid = victim.getUniqueId().toString();
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")) {
				if (sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);
			} else if (args[1].equalsIgnoreCase("-a")) {
				if (sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}

		if (plugin.cache.containsKey(uuid)) {
			for (InfoBan info : plugin.cache.get(uuid)) {
				if (info.getType() == BanType.BAN.getId()) {
					String failed = lang.getString("Ban.Failed");
					if (failed.contains(Ultrabans.VICTIM))
						failed = failed.replace(Ultrabans.VICTIM, name);
					return failed;
				}
			}
		}

		if (victim != null) {
			if (victim.isOnline()) {
				if (victim.getPlayer().hasPermission("ultraban.override.ban")
						&& !(sender instanceof ConsoleCommandSender))
					return lang.getString("Ban.Denied");
				String vicmsg = lang.getString("Ban.MsgToVictim");
				if (vicmsg.contains(Ultrabans.ADMIN))
					vicmsg = vicmsg.replace(Ultrabans.ADMIN, admin);
				if (vicmsg.contains(Ultrabans.REASON))
					vicmsg = vicmsg.replace(Ultrabans.REASON, reason);
				victim.getPlayer().kickPlayer(
						ChatColor.translateAlternateColorCodes('&', vicmsg));
			}
			name = victim.getName();
		}

		plugin.getAPI().banPlayer(uuid, reason, admin);

		String bcmsg = ChatColor.translateAlternateColorCodes('&',
				lang.getString("Ban.MsgToBroadcast"));
		if (bcmsg.contains(Ultrabans.ADMIN))
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if (bcmsg.contains(Ultrabans.REASON))
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if (bcmsg.contains(Ultrabans.VICTIM))
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		// if(config.getBoolean("CleanOnBan")) Formatting.deletePlyrdat(name);
		if (config.getBoolean("ClearWarnOnBan", false))
			plugin.getAPI().clearWarn(name);
		if (plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));

		if (broadcast) {
			plugin.getServer().broadcastMessage(bcmsg);
		} else {
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		return null;
	}
} public class CheckIP extends CommandHandler {
	public CheckIP(Ultrabans ultraBan) {
		super(ultraBan);
	}

	public String command(final CommandSender sender, Command command,
			final String[] args) {
		if (args.length < 1)
			return lang.getString("CheckIP.Arguments");
		try {
			String player_name = args[0];
			OfflinePlayer n = plugin.getServer().getOfflinePlayer(
					Formatting.expandName(player_name));
			if (n == null) {
				return lang.getString("CheckIP.NoPlayer");
			}
			String ip = plugin.getUBDatabase().getAddress(
					n.getUniqueId().toString());
			InetAddress inet = null;
			if (ip != null)
				inet = InetAddress.getByName(ip);
			if (n.isOnline())
				inet = n.getPlayer().getAddress().getAddress();
			if (inet == null) {
				return lang.getString("CheckIP.NoPlayer");
			}
			ip = inet.getHostAddress();
			/*
			 * 
			 * String ip = plugin.getUBDatabase().getAddress(p); InetAddress
			 * inet = null; if(ip != null){ inet = InetAddress.getByName(ip);
			 * }else{ OfflinePlayer n = plugin.getServer().getOfflinePlayer(p);
			 * if(n!=null && n.isOnline()){ inet =
			 * n.getPlayer().getAddress().getAddress(); ip =
			 * inet.getHostAddress();
			 * plugin.getUBDatabase().setAddress(n.getName().toLowerCase(), ip);
			 * }else{ return lang.getString("CheckIP.NoPlayer"); } }
			 */
			sender.sendMessage(ChatColor.YELLOW + "------[" + n.getName() + "]------");
			sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
					lang.getString("CheckIP.MSG1"))
					+ ChatColor.GRAY + ip);
			sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
					lang.getString("CheckIP.MSG2"))
					+ ChatColor.GRAY + inet.getHostName());
		} catch (UnknownHostException e) {
			sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
					lang.getString("CheckIP.Exception")));
		}

		return null;
	}
} public class Checkban extends CommandHandler {
	public Checkban(Ultrabans ultraBan) {
		super(ultraBan);
	}

	public String command(final CommandSender sender, Command command,
			String[] args) {
		if (args.length < 1)
			return lang.getString("CheckBan.Arguments");
		String name = args[0];
		name = Formatting.expandName(name);
		OfflinePlayer check = plugin.getServer().getOfflinePlayer(name);
		if (check != null)
			name = check.getName();
		String uuid = check.getUniqueId().toString();

		List<InfoBan> bans = plugin.getUBDatabase().listRecords(uuid);
		if (bans.isEmpty()) {
			String msg = lang.getString("CheckBan.None");
			if (msg.contains(Ultrabans.AMOUNT))
				msg = msg
						.replace(Ultrabans.AMOUNT, String.valueOf(bans.size()));
			if (msg.contains(Ultrabans.VICTIM))
				msg = msg.replace(Ultrabans.VICTIM, name);
			return msg;
		}
		String msg = lang.getString("CheckBan.Header");
		if (msg.contains(Ultrabans.AMOUNT))
			msg = msg.replace(Ultrabans.AMOUNT, String.valueOf(bans.size()));
		if (msg.contains(Ultrabans.VICTIM))
			msg = msg.replace(Ultrabans.VICTIM, bans.get(0).getName());
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
		for (InfoBan ban : bans) {
			sender.sendMessage(ChatColor.RED + BanType.toCode(ban.getType())
					+ ": " + ChatColor.GREEN + ban.getReason() + ChatColor.AQUA
					+ " by " + ban.getAdmin());
		}
		return null;
	}

} public class Clean extends CommandHandler{
	public Clean(Ultrabans ultraBan) {
		super(ultraBan);
	}
	
	public String command(final CommandSender sender, Command command, String[] args) {
		int count = 0;
		for(String name:plugin.cache.keySet()){
			OfflinePlayer of = plugin.getServer().getOfflinePlayer(name);
			if(of!=null && Formatting.deletePlyrdat(of.getName())) 
				count++;
		}
		String msg = lang.getString("Clean.Complete");
		if(msg.contains(Ultrabans.AMOUNT)) 
			msg = msg.replace(Ultrabans.AMOUNT, String.valueOf(count));
		return msg;
	}

} public class DupeIP extends CommandHandler{
	public DupeIP(Ultrabans ultraBan) {
		super(ultraBan);
	}
	
	public String command(final CommandSender sender, Command command, final String[] args) {
		if (args.length < 1) 
			return lang.getString("DupeIP.Argument");
		String name = Formatting.expandName(args[0]);
		String ip = plugin.getUBDatabase().getAddress(name);
		if(ip == null){
			OfflinePlayer n = plugin.getServer().getOfflinePlayer(name);
			if(n!=null && n.isOnline()){
				ip = n.getPlayer().getAddress().getAddress().getHostAddress();
				plugin.getUBDatabase().setAddress(n.getName().toLowerCase(), ip);
			}else{
				return lang.getString("DupeIP.NoPlayer");
			}
		}
		List<String> list = plugin.getUBDatabase().listPlayers(ip);
		String msg = lang.getString("DupeIP.Header");
		if(msg.contains(Ultrabans.VICTIM)) 
			msg = msg.replace(Ultrabans.VICTIM, name);
		if(msg.contains("%ip%")) 
			msg = msg.replace("%ip%", ip);
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<(list.size()-1);i++){
			if(!list.get(i).equalsIgnoreCase(name)){
				sb.append(list.get(i)).append(" ");
			}
		}
		if(sb.toString().length()>0)
			sender.sendMessage(ChatColor.GRAY+sb.toString());
		return lang.getString("DupeIP.Completed");
	}
} public class Export extends CommandHandler{
	public Export(Ultrabans ultraBan) {
		super(ultraBan);
	}
	
	public String command(final CommandSender sender, Command command, String[] args) {
		try{
			BufferedWriter banlist = new BufferedWriter(new FileWriter("banned-players.txt",true));
			for(String p : plugin.cache.keySet()){
				for(InfoBan info : plugin.cache.get(p)){
					if(info.getType() == BanType.BAN.getId()){
						banlist.newLine();
						banlist.write(g(p, info.getAdmin(), info.getReason()));
					}
				}
			}
			banlist.close();
			BufferedWriter iplist = new BufferedWriter(new FileWriter("banned-ips.txt",true));
			for(String p : plugin.cacheIP.keySet()){
				for(InfoBan info : plugin.cacheIP.get(p)){
					if(info.getType() == BanType.IPBAN.getId()){
						iplist.newLine();
						iplist.write(g(p, info.getAdmin(), info.getReason()));
					}
				}
			}
			iplist.close();
		}catch(IOException e){
			String msg = ChatColor.translateAlternateColorCodes('&', lang.getString("Export.Failed"));
			if(plugin.getLog())
				plugin.getLogger().severe(ChatColor.stripColor(msg));
			e.printStackTrace();
			return msg;
		}
		String msg = ChatColor.translateAlternateColorCodes('&', lang.getString("Export.Completed"));
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(msg));
		return msg;
	}
	
	public String g(String player, String admin, String reason) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
		Date now = new Date();
		now.setTime(System.currentTimeMillis());
	    StringBuilder sb = new StringBuilder();
	    sb.append(player).append("|").append(format.format(now)).append("|");
	    if(admin==null||admin.equalsIgnoreCase("")) 
	    	admin = "Ultrabans";
	    sb.append(admin).append("|").append("Forever").append("|");
	    if(reason.equalsIgnoreCase("")) 
	    	reason = "Exported from Ultrabans";
	    sb.append(reason);
	    return sb.toString();
	}
} public class Help extends CommandHandler{
	public Help(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if(args.length>0){
			Bukkit.getServer().dispatchCommand(sender, "help Ultrabans " + args[0]);
		}else{
			Bukkit.getServer().dispatchCommand(sender, "help Ultrabans");
		}
		return null;
	}
} public class History extends CommandHandler{
	public History(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		String size = "5";
		if (args.length > 0) 
			size = args[0];
		List<InfoBan> bans = plugin.getUBDatabase().listRecent(size);
		if(bans.size() < 1)
			return lang.getString("History.Failed");
		String msg = lang.getString("History.Header");
		if(msg.contains(Ultrabans.AMOUNT)) 
			msg = msg.replace(Ultrabans.AMOUNT, args[0]);
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
		for(InfoBan ban : bans){
			Date date = new Date();
			date.setTime(ban.getEndTime()*1000);
			String dateStr = date.toString();
			switch(BanType.fromID(ban.getType())){
				case TEMPBAN:
				case TEMPIPBAN:
				case TEMPJAIL:{
					sender.sendMessage(ChatColor.RED + BanType.toCode(ban.getType()) + ": " + ban.getName() + ChatColor.GRAY + " by " + ban.getAdmin() + " till " + dateStr.substring(4, 19) + " for " + ban.getReason());
					break;
				}
				default:{
					sender.sendMessage(ChatColor.RED + BanType.toCode(ban.getType()) + ": " + ban.getName() + ChatColor.GRAY + " by " + ban.getAdmin() + " for " + ban.getReason());
					break;	
				}
			}
		}
		return null;
	}
} public class Import extends CommandHandler{
	public Import(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, Command command, String[] args) {
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Import.Loading")));
		try {
			BufferedReader banlist = new BufferedReader(new FileReader("banned-players.txt"));
			String p;
			while ((p = banlist.readLine()) != null){
				if(!p.contains("#")&&p.length()>0){
					g(p);
				}
			}
			banlist.close();
			BufferedReader bannedIP = new BufferedReader(new FileReader("banned-ips.txt"));
			String ip;
			while ((ip = bannedIP.readLine()) != null){
				if(ip!=null&&!ip.contains("#")&&ip.length()>0){
				    String[] args1 = ip.split("\\|");
				    String name = args1[0].trim();
					String cknullIP = plugin.getUBDatabase().getName(name);
					if (cknullIP == null)
						name = "imported";
					plugin.getAPI().ipbanPlayer(name, ip, "imported", sender.getName());
				}
			}
			bannedIP.close();
		}catch(IOException e){
			String msg = ChatColor.translateAlternateColorCodes('&', lang.getString("Import.Failed"));
			sender.sendMessage(msg);
			if(plugin.getLog())
				plugin.getLogger().severe(ChatColor.stripColor(msg));
		}
		String msg = ChatColor.translateAlternateColorCodes('&', lang.getString("Import.Completed"));
		if(plugin.getLog())
			plugin.getLogger().severe(ChatColor.stripColor(msg));
		return msg;
	}

	public void g(String line) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
	    String[] args = line.split("\\|");
	    if(args.length<4) return;
	    String name = args[0].trim();
	    long temp = 0;
	    int type = 0;
	    try {
		    if(!args[3].trim().equalsIgnoreCase("Forever")){
		    	temp=format.parse(args[3].trim()).getTime();
		    }
		} catch (ParseException e) {
			e.printStackTrace();
		}
	    String admin = args[2].trim();
	    String reason = args[4];
	    plugin.getAPI().addPlayer(name, reason, admin, temp, BanType.fromID(type));
		plugin.getUBDatabase().addPlayer(name, reason, admin, temp, type);
	}
} public class Inventory extends CommandHandler{
	public Inventory(Ultrabans instance) {
		super(instance);
	}
	
	public String command(CommandSender sender, Command command, String[] args) {
		if(sender instanceof Player){
			if (args.length < 1) 
				return lang.getString("InvOf.Arguments");
			OfflinePlayer victim = plugin.getServer().getOfflinePlayer(args[0]);
			if(victim==null||!victim.isOnline()){
				return ChatColor.translateAlternateColorCodes('&', lang.getString("InvOf.Failed"));
			}
			((Player) sender).openInventory(victim.getPlayer().getInventory());
			return null;
		}
		return ChatColor.translateAlternateColorCodes('&', lang.getString("InvOf.Console"));
	}
} public class Ipban extends CommandHandler{
	public Ipban(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command,  String[] args) {
		if (args.length < 1) 
			return lang.getString("IPBan.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if(name.equalsIgnoreCase(admin))
			return lang.getString("IPBan.Emo");
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")){
				if(	sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);	
			} else if (args[1].equalsIgnoreCase("-a")){
				if(sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);	
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}
		if(Formatting.validIP(name)){
			String pname = plugin.getUBDatabase().getName(name);
			if (pname == null)
				pname = name;
			plugin.getAPI().ipbanPlayer(pname, name, reason, admin);
			String bcmsg = lang.getString("IPBan.MsgToBroadcast");
			if(bcmsg.contains(Ultrabans.ADMIN)) bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
			if(bcmsg.contains(Ultrabans.REASON)) bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
			if(bcmsg.contains(Ultrabans.VICTIM)) bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
			if(broadcast){
				plugin.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&',bcmsg));
			}else{
				sender.sendMessage(ChatColor.ITALIC + "Silent: " + ChatColor.translateAlternateColorCodes('&',bcmsg));
			}
			if(plugin.getLog())
				plugin.getLogger().info(admin + " banned player " + name + ".");
			return null;
		}
		String victimip = plugin.getUBDatabase().getAddress(name);
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim != null){
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.ipban")
						&& !admin.equalsIgnoreCase(Ultrabans.DEFAULT_ADMIN))
					return lang.getString("IPBan.Denied");
				victimip = victim.getPlayer().getAddress().getAddress().getHostAddress();
				plugin.getUBDatabase().setAddress(victim.getName(), victimip);
			}		
			name = victim.getName();
			if(victimip == null)
				victimip = plugin.getUBDatabase().getAddress(victim.getName());
		}
		if(victimip == null){
			String failed = lang.getString("IPBan.IPNotFound");
			if(failed.contains(Ultrabans.VICTIM)) 
				failed = failed.replace(Ultrabans.VICTIM, name);
			sender.sendMessage(ChatColor.translateAlternateColorCodes('&', failed));
			StringBuilder sb = new StringBuilder();
			sb.append("ban").append(" ").append(name).append(" ");
			if(!broadcast)
				sb.append("-s").append(" ");
			sb.append(reason);
			plugin.getServer().dispatchCommand(sender, sb.toString());
			return null;
		}
		if(plugin.cacheIP.containsKey(victimip)){
			String failed = lang.getString("IPBan.Failed");
			if(failed.contains(Ultrabans.VICTIM)) 
				failed = failed.replace(Ultrabans.VICTIM, name);
			return failed;
		}
		plugin.getAPI().ipbanPlayer(name, victimip, reason, admin);	
		if(victim != null && victim.isOnline()){
			String msgvic = lang.getString("IPBan.MsgToVictim");
			if(msgvic.contains(Ultrabans.ADMIN)) 
				msgvic = msgvic.replace(Ultrabans.ADMIN, admin);
			if(msgvic.contains(Ultrabans.REASON)) 
				msgvic = msgvic.replace(Ultrabans.REASON, reason);
			victim.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', msgvic));
		}			
		String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("IPBan.MsgToBroadcast"));
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(config.getBoolean("CleanOnBan")) 
			Formatting.deletePlyrdat(name);
		if(config.getBoolean("ClearWarnOnBan",false)) 
			plugin.getAPI().clearWarn(name);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}	
} public class Jail extends CommandHandler{
	public Jail(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, final Command command, final String[] args) {
		if (args.length < 1) 
			return lang.getString("Jail.Arguments");
		if(args[0].equalsIgnoreCase("setjail")){
			if(!(sender instanceof Player))
				return lang.getString("Jail.SetFail");
			plugin.jail.setJail(((Player) sender).getLocation(), "jail");
			return lang.getString("Jail.SetJail");
		}
		if(args[0].equalsIgnoreCase("setrelease")){
			if(!(sender instanceof Player))
				return lang.getString("Jail.SetFail");
			plugin.jail.setJail(((Player) sender).getLocation(), "release");
			return lang.getString("Jail.SetRelease");
		}
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")){
				if(	sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);	
			} else if (args[1].equalsIgnoreCase("-a")){
				if(sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);	
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}
		if(name.equalsIgnoreCase(admin))
			return lang.getString("Jail.Emo");
		if(plugin.cache.containsKey(name.toLowerCase())){
			for(InfoBan info: plugin.cache.get(name.toLowerCase())){
				if(info.getType() == BanType.JAIL.getId()){
					String msg = lang.getString("Jail.Failed");
					if(msg.contains(Ultrabans.VICTIM)) 
						msg = msg.replace(Ultrabans.VICTIM, name);
					return msg;
				}
			}
		}
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim !=null){
			name = victim.getName();
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.jail"))
					return lang.getString("Jail.Denied");
				String msgvic = lang.getString("Jail.MsgToVictim");
				if(msgvic.contains(Ultrabans.ADMIN)) 
					msgvic = msgvic.replace(Ultrabans.ADMIN, admin);
				if(msgvic.contains(Ultrabans.REASON)) 
					msgvic = msgvic.replace(Ultrabans.REASON, reason);
				victim.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', msgvic));
				victim.getPlayer().teleport(plugin.jail.getJail("jail"));
			} 
		}		
		String bcmsg = lang.getString("Jail.MsgToBroadcast");
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON))
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}

} public class Kick extends CommandHandler{
	public Kick(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1) 
			return lang.getString("Kick.Arguments");
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		boolean broadcast = true;
		if (sender instanceof Player)
			admin = sender.getName();
		if((args[0].equals("*") || args[0].equals("all")) && sender.hasPermission("ultrabans.kick.all")){
			if(args.length > 1)
				reason = Formatting.combineSplit(1, args);
			String adminMsg = ChatColor.translateAlternateColorCodes('&', lang.getString("Kick.MsgToAll"));
			if(adminMsg.contains(Ultrabans.ADMIN))
				adminMsg = adminMsg.replace(Ultrabans.ADMIN, admin);
			if(adminMsg.contains(Ultrabans.REASON)) 
				adminMsg = adminMsg.replace(Ultrabans.REASON, reason);
			for (Player players:plugin.getServer().getOnlinePlayers()){
				if (!players.hasPermission("ultraban.override.kick.all")){
					players.kickPlayer(adminMsg);
				}
			}
			if(plugin.getLog())
				plugin.getLogger().info(ChatColor.stripColor(adminMsg));
			return adminMsg;
		}
		String name = Formatting.expandName(args[0]);
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")){
				if(	sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);	
			} else if (args[1].equalsIgnoreCase("-a")){
				if(sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);	
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}
		Player victim = plugin.getServer().getPlayer(name);
		if(victim == null)
			return lang.getString("Kick.Online");
		if(victim.getName().equalsIgnoreCase(admin))
			return lang.getString("Kick.Emo");
		if(victim.hasPermission("ultraban.override.kick"))
			return lang.getString("Kick.Denied");
		plugin.getAPI().kickPlayer(name, reason, admin);
		String msgvic = ChatColor.translateAlternateColorCodes('&', lang.getString("Kick.MsgToVictim"));
		if(msgvic.contains(Ultrabans.ADMIN)) 
			msgvic = msgvic.replace(Ultrabans.ADMIN, admin);
		if(msgvic.contains(Ultrabans.REASON)) 
			msgvic = msgvic.replace(Ultrabans.REASON, reason);
		victim.kickPlayer(msgvic);
		String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("Kick.MsgToBroadcast"));
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, victim.getName());
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}
} public class Lockdown extends CommandHandler{
	public Lockdown(Ultrabans instance) {
		super(instance);
	}
	
	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1) 
			return lang.getString("Lockdown.Arguments");
		String admin = Ultrabans.DEFAULT_ADMIN;
		if (sender instanceof Player)
			admin = sender.getName();
		boolean locked = config.getBoolean("Lockdown", false);
		String toggle = args[0];
		if (toggle.equalsIgnoreCase("on")){ 
			if(!locked){ 
				plugin.getConfig().set("Lockdown",(boolean) true);
		        plugin.saveConfig();
				if(plugin.getLog())
					plugin.getLogger().info(admin + " initiated lockdown.");
				return lang.getString("Lockdown.Start");
			}
			return lang.getString("Lockdown.LoginMsg");
		}
		if (toggle.equalsIgnoreCase("off")){
			if(locked){
				plugin.getConfig().set("Lockdown",(boolean) false);
		        plugin.saveConfig();
				if(plugin.getLog())
					plugin.getLogger().info(admin + " disabled lockdown.");
				return lang.getString("Lockdown.End");
			}
			return lang.getString("Lockdown.Status");
		}
		return locked?lang.getString("Lockdown.LoginMsg"):lang.getString("Lockdown.Status");
	}
} public class Mute extends CommandHandler{
	public Mute(Ultrabans instance) {
		super(instance);
	}
	
	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1) 
			return lang.getString("Mute.Arguments");
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if (args.length > 1) {
			reason = Formatting.combineSplit(1, args);
		}
		if(name.equalsIgnoreCase(admin))
			return lang.getString("Mute.Emo");
		Player victim = plugin.getServer().getPlayer(name);
		if(victim != null){
			if(victim.hasPermission("ultraban.override.mute"))
				return lang.getString("Messages.Mute.Denied");
			if (plugin.muted.contains(name.toLowerCase())){
				plugin.muted.remove(name.toLowerCase());
		 		victim.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Mute.UnmuteMsgToVictim")));
				String adminMsgs = lang.getString("Messages.Mute.UnmuteMsgToSender","You have unmuted %victim%.");
				if(adminMsgs.contains(Ultrabans.VICTIM)) 
					adminMsgs = adminMsgs.replace(Ultrabans.VICTIM, name);
				return adminMsgs;
			}
			plugin.getAPI().mutePlayer(name, reason, admin);
	 		victim.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Mute.MuteMsgToVictim")));
	 		String adminMsgs = ChatColor.translateAlternateColorCodes('&', lang.getString("Mute.MuteMsgToSender"));
			if(adminMsgs.contains(Ultrabans.VICTIM)) 
				adminMsgs = adminMsgs.replace(Ultrabans.VICTIM, name);
			plugin.getLogger().info(ChatColor.stripColor(adminMsgs));
			return adminMsgs;
		}
		if (plugin.muted.contains(name.toLowerCase())){
			plugin.muted.remove(name.toLowerCase());
			String adminMsgs = lang.getString("Mute.UnmuteMsgToSender");
			if(adminMsgs.contains(Ultrabans.VICTIM)) 
				adminMsgs = adminMsgs.replace(Ultrabans.VICTIM, name);
	 		return adminMsgs;
		}				
		return lang.getString("Mute.Failed");	
	}

} public class Pardon extends CommandHandler{
	public Pardon(Ultrabans instance) {
		super(instance);
	}
	
	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1) 
			return lang.getString("Pardon.Arguments");
		String admin = Ultrabans.DEFAULT_ADMIN;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if(plugin.cache.containsKey(name.toLowerCase())){
			for(InfoBan info: plugin.cache.get(name.toLowerCase())){
				if(info.getType() == BanType.JAIL.getId()){
					plugin.cache.remove(name.toLowerCase());
					String bcmsg = lang.getString("Pardon.Msg");
					if(bcmsg.contains(Ultrabans.ADMIN)) 
						bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
					if(bcmsg.contains(Ultrabans.VICTIM)) 
						bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
					plugin.getAPI().pardonPlayer(name, admin);
					Player victim = plugin.getServer().getPlayer(name);
					if(victim != null){
						Location stlp = plugin.jail.getJail("release");
						if(stlp != null){
							victim.teleport(stlp);
						}else{
							victim.teleport(victim.getBedSpawnLocation());
						}
						victim.sendMessage(bcmsg);
					}
					return bcmsg;
				}
			}
		}
		return lang.getString("Pardon.Failed");
	}
} public class Perma extends CommandHandler {
	public Perma(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1)
			return lang.getString("PermaBan.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = args[0];
		name = Formatting.expandName(name);
		if(name.equalsIgnoreCase(admin))
			return lang.getString("PermaBan.Emo");
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")){
				if(	sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);	
			} else if (args[1].equalsIgnoreCase("-a")){
				if(sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);	
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}
		if(plugin.cache.containsKey(name.toLowerCase())){
			for(InfoBan info: plugin.cache.get(name.toLowerCase())){
				if(info.getType() == BanType.BAN.getId()){
					String failed = lang.getString("PermaBan.Failed");
					if(failed.contains(Ultrabans.VICTIM))
						failed = failed.replace(Ultrabans.VICTIM, name);
					return failed; 					
				}
			}
		}
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim != null){
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.permaban") &&
						!admin.equalsIgnoreCase(Ultrabans.ADMIN))
					return lang.getString("PermaBan.Denied");
				String vicmsg = lang.getString("PermaBan.MsgToVictim");
				if(vicmsg.contains(Ultrabans.ADMIN))
					vicmsg = vicmsg.replace(Ultrabans.ADMIN, admin);
				if(vicmsg.contains(Ultrabans.REASON)) 
					vicmsg = vicmsg.replace(Ultrabans.REASON, reason);
				victim.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', vicmsg));
			}
			name = victim.getName();
		}
		plugin.getAPI().permabanPlayer(name, reason, admin);
		String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("PermaBan.MsgToBroadcast"));
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(config.getBoolean("CleanOnBan")) 
			Formatting.deletePlyrdat(name);
		if(config.getBoolean("ClearWarnOnBan",false)) 
			plugin.getAPI().clearWarn(name);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}
} public class Ping extends CommandHandler{
	public Ping(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, Command command, String[] args) {
		if(args.length>0){
			Player p = plugin.getServer().getPlayer(args[0]);
			if(p!=null){
				String ping = null;
	            for(Method meth:p.getClass().getMethods()){
	            	if(meth.getName().equals("getHandle")){
						try {
							Object obj = meth.invoke(p, (Object[]) null);
		            		for(Field field:obj.getClass().getFields())
		            			if(field.getName().equals("ping"))
		            				ping = String.valueOf(field.getInt(obj));
						} catch (Exception e) {
							e.printStackTrace();
						}
	            	}
	            }
	            String msg = lang.getString("Ping.Personal");
	            if(msg.contains(Ultrabans.VICTIM))
	            	msg.replace(Ultrabans.VICTIM, p.getName());
	            if(msg.contains(Ultrabans.AMOUNT))
	            	msg.replace(Ultrabans.AMOUNT, String.valueOf(ping));
				return msg;
			}
			return lang.getString("Ping.Failed");
		}
		if(sender instanceof Player){
			Player p = (Player) sender;
			int ping = 0;
            for(Method meth:p.getClass().getMethods()){
            	if(meth.getName().equals("getHandle")){
					try {
						Object obj = meth.invoke(p, (Object[]) null);
	            		for(Field field:obj.getClass().getFields())
	            			if(field.getName().equals("ping"))
	            				ping = field.getInt(obj);
					} catch (Exception e) {
						e.printStackTrace();
					}
            	}    	
            }
            String msg = lang.getString("Ping.Personal");
            if(msg.contains(Ultrabans.AMOUNT))
            	msg.replace(Ultrabans.AMOUNT, String.valueOf(ping));
			return msg;
		}
		return lang.getString("Ping.Failed");
	}
} public class Reload extends CommandHandler{
	public Reload(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, Command command, String[] args) {
		plugin.reloadConfig();
		plugin.getServer().getPluginManager().disablePlugin(plugin);
		plugin.getServer().getPluginManager().enablePlugin(plugin);
		if(plugin.getLog())
			plugin.getLogger().info("Reloaded.");
		return lang.getString("Reload");
	}
} public class Spawn extends CommandHandler{
	public Spawn(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, Command command, String[] args) {
		if (args.length < 1)
			return lang.getString("Spawn.Arguments");
		String admin = Ultrabans.DEFAULT_ADMIN;
		if(sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]); 
		Player victim = plugin.getServer().getPlayer(name);
		if(victim == null){
			return lang.getString("Spawn.Failed");
		}
		victim.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Spawn.MsgToVictim")));
		victim.teleport(victim.getWorld().getSpawnLocation());	
		
		String bcmsg = lang.getString("Spawn.MsgToSender");
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		return bcmsg;
	}
} public class Starve extends CommandHandler{
	public Starve(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, Command command, String[] args) {
		if (args.length < 1)
			return lang.getString("Starve.Arguments");
		String admin = Ultrabans.DEFAULT_ADMIN;
		if(sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]); 
		Player victim = plugin.getServer().getPlayer(name);
		if(victim == null){
			return lang.getString("Starve.Failed");
		}
		victim.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Starve.MsgToVictim")));
		victim.setFoodLevel(0);	
		
		String bcmsg = lang.getString("Starve.MsgToSender");
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		return bcmsg;
	}
} public class Status extends CommandHandler{
	public Status(Ultrabans instance) {
		super(instance);
	}

	public String command(final CommandSender sender, Command command, String[] args) {
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Status.CacheHeader")));
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Status.CacheBans")
				.replace(Ultrabans.AMOUNT,String.valueOf(plugin.cache.size()))));
		sender.sendMessage(ChatColor.translateAlternateColorCodes('&', lang.getString("Status.CacheIPBans")
				.replace(Ultrabans.AMOUNT,String.valueOf(plugin.cacheIP.size()))));
		int counter=0;
		counter = counter+plugin.cache.toString().getBytes().length;
		counter = counter+plugin.cacheIP.toString().getBytes().length;
		return lang.getString("Status.Usage").replace(Ultrabans.AMOUNT, String.valueOf(counter));
	}
} public class Tempban extends CommandHandler {
	public Tempban(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 3)
			return lang.getString("Tempban.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = args[0];
		name = Formatting.expandName(name);
		if(name.equalsIgnoreCase(admin))
			return lang.getString("Tempban.Emo");
		long tempTime = 0;
		String amt = new String();
		String mode = new String();
			if(args.length > 3){
				if(args[1].equalsIgnoreCase("-s")
						&&sender.hasPermission(command.getPermission()+".silent"))
					broadcast = false;
				if(args[1].equalsIgnoreCase("-a")
						&&sender.hasPermission(command.getPermission()+".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				amt=args[2];
				mode=args[3];
				reason = Formatting.combineSplit(4, args);
				tempTime = Formatting.parseTimeSpec(amt,mode);
			}else if(args.length > 2){
				amt=args[1];
				mode=args[2];
				tempTime = Formatting.parseTimeSpec(amt, mode);
				reason = Formatting.combineSplit(3, args);
			}
		if(tempTime == 0) 
			return lang.getString("Tempban.TimeFail");
		long temp = System.currentTimeMillis()/1000+tempTime;

		if(plugin.cache.containsKey(name.toLowerCase())){
			for(InfoBan info: plugin.cache.get(name.toLowerCase())){
				if(info.getType() == BanType.TEMPBAN.getId() 
				|| info.getType() == BanType.BAN.getId()){
					String failed = lang.getString("Tempban.Failed");
					if(failed.contains(Ultrabans.VICTIM))
						failed = failed.replace(Ultrabans.VICTIM, name);
					return failed;
					
				}
			}
		}
		
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim != null){
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.tempban") &&
						!admin.equalsIgnoreCase(Ultrabans.ADMIN))
					return lang.getString("Tempban.Denied");
				String vicmsg = lang.getString("Tempban.MsgToVictim");
				if(vicmsg.contains(Ultrabans.ADMIN))
					vicmsg = vicmsg.replace(Ultrabans.ADMIN, admin);
				if(vicmsg.contains(Ultrabans.REASON)) 
					vicmsg = vicmsg.replace(Ultrabans.REASON, reason);
				victim.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', vicmsg));
			}
			name = victim.getName();
		}
		plugin.getAPI().tempbanPlayer(name, reason, temp, admin);
		String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("Tempban.MsgToBroadcast"));
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}
} public class Tempipban  extends CommandHandler {
	public Tempipban(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 3)
			return lang.getString("Tempban.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = args[0];
		name = Formatting.expandName(name);
		if(name.equalsIgnoreCase(admin))
			return lang.getString("Tempban.Emo");
		long tempTime = 0;
		String amt = new String();
		String mode = new String();
			if(args.length > 3){
				if(args[1].equalsIgnoreCase("-s")
						&&sender.hasPermission(command.getPermission()+".silent"))
					broadcast = false;
				if(args[1].equalsIgnoreCase("-a")
						&&sender.hasPermission(command.getPermission()+".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				amt=args[2];
				mode=args[3];
				reason = Formatting.combineSplit(4, args);
				tempTime = Formatting.parseTimeSpec(amt,mode);
			}else if(args.length > 2){
				amt=args[1];
				mode=args[2];
				tempTime = Formatting.parseTimeSpec(amt, mode);
				reason = Formatting.combineSplit(3, args);
			}
		if(tempTime == 0) 
			return lang.getString("Tempban.TimeFail");
		long temp = System.currentTimeMillis()/1000+tempTime;		
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim != null){
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.tempban") &&
						!admin.equalsIgnoreCase(Ultrabans.ADMIN))
					return lang.getString("Tempban.Denied");
				String msgvic = lang.getString("TempIpBan.MsgToVictim");
				if(msgvic.contains(Ultrabans.ADMIN)) 
					msgvic = msgvic.replace(Ultrabans.ADMIN, admin);
				if(msgvic.contains(Ultrabans.REASON))
					msgvic = msgvic.replace(Ultrabans.REASON, reason);
				if(msgvic.contains(Ultrabans.AMOUNT)) 
					msgvic = msgvic.replace(Ultrabans.AMOUNT, amt);
				if(msgvic.contains(Ultrabans.MODE)) 
					msgvic = msgvic.replace(Ultrabans.MODE, mode);
				victim.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', msgvic));
			}
			name = victim.getName();
		}
		String offlineip = plugin.getUBDatabase().getAddress(name);
		if(offlineip != null){
			if(plugin.cacheIP.containsKey(offlineip)){
				for(InfoBan info: plugin.cache.get(offlineip)){
					if(info.getType() == BanType.TEMPBAN.getId() 
					|| info.getType() == BanType.BAN.getId()){
						String failed = lang.getString("TempIpBan.Failed");
						if(failed.contains(Ultrabans.VICTIM))
							failed = failed.replace(Ultrabans.VICTIM, name);
						return failed;
					}
				}
			}
		}else{
			StringBuilder sb = new StringBuilder();
			sb.append("tempban ").append(name+" ");
			if(!broadcast)
				sb.append("-s ");
			sb.append(amt+" ").append(mode+" ").append(reason);
			plugin.getServer().dispatchCommand(sender, sb.toString());
			String failed = lang.getString("TempIpBan.IPNotFound");
			if(failed.contains(Ultrabans.VICTIM))
				failed = failed.replace(Ultrabans.VICTIM, name);
			return failed;
		}
		
		plugin.getAPI().tempipbanPlayer(name, offlineip, reason, temp, admin);
		String bcmsg = lang.getString("TempIpBan.MsgToBroadcast");
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(bcmsg.contains(Ultrabans.AMOUNT)) 
			bcmsg = bcmsg.replace(Ultrabans.AMOUNT, amt);
		if(bcmsg.contains(Ultrabans.MODE)) 
			bcmsg = bcmsg.replace(Ultrabans.MODE, mode);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(bcmsg);
		return bcmsg;
	}
} public class Tempjail extends CommandHandler {
	public Tempjail(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 3)
			return lang.getString("Tempjail.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = args[0];
		name = Formatting.expandName(name);
		if(name.equalsIgnoreCase(admin))
			return lang.getString("Tempjail.Emo");
		long tempTime = 0;
		String amt = new String();
		String mode = new String();
			if(args.length > 3){
				if(args[1].equalsIgnoreCase("-s")
						&&sender.hasPermission(command.getPermission()+".silent"))
					broadcast = false;
				if(args[1].equalsIgnoreCase("-a")
						&&sender.hasPermission(command.getPermission()+".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				amt=args[2];
				mode=args[3];
				reason = Formatting.combineSplit(4, args);
				tempTime = Formatting.parseTimeSpec(amt,mode);
			}else if(args.length > 2){
				amt=args[1];
				mode=args[2];
				tempTime = Formatting.parseTimeSpec(amt, mode);
				reason = Formatting.combineSplit(3, args);
			}
		if(tempTime == 0) 
			return lang.getString("Tempjail.TimeFail");
		long temp = System.currentTimeMillis()/1000+tempTime;

		if(plugin.cache.containsKey(name.toLowerCase())){
			for(InfoBan info: plugin.cache.get(name.toLowerCase())){
				if(info.getType() == BanType.TEMPJAIL.getId() 
				|| info.getType() == BanType.JAIL.getId()){
					String failed = lang.getString("Tempjail." +
							"Failed");
					if(failed.contains(Ultrabans.VICTIM))
						failed = failed.replace(Ultrabans.VICTIM, name);
					return failed;					
				}
			}
		}
		
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim != null){
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.tempjail") &&
						!admin.equalsIgnoreCase(Ultrabans.ADMIN))
					return lang.getString("Tempjail.Denied");
				String vicmsg = lang.getString("Tempjail.MsgToVictim");
				if(vicmsg.contains(Ultrabans.ADMIN))
					vicmsg = vicmsg.replace(Ultrabans.ADMIN, admin);
				if(vicmsg.contains(Ultrabans.REASON)) 
					vicmsg = vicmsg.replace(Ultrabans.REASON, reason);
				//victim.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', vicmsg)); //Teleport
			}
			name = victim.getName();
		}
		plugin.getAPI().tempjailPlayer(name, reason, temp, admin);
		String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("Tempjail.MsgToBroadcast"));
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}
} public class Unban extends CommandHandler {
	public Unban(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1)
			return lang.getString("Unban.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")){
				if(	sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);	
			} else if (args[1].equalsIgnoreCase("-a")){
				if(sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);	
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}
		OfflinePlayer of = plugin.getServer().getOfflinePlayer(name);
		if(of!=null){
			if(of.isBanned()) 
				of.setBanned(false);
			name = of.getName();
		}
		int count = 0;
		String ip = plugin.getUBDatabase().getAddress(name);
		if(ip != null && plugin.cacheIP.containsKey(ip)){
			count++;
			plugin.cacheIP.remove(ip);
			if(plugin.getLog())
				plugin.getLogger().info("Removed IP ban!");
		}
		
		if(Formatting.validIP(name)){
			if(plugin.cacheIP.containsKey(name)){
				for(BanInfo info : plugin.cacheIP.get(name)){
					name = info.getName();
					reason = info.getReason();
					admin = info.getAdmin();
					plugin.getUBDatabase().removeFromBanlist(name);
					plugin.getUBDatabase().addPlayer(name, "Unbanned: " + reason, admin, 0, 5);
					plugin.getLogger().info(admin + " unbanned player " + name + ".");	
					//TODO:
					String bcmsg = lang.getString("Unban.MsgToBroadcast", "%victim% was unbanned by %admin%!");
					bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
					bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
					plugin.getServer().broadcastMessage(bcmsg);					
				}
				return null;
			}else{
				//TODO: Unban failed for that IP
				return "Failed IP";
			}
		}

		List<BanInfo> list = new ArrayList<BanInfo>();
		if(plugin.cache.containsKey(name.toLowerCase())){
			for(BanInfo info : plugin.cache.get(name.toLowerCase())){
				switch(BanType.fromID(info.getType())){
					case BAN:
					case IPBAN:
					case TEMPBAN:
					case TEMPIPBAN:{
						list.add(info);
						count++;
						break;
					}
					case PERMA:{
						String perma = config.getString("Messages.Unban.PermaBanned");
						perma = perma.replace(Ultrabans.VICTIM, name);
						if(plugin.getLog())
							plugin.getLogger().info(perma);
						return perma;
					}
					case INFO:
					case JAIL:
					case KICK:
					case MUTE:
					case TEMPJAIL:
					case UNBAN:
					case WARN:
					default:
						break;
				}
			}
		}
		if(count!=0){
			List<BanInfo> lt = plugin.cache.get(name.toLowerCase());
			for(BanInfo info: list){
				if(config.getBoolean("UnbansLog.Enable", true)){
					reason = info.getReason();
					if(config.getBoolean("UnbansLog.LogReason",true) && reason != null){
						plugin.getUBDatabase().addPlayer(name, "Unbanned: "+reason, admin, 0, 5);
					}else{
						plugin.getUBDatabase().addPlayer(name, "Unbanned", admin, 0, 5);
					}
				}
				lt.remove(info);
			}
			plugin.getUBDatabase().removeFromBanlist(name);
			plugin.cache.put(name.toLowerCase(), lt);
			String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("Unban.MsgToBroadcast"));
			if(bcmsg.contains(Ultrabans.ADMIN)) 
				bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
			if(bcmsg.contains(Ultrabans.VICTIM)) 
				bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
			if(broadcast){
				plugin.getServer().broadcastMessage(bcmsg);
			}else{
				sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
			}
			if(plugin.getLog())
				plugin.getLogger().info(ChatColor.stripColor(bcmsg));
			return null;
		}
		String failed = config.getString("Messages.Unban.Failed", "%victim% is already unbanned!");
		failed = failed.replace(Ultrabans.VICTIM, name);
		return failed;
	}
} public class Warn extends CommandHandler {
	public Warn(Ultrabans instance) {
		super(instance);
	}

	public String command(CommandSender sender, Command command, String[] args) {
		if (args.length < 1)
			return lang.getString("Warn.Arguments");
		boolean broadcast = true;
		String admin = Ultrabans.DEFAULT_ADMIN;
		String reason = Ultrabans.DEFAULT_REASON;
		if (sender instanceof Player)
			admin = sender.getName();
		String name = Formatting.expandName(args[0]);
		if(name.equalsIgnoreCase(admin))
			return lang.getString("Warn.Emo");
		if (args.length > 1) {
			if (args[1].equalsIgnoreCase("-s")){
				if(	sender.hasPermission(command.getPermission() + ".silent"))
					broadcast = false;
				reason = Formatting.combineSplit(2, args);	
			} else if (args[1].equalsIgnoreCase("-a")){
				if(sender.hasPermission(command.getPermission() + ".anon"))
					admin = Ultrabans.DEFAULT_ADMIN;
				reason = Formatting.combineSplit(2, args);	
			} else {
				reason = Formatting.combineSplit(1, args);
			}
		}
		OfflinePlayer victim = plugin.getServer().getOfflinePlayer(name);
		if(victim != null){
			if(victim.isOnline()){
				if(victim.getPlayer().hasPermission("ultraban.override.warn") &&
						!admin.equalsIgnoreCase(Ultrabans.ADMIN))
					return lang.getString("Warn.Denied");
				String vicmsg = lang.getString("Warn.MsgToVictim");
				if(vicmsg.contains(Ultrabans.ADMIN))
					vicmsg = vicmsg.replace(Ultrabans.ADMIN, admin);
				if(vicmsg.contains(Ultrabans.REASON)) 
					vicmsg = vicmsg.replace(Ultrabans.REASON, reason);
				victim.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', vicmsg));
				
			}
			name = victim.getName();
		}
		if(config.getBoolean("MaxWarning.Enable", false)){
			Integer max = config.getInt("MaxWarning.Amt", 5);
			String idoit = victim.getName();
			if(plugin.getUBDatabase().maxWarns(idoit) != null && plugin.getUBDatabase().maxWarns(idoit).size() >= max){
				String cmd = config.getString("MaxWarning.Result", "ban");
				String r = config.getString("MaxWarning.Reason","Max Warns");
				boolean s = config.getBoolean("MaxWarning.Silent",true);
				StringBuilder sb = new StringBuilder();
				if(cmd.equalsIgnoreCase("ban") 
						|| cmd.equalsIgnoreCase("kick") 
						|| cmd.equalsIgnoreCase("ipban") 
						|| cmd.equalsIgnoreCase("jail") 
						|| cmd.equalsIgnoreCase("permaban")){
					sb.append(cmd+" ").append(idoit+" ");
					if(s)
						sb.append("-s ");
					sb.append(r);
					plugin.getServer().dispatchCommand(sender, sb.toString());
					
				}else if(cmd.equalsIgnoreCase("tempban") 
						|| cmd.equalsIgnoreCase("tempipban") 
						|| cmd.equalsIgnoreCase("tempjail")){
					sb.append(cmd+" ").append(idoit+" ");
					if(s)
						sb.append("-s ");
					sb.append(config.getString("MaxWarning.Temp.Amt", "5")+" ")
						.append(config.getString("MaxWarning.Temp.Mode", "day")+" ")
						.append(r);
					plugin.getServer().dispatchCommand(sender, sb.toString());
				}else{
					String fakecmd = "ban" + " " + idoit + " " + "-s" + " " + r;
					plugin.getServer().dispatchCommand(sender, fakecmd);
				}
				return null;
			}	
		}
		plugin.getAPI().warnPlayer(name, reason, admin);
		String bcmsg = ChatColor.translateAlternateColorCodes('&', lang.getString("Warn.MsgToBroadcast"));
		if(bcmsg.contains(Ultrabans.ADMIN)) 
			bcmsg = bcmsg.replace(Ultrabans.ADMIN, admin);
		if(bcmsg.contains(Ultrabans.REASON)) 
			bcmsg = bcmsg.replace(Ultrabans.REASON, reason);
		if(bcmsg.contains(Ultrabans.VICTIM)) 
			bcmsg = bcmsg.replace(Ultrabans.VICTIM, name);
		if(broadcast){
			plugin.getServer().broadcastMessage(bcmsg);
		}else{
			sender.sendMessage(ChatColor.ITALIC + "Silent: " + bcmsg);
		}
		if(plugin.getLog())
			plugin.getLogger().info(ChatColor.stripColor(bcmsg));
		return null;
	}
} public abstract class Database {
	Ultrabans plugin;
	String bantable;
	String iptable;
	String aliastable;
	
	Connection connection;

	public Database(Ultrabans instance) {
		plugin = instance;
	}

	public abstract Connection getSQLConnection();

	public abstract void load();

	//XXX:Rewrite
	public void initialize() {
		connection = getSQLConnection();
		try {
			PreparedStatement ps = connection.prepareStatement(
					"SELECT * FROM " + bantable + " WHERE type != 8 AND type != 5");
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				String uuid = rs.getString("uuid");
				
				List<InfoBan> list = new ArrayList<InfoBan>();
				if (plugin.cache.containsKey(uuid))
					list = plugin.cache.get(uuid);
				
				list.add(new InfoBan(rs.getString("uuid"), rs
						.getString("reason"), rs.getString("admin"), rs
						.getLong("temptime"), rs.getInt("type")));
				plugin.cache.put(uuid.toLowerCase(), list);
				if (rs.getInt("type") == 1 || rs.getInt("type") == 11) {
					list = new ArrayList<InfoBan>();
					String ip = getAddress(uuid);
					if (ip != null && plugin.cacheIP.containsKey(ip))
						list = plugin.cacheIP.get(ip);
					list.add(new InfoBan(rs.getString("uuid"), rs
							.getString("reason"), rs.getString("admin"), rs
							.getLong("temptime"), rs.getInt("type")));
					plugin.cacheIP.put(ip, list);
				}
			}
			close(ps, rs);
		} catch (SQLException ex) {
			plugin.getLogger().log(Level.SEVERE,
					"Unable to retreive connection", ex);
		}
	}
	
	public void putAddress(String uuid, String ip) throws SQLException{
		connection = getSQLConnection();
		PreparedStatement ps = connection.prepareStatement(
				"REPLACE INTO " + iptable + " (uuid,ip) VALUES(?,?)");
		ps.setString(1, uuid);
		ps.setString(2, ip);
		ps.executeUpdate();
		close(ps, null);
		return;
	}

	public List<InetAddress> getIPAddress(String uuid) throws SQLException{
		connection = getSQLConnection();
		PreparedStatement ps = connection.prepareStatement(
				"SELECT * FROM " + iptable + " WHERE uuid = ?");
		ps.setString(1, uuid);
		ResultSet rs = ps.executeQuery();
		List<InetAddress> ip = new ArrayList<InetAddress>();
		while (rs.next()) {
			try {
				ip.add(InetAddress.getByName(rs.getString("ip")));
			} catch (UnknownHostException ex) {
				Error.execute(plugin, ex);
			}
		}
		close(ps, rs);
		return ip;
	}
	
	public List<UUID> getUUID(String ip) throws SQLException {
		connection = getSQLConnection();
		PreparedStatement ps = connection.prepareStatement(
				"SELECT * FROM " + iptable + " WHERE ip = ?");
		ps.setString(1, ip);
		ResultSet rs = ps.executeQuery();
		List<UUID> uuid = new ArrayList<UUID>();
		while (rs.next()) {
			uuid.add(UUID.fromString(rs.getString("uuid")));
		}
		close(ps, rs);
		return uuid;
	}

	public boolean matchIPAddress(String uuid, String ip) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement(
				"SELECT ip FROM " + iptable	+ " WHERE uuid = ? AND ip = ?");
			ps.setString(1, uuid);
			ps.setString(2, ip);
			ResultSet rs = ps.executeQuery();
			boolean set = false;
			while (rs.next()) {
				set = true;
			}
			close(ps, rs);
			return set;
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
		return false;
	}

	//XXX:Down rewrite
	public void addUUID(String uuid, String alias, String reason, String admin,
			long tempTime, int type) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection
					.prepareStatement("INSERT INTO "
							+ bantable
							+ " (uuid,alias,reason,admin,time,temptime,type) VALUES(?,?,?,?,?,?,?)");
			ps.setString(1, uuid);
			ps.setString(3, reason);
			ps.setString(4, admin);
			ps.setLong(5, System.currentTimeMillis() / 1000);
			ps.setLong(6, tempTime);
			ps.setLong(7, type);
			ps.executeUpdate();
			close(ps, null);
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
	}

	public void importPlayer(String uuid, String reason, String admin,
			long tempTime, long time, int type) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection
					.prepareStatement("INSERT INTO "
							+ bantable
							+ " (uuid,reason,admin,time,temptime,type) VALUES(?,?,?,?,?,?)");
			ps.setLong(5, tempTime);
			ps.setString(1, uuid);
			ps.setString(2, reason);
			ps.setString(3, admin);
			ps.setLong(4, time);
			ps.setLong(6, type);
			ps.executeUpdate();
			close(ps, null);
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
	}

	public boolean removeFromBanlist(String uuid) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("DELETE FROM "
					+ bantable + " WHERE uuid = ? AND (type = 0 OR type = 1)");
			ps.setString(1, uuid);
			ps.executeUpdate();
			close(ps, null);
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
			return false;
		}
		return true;
	}

	public List<InfoBan> listRecords(String uuid) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("SELECT * FROM "
					+ bantable + " WHERE uuid = ?");
			ps.setString(1, uuid);
			ResultSet rs = ps.executeQuery();
			List<InfoBan> bans = new ArrayList<InfoBan>();
			while (rs.next()) {
				bans.add(new InfoBan(rs.getString("uuid"), rs
						.getString("reason"), rs.getString("admin"), rs
						.getLong("temptime"), rs.getInt("type")));
			}
			close(ps, rs);
			return bans;
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
		return null;
	}

	public List<InfoBan> listRecent(String number) {
		Integer num = Integer.parseInt(number.trim());
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("SELECT * FROM "
					+ bantable + " ORDER BY time DESC LIMIT ?");
			ps.setInt(1, num);
			ResultSet rs = ps.executeQuery();
			List<InfoBan> bans = new ArrayList<InfoBan>();
			while (rs.next()) {
				bans.add(new InfoBan(rs.getString("uuid"), rs
						.getString("reason"), rs.getString("admin"), rs
						.getLong("temptime"), rs.getInt("type")));
			}
			close(ps, rs);
			return bans;
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		} catch (NumberFormatException nfe) {
			plugin.getLogger().warning("Input was not a number.");
		}
		return null;
	}

	public List<InfoBan> maxWarns(String uuid) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("SELECT * FROM "
					+ bantable + " WHERE uuid = ? AND type = ?");
			ps.setString(1, uuid);
			ps.setInt(2, 2);
			ResultSet rs = ps.executeQuery();
			List<InfoBan> bans = new ArrayList<InfoBan>();
			while (rs.next()) {
				String[] alias = rs.getString("alias").split(",");
				bans.add(new InfoBan(rs.getString("uuid"), alias, rs
						.getString("reason"), rs.getString("admin"), rs
						.getLong("temptime"), rs.getInt("type")));
			}
			close(ps, rs);
			return bans;
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
		return null;
	}

	public boolean removeFromJaillist(String uuid) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("DELETE FROM "
					+ bantable + " WHERE uuid = ? AND type = 6");
			ps.setString(1, uuid);
			ps.executeUpdate();
			close(ps, null);
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
			return false;
		}
		return true;

	}

	public List<String> listPlayers(String ip) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("SELECT * FROM "
					+ iptable + " WHERE ip = ?");
			ps.setString(1, ip);
			ResultSet rs = ps.executeQuery();
			List<String> bans = new ArrayList<String>();
			while (rs.next()) {
				bans.add(rs.getString("uuid"));
			}
			close(ps, rs);
			return bans;
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
		return null;
	}

	public void clearWarns(String uuid) {
		try {
			connection = getSQLConnection();
			PreparedStatement ps = connection.prepareStatement("DELETE FROM "
					+ bantable + " WHERE uuid = ? AND type = 2");
			ps.setString(1, uuid);
			close(ps, null);
		} catch (SQLException ex) {
			Error.execute(plugin, ex);
		}
	}

	public void close(PreparedStatement ps, ResultSet rs) {
		try {
			if (ps != null)
				ps.close();
			if (rs != null)
				rs.close();
		} catch (SQLException ex) {
			Error.close(plugin, ex);
		}
	}
} public class SQL extends Database {
	private String database;
	private String username;
	private String password;

	public SQL(Ultrabans instance) {
		super(instance);
		YamlConfiguration config = (YamlConfiguration) plugin.getConfig();
		database = config.getString("MySQL.Database",
				"jdbc:mysql://localhost:3306/minecraft");
		username = config.getString("MySQL.User", "root");
		password = config.getString("MySQL.Password", "root");
		bantable = config.getString("MySQL.Table", "banlist");
		iptable = config.getString("MySQL.IPTable", "iptable");
		aliastable = config.getString("MySQL.AliasTable", "aliastable");
	}

	public Connection getSQLConnection() {
		try {
			if (connection != null && !connection.isClosed()) {
				return connection;
			}
			Properties info = new Properties();
			info.put("autoReconnect", "true");
			info.put("user", username);
			info.put("password", password);
			info.put("useUnicode", "true");
			info.put("characterEncoding", "utf8");
			connection = DriverManager.getConnection(database, info);
			return connection;
		} catch (SQLException ex) {
			plugin.getLogger().log(Level.SEVERE,
					"Unable to retreive connection", ex);
		}
		return null;
	}

	public String SQLCreateBansTable = "CREATE TABLE IF NOT EXISTS %table% ("
			+ "`uuid` varchar(36) NOT NULL,"
			+ "`reason` text NOT NULL,"
			+ "`admin` varchar(32) NOT NULL,"
			+ "`time` bigint(20) NOT NULL,"
			+ "`temptime` bigint(20) NOT NULL,"
			+ "`id` int(11) NOT NULL AUTO_INCREMENT,"
			+ "`type` int(1) NOT NULL DEFAULT '0',"
			+ "PRIMARY KEY (`id`) USING BTREE"
			+ ") ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;";

	public String SQLCreateIPTable = "CREATE TABLE IF NOT EXISTS %table% ("
			+ "`ip` varchar(45) NOT NULL," 
			+ "`uuid` varchar(36) NOT NULL,"
			+ "PRIMARY KEY (`ip`)"
			+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;";

	public String SQLCreateAliasTable = "CREATE TABLE IF NOT EXISTS %table% ("
			+ "`name` varchar(32) NOT NULL," 
			+ "`uuid` varchar(36) NOT NULL,"
			+ "PRIMARY KEY (`name`)"
			+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;";

	public void load() {
		connection = getSQLConnection();
		try {
			Statement s = connection.createStatement();
			s.executeUpdate(SQLCreateBansTable.replaceAll("%table%",bantable));
			s.executeUpdate(SQLCreateIPTable.replaceAll("%table%", iptable));
			s.executeUpdate(SQLCreateAliasTable.replaceAll("%table%", aliastable));
			s.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		initialize();
	}
} public class SQLite extends Database {
	String dbname;

	public SQLite(Ultrabans instance) {
		super(instance);
		dbname = plugin.getConfig().getString("SQLite.Filename", "banlist");
		bantable = "banlist";
		iptable = "iptable";
		aliastable = "aliastable";
	}

	public String SQLiteCreateBansTable = "CREATE TABLE IF NOT EXISTS banlist ("
			+ "`uuid` TEXT,"
			+"`alias` TEXT"
			+ "`reason` TEXT,"
			+ "`admin` TEXT,"
			+ "`time` INTEGER,"
			+ "`temptime` INTEGER ,"
			+ "`id` INTEGER PRIMARY KEY," 
			+ "`type` INTEGER DEFAULT '0'" 
			+ ");";
	
	public String SQLCreateIPTable = "CREATE TABLE IF NOT EXISTS %table% ("
			+ "`ip` TEXT," 
			+ "`uuid` TEXT,"
			+ "PRIMARY KEY (`ip`)"
			+ ");";

	public String SQLCreateAliasTable = "CREATE TABLE IF NOT EXISTS %table% ("
			+ "`name` TEXT," 
			+ "`uuid` TEXT,"
			+ "PRIMARY KEY (`name`)"
			+ ");";

	public Connection getSQLConnection() {
		File dataFolder = new File(plugin.getDataFolder(), dbname + ".db");
		if (!dataFolder.exists()) {
			try {
				dataFolder.createNewFile();
			} catch (IOException e) {
				plugin.getLogger().log(Level.SEVERE,
						"File write error: " + dbname + ".db");
			}
		}
		try {
			if (connection != null && !connection.isClosed()) {
				return connection;
			}
			Class.forName("org.sqlite.JDBC");
			connection = DriverManager.getConnection("jdbc:sqlite:"
					+ dataFolder);
			return connection;
		} catch (SQLException ex) {
			plugin.getLogger().log(Level.SEVERE,
					"SQLite exception on initialize", ex);
		} catch (ClassNotFoundException ex) {
			plugin.getLogger()
					.log(Level.SEVERE,
							"You need the SQLite JBDC library. Google it. Put it in /lib folder.");
		}
		return null;
	}

	public void load() {
		connection = getSQLConnection();
		try {
			Statement s = connection.createStatement();
			s.executeUpdate(SQLiteCreateBansTable);
			s.executeUpdate(SQLCreateIPTable);
			s.executeUpdate(SQLCreateAliasTable);
			s.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		initialize();
	}
} public class UltraBanBlockListener implements Listener {
	Ultrabans plugin;

	public UltraBanBlockListener(Ultrabans instance) {
		plugin = instance;
	}

	@EventHandler(priority = EventPriority.HIGHEST)
	public void onBlockPlace(BlockPlaceEvent event) {
		Player player = event.getPlayer();
		if (plugin.cache.containsKey(player.getUniqueId().toString())) {
			for (InfoBan info : plugin.cache.get(player.getUniqueId()
					.toString())) {
				if (info.getType() == BanType.TEMPJAIL.getId()
						|| info.getType() == BanType.JAIL.getId()) {
					if (info.getType() == BanType.TEMPJAIL.getId()
							&& tempjailCheck(player, info))
						return;
					String adminMsg = plugin.getConfig().getString(
							"Messages.Jail.PlaceMsg",
							"You cannot place blocks while you are jailed!");
					player.sendMessage(ChatColor.GRAY + adminMsg);
					event.setCancelled(true);
				}
			}
		}
	}

	@EventHandler(priority = EventPriority.HIGHEST)
	public void onBlockBreak(BlockBreakEvent event) {
		Player player = event.getPlayer();
		if (plugin.cache.containsKey(player.getUniqueId().toString())) {
			List<InfoBan> list = plugin.cache.get(player.getUniqueId()
					.toString());
			for (InfoBan info : list) {
				if (info.getType() == BanType.TEMPJAIL.getId()
						|| info.getType() == BanType.JAIL.getId()) {
					if (info.getType() == BanType.TEMPJAIL.getId()
							&& tempjailCheck(player, info))
						return;
					String adminMsg = plugin.getConfig().getString(
							"Messages.Jail.BreakMsg",
							"You cannot break blocks while you are jailed!");
					player.sendMessage(ChatColor.GRAY + adminMsg);
					event.setCancelled(true);
				}
			}
		}
	}

	private boolean tempjailCheck(Player player, InfoBan info) {
		long tempTime = info.getEndTime();
		long now = System.currentTimeMillis() / 1000;
		long diff = tempTime - now;
		if (diff <= 0) {
			List<InfoBan> list = plugin.cache.get(player.getUniqueId()
					.toString());
			list.remove(info);
			plugin.cache.put(player.getUniqueId().toString(), list);
			plugin.getAPI().pardonPlayer(player.getName(), info.getAdmin());
			Location stlp = plugin.jail.getJail("release");
			player.teleport(stlp);
			String bcmsg = plugin.getConfig().getString("Messages.Pardon.Msg",
					"%victim% was released from jail by %admin%!");
			if (bcmsg.contains(Ultrabans.ADMIN))
				bcmsg = bcmsg.replaceAll(Ultrabans.ADMIN,
						Ultrabans.DEFAULT_ADMIN);
			if (bcmsg.contains(Ultrabans.VICTIM))
				bcmsg = bcmsg.replaceAll(Ultrabans.VICTIM, player.getName());
			player.sendMessage(ChatColor.translateAlternateColorCodes('&',
					bcmsg));
			return true;
		}
		Date date = new Date();
		date.setTime(tempTime * 1000);
		String dateStr = date.toString();
		player.sendMessage(ChatColor.GRAY + "You've been tempjailed for "
				+ info.getReason());
		player.sendMessage(ChatColor.GRAY + "Remaining: " + ChatColor.RED
				+ dateStr);
		return false;
	}
} public class UltraBanPlayerListener implements Listener {
	Ultrabans plugin;
	String spamcheck = null;
	int spamCount = 0;
	FileConfiguration config;
	YamlConfiguration lang;

	public UltraBanPlayerListener(Ultrabans ultraBans) {
		plugin = ultraBans;
		config = ultraBans.getConfig();
		lang = ultraBans.getLangConfig();
	}

	@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
	public void onPlayerLogin(PlayerLoginEvent event) {
		// TODO Set IP...
		String reason = Ultrabans.DEFAULT_REASON;
		String admin = Ultrabans.DEFAULT_ADMIN;
		
		final Player player = event.getPlayer();
		String ip = event.getAddress().getHostAddress();

		plugin.getUBDatabase().setAddress(player.getUniqueId().toString(), ip);
		if (plugin.cacheIP.containsKey(ip)) {
			for (InfoBan info : plugin.cacheIP.get(player.getUniqueId()
					.toString())) {
				if (info.getType() == BanType.IPBAN.getId()
						|| info.getType() == BanType.TEMPIPBAN.getId()) {
					// TODO:TempCheck via Type

					if (admin == info.getAdmin())
						admin = info.getAdmin();
					if (reason == info.getReason())
						reason = info.getReason();
					String bcmsg = lang.getString("IPBan.Login");
					if (bcmsg.contains(Ultrabans.ADMIN))
						bcmsg = bcmsg.replaceAll(Ultrabans.ADMIN, admin);
					if (bcmsg.contains(Ultrabans.REASON))
						bcmsg = bcmsg.replaceAll(Ultrabans.REASON, reason);
					event.disallow(PlayerLoginEvent.Result.KICK_BANNED,
							ChatColor.translateAlternateColorCodes('&', bcmsg));
				}
			}
		}

		if (plugin.cache.containsKey(player.getUniqueId().toString())) {
			for (InfoBan info : plugin.cache.get(player.getUniqueId()
					.toString())) {
				if (info.getType() == BanType.BAN.getId()
						|| info.getType() == BanType.TEMPBAN.getId()) {

					// TODO:TempCheck via Type

					if (admin == info.getAdmin())
						admin = info.getAdmin();
					if (reason == info.getReason())
						reason = info.getReason();
					String bcmsg = lang.getString("Ban.Login");
					if (bcmsg.contains(Ultrabans.ADMIN))
						bcmsg = bcmsg.replaceAll(Ultrabans.ADMIN, admin);
					if (bcmsg.contains(Ultrabans.REASON))
						bcmsg = bcmsg.replaceAll(Ultrabans.REASON, reason);
					event.disallow(PlayerLoginEvent.Result.KICK_BANNED,
							ChatColor.translateAlternateColorCodes('&', bcmsg));
				}

			}
		}
		if (config.getBoolean("Lockdown", false)
				&& !player.hasPermission("ultraban.override.lockdown")) {
			String lockMsgLogin = lang.getString("Lockdown.LoginMsg",
					"Server is under a lockdown, Try again later!");
			event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
					ChatColor.translateAlternateColorCodes('&', lockMsgLogin));
			plugin.getLogger().info(
					player.getName() + " attempted to join during lockdown.");
		}

		if (!player.hasPermission("ultraban.override.dupeip")
				&& config.getBoolean("Login.DupeCheck.Enable", true)) {
			plugin.getServer().getScheduler()
					.scheduleSyncDelayedTask(plugin, new Runnable() {
						@Override
						public void run() {
							String ip = plugin.getUBDatabase().getAddress(
									player.getUniqueId().toString());
							if (ip != null) {
								List<String> list = plugin.getUBDatabase()
										.listPlayers(ip);
								for (Player admin : plugin.getServer()
										.getOnlinePlayers()) {
									if (admin.hasPermission("ultraban.dupeip")) {
										for (String name : list) {
											if (!name.equalsIgnoreCase(player
													.getName()))
												admin.sendMessage(ChatColor.GRAY
														+ "Player: "
														+ name
														+ " duplicates player: "
														+ player.getName()
														+ "!");
										}
									}
								}
							}
						}
					}, 20L);
		}
	}

	@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
	public void onAsyncLogin(AsyncPlayerPreLoginEvent event) {
		String ip = event.getAddress().getHostAddress();
		String reason = Ultrabans.DEFAULT_ADMIN;
		String admin = Ultrabans.DEFAULT_REASON;
		if (plugin.cacheIP.containsKey(ip)) {
			for (InfoBan info : plugin.cacheIP.get(ip)) {
				if (info.getType() == BanType.IPBAN.getId()
						|| info.getType() == BanType.TEMPIPBAN.getId()) {
					// TODO:TempCheck via Type

					if (admin == info.getAdmin())
						admin = info.getAdmin();
					if (reason == info.getReason())
						reason = info.getReason();
					String bcmsg = lang.getString("IPBan.Login");
					if (bcmsg.contains(Ultrabans.ADMIN))
						bcmsg = bcmsg.replaceAll(Ultrabans.ADMIN, admin);
					if (bcmsg.contains(Ultrabans.REASON))
						bcmsg = bcmsg.replaceAll(Ultrabans.REASON, reason);
					event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
							ChatColor.translateAlternateColorCodes('&', bcmsg));
				}
			}
		}
	}

	@EventHandler(priority = EventPriority.LOW)
	public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
		Player player = event.getPlayer();
		String args[] = event.getMessage().split(" ");
		String adminMsg = config.getString("Messages.Mute.Chat",
				"Your cry falls on deaf ears.");

		if (config.getBoolean("Jail.Vannila", true)
				&& plugin.cache.containsKey(player.getUniqueId().toString())) {
			List<InfoBan> list = plugin.cache.get(player.getUniqueId()
					.toString());
			for (InfoBan info : list) {
				if (info.getType() == BanType.TEMPJAIL.getId()
						|| info.getType() == BanType.JAIL.getId()) {
					if (tempjailCheck(player, info)
							&& config.getStringList("Jail.AllowedCommands")
									.contains(args[0]))
						return;
					player.sendMessage(ChatColor.translateAlternateColorCodes(
							'&', adminMsg));
					event.setCancelled(true);
				}
			}
		}

		if (plugin.muted.contains(player.getUniqueId().toString())
				&& config.getBoolean("Muted.Vannila", true)) {
			if (config.getStringList("Mute.AllowedCommands").contains(args[0]))
				return;
			player.sendMessage(ChatColor.translateAlternateColorCodes('&',
					adminMsg));
			event.setCancelled(true);
		}

	}

	@EventHandler(priority = EventPriority.LOW)
	public void onPlayerChat(AsyncPlayerChatEvent event) {
		Player player = event.getPlayer();
		String message = event.getMessage();
		String adminMsg = config.getString("Messages.Mute.Chat",
				"Your cry falls on deaf ears.");
		if (plugin.muted.contains(player.getUniqueId().toString())) {
			;
			player.sendMessage(adminMsg);
			event.setCancelled(true);
		}
		if (plugin.cache.containsKey(player.getUniqueId().toString())
				&& config.getBoolean("Jail.Mute", true)) {
			List<InfoBan> list = plugin.cache.get(player.getUniqueId()
					.toString());
			for (InfoBan info : list) {
				if (info.getType() == BanType.TEMPJAIL.getId()
						|| info.getType() == BanType.JAIL.getId()) {
					if (tempjailCheck(player, info))
						return;
					player.sendMessage(ChatColor.translateAlternateColorCodes(
							'&', adminMsg));
					event.setCancelled(true);
				}
			}
		}
		if (config.getBoolean("Chat.IPCheck.Enable", true)) {
			ipcheck(player, message, event);
		}
		if (config.getBoolean("Chat.SpamCheck.Enable", true)) {
			spamcheck(player, message, event);
		}
		if (config.getBoolean("Chat.SwearCensor.Enable", true)) {
			swearcheck(player, message, event);
		}
	}

	private boolean tempjailCheck(Player player, InfoBan info) {
		long tempTime = info.getEndTime();
		long now = System.currentTimeMillis() / 1000;
		long diff = tempTime - now;
		if (diff <= 0) {
			List<InfoBan> list = plugin.cache.get(player.getUniqueId()
					.toString());
			list.remove(info);
			plugin.cache.put(player.getUniqueId().toString(), list);
			plugin.getAPI().pardonPlayer(player.getName(), info.getAdmin());
			Location stlp = plugin.jail.getJail("release");
			player.teleport(stlp);
			String bcmsg = plugin.getConfig().getString("Messages.Pardon.Msg",
					"%victim% was released from jail by %admin%!");
			if (bcmsg.contains(Ultrabans.ADMIN))
				bcmsg = bcmsg.replaceAll(Ultrabans.ADMIN,
						Ultrabans.DEFAULT_ADMIN);
			if (bcmsg.contains(Ultrabans.VICTIM))
				bcmsg = bcmsg.replaceAll(Ultrabans.VICTIM, player.getName());
			player.sendMessage(ChatColor.translateAlternateColorCodes('&',
					bcmsg));
			return true;
		}
		Date date = new Date();
		date.setTime(tempTime * 1000);
		String dateStr = date.toString();
		player.sendMessage(ChatColor.GRAY + "You've been tempjailed for "
				+ info.getReason());
		player.sendMessage(ChatColor.GRAY + "Remaining: " + ChatColor.RED
				+ dateStr);
		return false;
	}

	private void ipcheck(Player player, String message,
			AsyncPlayerChatEvent event) {
		String mes = new String(message);
		String[] content = { "\\,", "\\-", "\\_", "\\=" };
		for (int ii = 0; ii < content.length; ii++) {
			if (mes.contains(content[ii]))
				mes = mes.replaceAll(content[ii], ".");
		}
		String[] ipcheck = mes.split(" ");
		String mode = config.getString("Chat.IPCheck.Blocking");
		if (mode == null)
			mode = "";
		boolean valid = false;
		for (int i = 0; i < ipcheck.length; i++) {
			if (Formatting.validIP(ipcheck[i].trim())) {
				if (mode.equalsIgnoreCase("%scramble%")) {
					event.setMessage(mes.replaceAll(ipcheck[i].trim(),
							ChatColor.MAGIC + "AAAAA"));
				} else if (mode.equalsIgnoreCase("%replace%")) {
					event.setMessage(mes.replaceAll(ipcheck[i].trim(), plugin
							.getServer().getIp()));
				} else {
					event.setMessage(mes.replaceAll(ipcheck[i].trim(), mode));
				}
				valid = true;
			}
		}
		String result = config.getString("Chat.IPCheck.Result", "ban");
		String reason = config.getString("Chat.IPCheck.Reason", "Advertising");
		if (valid && result != null) {
			if (result.equalsIgnoreCase("ban")
					|| result.equalsIgnoreCase("kick")
					|| result.equalsIgnoreCase("ipban")
					|| result.equalsIgnoreCase("jail")
					|| result.equalsIgnoreCase("warn")) {
				String fakecmd = null;
				if (config.getBoolean("Chat.IPCheck.Silent", false)) {
					fakecmd = result + " " + player.getName() + " " + "-s"
							+ " " + reason;
				} else {
					fakecmd = result + " " + player.getName() + " " + reason;
				}
				plugin.getServer().dispatchCommand(
						plugin.getServer().getConsoleSender(), fakecmd);
			}
		}
	}

	private void spamcheck(Player player, String message,
			AsyncPlayerChatEvent event) {
		String mes = new String(message);
		if (!mes.equalsIgnoreCase(spamcheck)) {
			spamcheck = event.getMessage();
			spamCount = 0;
		} else {
			event.setCancelled(true);
			spamCount++;
		}
		String result = config.getString("Chat.SpamCheck.Result", "kick");
		String reason = config.getString("Chat.SpamCheck.Reason", "Spam");
		if (config.getInt("Chat.SpamCheck.Counter") < spamCount
				&& result != null) {
			if (result.equalsIgnoreCase("ban")
					|| result.equalsIgnoreCase("kick")
					|| result.equalsIgnoreCase("ipban")
					|| result.equalsIgnoreCase("jail")
					|| result.equalsIgnoreCase("warn")) {
				String fakecmd = null;
				if (config.getBoolean("Chat.SpamCheck.Silent", false)) {
					fakecmd = result + " " + player.getName() + " " + "-s"
							+ " " + reason;
				} else {
					fakecmd = result + " " + player.getName() + " " + reason;
				}
				plugin.getServer().dispatchCommand(
						plugin.getServer().getConsoleSender(), fakecmd);
			}
		}

	}

	private void swearcheck(Player player, String message,
			AsyncPlayerChatEvent event) {
		String mes = new String(message);
		String[] string = config.getString("Chat.SwearCensor.Words").split(" ");
		String mode = config.getString("Chat.SwearCensor.Blocking");
		if (mode == null)
			mode = "";
		boolean valid = false;
		for (int i = 0; i < string.length; i++) {
			if (Pattern
					.compile(Pattern.quote(string[i].trim()),
							Pattern.CASE_INSENSITIVE).matcher(mes).find()) {
				if (mode.equalsIgnoreCase("%scramble%")) {
					mes = mes.replaceAll(string[i].trim(), ChatColor.MAGIC
							+ "AAAAA");
				} else {
					mes = mes.replaceAll(string[i].trim(), mode);
				}
				valid = true;
			}
		}
		event.setMessage(mes);
		String result = config.getString("Chat.SwearCensor.Result", "mute");
		String reason = config.getString("Chat.SwearCensor.Reason", "Language");
		if (valid && result != null) {
			if (result.equalsIgnoreCase("ban")
					|| result.equalsIgnoreCase("kick")
					|| result.equalsIgnoreCase("ipban")
					|| result.equalsIgnoreCase("jail")
					|| result.equalsIgnoreCase("warn")
					|| result.equalsIgnoreCase("mute")) {
				String fakecmd = null;
				if (config.getBoolean("Chat.SwearCensor.Silent", false)) {
					fakecmd = result + " " + player.getName() + " " + "-s"
							+ " " + reason;
				} else {
					fakecmd = result + " " + player.getName() + " " + reason;
				}
				plugin.getServer().dispatchCommand(
						plugin.getServer().getConsoleSender(), fakecmd);
			}
		}
	}

	@EventHandler
	public void onPlayerRespawn(PlayerRespawnEvent event) {
		Player player = event.getPlayer();
		if (plugin.cache.containsKey(player.getUniqueId().toString())) {
			List<InfoBan> list = plugin.cache.get(player.getUniqueId()
					.toString());
			for (InfoBan info : list) {
				if (info.getType() == BanType.TEMPJAIL.getId()
						|| info.getType() == BanType.JAIL.getId()) {
					if (tempjailCheck(player, info))
						return;
					event.setRespawnLocation(plugin.jail.getJail("jail"));
				}
			}
		}
	}
} public class InfoBan {
	private String uuid;
	private String[] aliases;
	private String reason;
	private String admin;
	private long endTime;
	private int type;

	public InfoBan(String uuid, String[] aliases, String reason, String admin, long endTime, int type) {
		this.setUuid(uuid);
		this.setAliases(aliases);
		this.setReason(reason);
		this.setAdmin(admin);
		this.setEndTime(endTime);
		this.setType(type);
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String[] getAliases() {
		return aliases;
	}

	public void setAliases(String[] aliases) {
		this.aliases = aliases;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getAdmin() {
		return admin;
	}

	public void setAdmin(String admin) {
		this.admin = admin;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

} public class Jailtools {
	Ultrabans plugin;

	public Jailtools(Ultrabans ultraBan) {
		this.plugin = ultraBan;
	}

	public void setJail(Location location, String label) {
		YamlConfiguration config = (YamlConfiguration) plugin.getConfig();
		config.set(label + ".x", (int) location.getX());
		config.set(label + ".y", (int) location.getY());
		config.set(label + ".z", (int) location.getZ());
		config.set(label + ".world", location.getWorld().getName());
		plugin.saveConfig();

	}

	public Location getJail(String label) {
		YamlConfiguration config = (YamlConfiguration) plugin.getConfig();
		Location setlp = new Location(plugin.getServer().getWorld(
				config.getString(label + ".world", plugin.getServer()
						.getWorlds().get(0).getName())), config.getInt(label
				+ ".x", 0), config.getInt(label + ".y", 0), config.getInt(label
				+ ".z", 0));
		return setlp;
	}
}
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.modcrafting.ultrabans.commands.Ban;
import com.modcrafting.ultrabans.commands.CheckID;
import com.modcrafting.ultrabans.commands.CheckIP;
import com.modcrafting.ultrabans.commands.Checkban;
import com.modcrafting.ultrabans.commands.Clean;
import com.modcrafting.ultrabans.commands.DupeIP;
import com.modcrafting.ultrabans.commands.Export;
import com.modcrafting.ultrabans.commands.Help;
import com.modcrafting.ultrabans.commands.History;
import com.modcrafting.ultrabans.commands.Import;
import com.modcrafting.ultrabans.commands.Inventory;
import com.modcrafting.ultrabans.commands.Ipban;
import com.modcrafting.ultrabans.commands.Jail;
import com.modcrafting.ultrabans.commands.Kick;
import com.modcrafting.ultrabans.commands.Lockdown;
import com.modcrafting.ultrabans.commands.Mute;
import com.modcrafting.ultrabans.commands.Pardon;
import com.modcrafting.ultrabans.commands.Perma;
import com.modcrafting.ultrabans.commands.Ping;
import com.modcrafting.ultrabans.commands.Reload;
import com.modcrafting.ultrabans.commands.Spawn;
import com.modcrafting.ultrabans.commands.Starve;
import com.modcrafting.ultrabans.commands.Status;
import com.modcrafting.ultrabans.commands.Tempban;
import com.modcrafting.ultrabans.commands.Tempipban;
import com.modcrafting.ultrabans.commands.Tempjail;
import com.modcrafting.ultrabans.commands.Unban;
import com.modcrafting.ultrabans.commands.Version;
import com.modcrafting.ultrabans.commands.Warn;
import com.modcrafting.ultrabans.db.Database;
import com.modcrafting.ultrabans.db.SQL;
import com.modcrafting.ultrabans.db.SQLite;
import com.modcrafting.ultrabans.listeners.UltraBanBlockListener;
import com.modcrafting.ultrabans.listeners.UltraBanPlayerListener;
import com.modcrafting.ultrabans.util.InfoAlias;
import com.modcrafting.ultrabans.util.InfoBan;
import com.modcrafting.ultrabans.util.InfoIP;
import com.modcrafting.ultrabans.util.Jailtools;
/* COPYRIGHT (c) 2015 Deathmarine
 * This file is part of Ultrabans.
 * Ultrabans 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.
 * 
 * Ultrabans 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 Ultrabans.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.modcrafting.ultrabans;




public class Ultrabans extends JavaPlugin {
	public HashSet<String> muted = new HashSet<String>();
	
	public Set<InfoBan> cache = new HashSet<InfoBan>();
	public Set<InfoIP> cacheIP = new HashSet<InfoIP>();
	public Set<InfoAlias> cacheAlias = new HashSet<InfoAlias>();
	
	public Jailtools jail = new Jailtools(this);
	public UltrabansAPI api = new UltrabansAPI(this);
	
	public YamlConfiguration lang;
	private Database db;