<commit_before>package net.craftminecraft.bungee.bungeeban;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.collect.ImmutableList;

import net.craftminecraft.bungee.bungeeban.banstore.BanEntry;
import net.craftminecraft.bungee.bungeeban.banstore.IBanStore;
import net.craftminecraft.bungee.bungeeban.util.MainConfig;
import net.craftminecraft.bungee.bungeeban.util.Utils;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;


public class BanManager {
	private static Pattern pattern = Pattern.compile(
			"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");

	private static IBanStore banstore;
	
	// Static class.
	private BanManager() {}
	
	public static void setBanStore(IBanStore banstore) {
		BanManager.banstore = banstore;
	}
	
	public static boolean ban(BanEntry entry) {
		if (entry.isGlobal()) {
			gkick(entry.getBanned(), Utils.formatMessage(entry.getReason(), entry));
		} else {
			kick(entry.getBanned(), entry.getServer(), Utils.formatMessage(entry.getReason(), entry));
		}
		
		String type = "ban";
		type += (entry.isIPBan()) ? "ip" : "";
		type = ((entry.isTempBan()) ? "temp" : "") + type;
		type = ((entry.isGlobal()) ? "g" : "") + type;
		if (banstore.ban(entry)) {
			for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
				if ((player != null && player.getServer() != null && 
						player.getServer().getInfo().getName().equals(entry.getServer()))
					|| entry.isGlobal() 
					|| MainConfig.getInstance().message_sendLocalMsgGlobally) {
					if (Utils.hasPermission(player, "see", type))
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType(type), entry));
				}
			}
			return true;
		} else {
			return false;
		}
	}

	public static BanEntry getBan(String playerorip, String server) {
		if (isIP(playerorip)) {
			return banstore.getIPBanList().get(playerorip.toLowerCase(), server);
		} else {
			return banstore.getBanList().get(playerorip, server);
		}
	}

	public static List<BanEntry> getBanList() {
		return ImmutableList.copyOf(banstore.getBanList().values());
	}

	@Deprecated
	public static List<BanEntry> getBanList(String playerorip) {
		return getPlayerBanList(playerorip.toLowerCase());
	}

	public static List<BanEntry> getPlayerBanList(String player) {
		return ImmutableList.copyOf(banstore.getBanList().row(player.toLowerCase()).values());
	}

	public static List<BanEntry> getIPBanList(String ip) {
		return ImmutableList.copyOf(banstore.getIPBanList().row(ip).values());
	}

	public static List<BanEntry> getServerBanList(String server) {
		ArrayList<BanEntry> entries = new ArrayList<BanEntry>();
		entries.addAll(banstore.getIPBanList().column(server).values());
		entries.addAll(banstore.getBanList().column(server).values());
		return ImmutableList.copyOf(entries);
	}

	public static List<BanEntry> getServerPlayerBanList(String server) {
		return ImmutableList.copyOf(banstore.getBanList().column(server).values());
	}

	public static List<BanEntry> getServerIPBanList(String server) {
		return ImmutableList.copyOf(banstore.getIPBanList().column(server).values());
	}

	public static boolean gunban(String playerorip) {
		BanEntry.Builder builder = new BanEntry.Builder(playerorip.toLowerCase()).global();
		BanEntry entry;
		if (isIP(playerorip)) {
			entry = builder.ipban().build();
			if(banstore.gunbanIP(playerorip)) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if (Utils.hasPermission(player, "see", "gunbanip"))
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("gunbanip"), entry));
				}
				return true;
			}
		} else {
			entry = builder.build();
			if (banstore.gunban(playerorip)) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if (Utils.hasPermission(player, "see", "gunban"))
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("gunban"), entry));
				}
				return true;
			}
		}
		return false;
	}
	
	public static boolean unban(String playerorip, String server) {
		BanEntry.Builder builder = new BanEntry.Builder(playerorip.toLowerCase(), server);
		BanEntry entry;
		if (isIP(playerorip)) {
			entry = builder.ipban().build();
			if (banstore.unbanIP(playerorip, server)) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if ((MainConfig.getInstance().message_sendLocalMsgGlobally
						|| player.getServer().getInfo().getName().equalsIgnoreCase(server))
						&& Utils.hasPermission(player, "see", "unbanip")) {
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("unbanip"), entry));
					}
				}
				return true;
			}
		} else {
			entry = builder.build();
			if (banstore.unban(playerorip, server)) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if ((player.getServer().getInfo().getName().equalsIgnoreCase(server)
						|| MainConfig.getInstance().message_sendLocalMsgGlobally)
						&& Utils.hasPermission(player, "see", "unban")) {
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("unban"), entry));
					}
				}
				return true;
			}
		}
		return false;
	}
	<commit_msg>Fix case sensitivity<commit_after>package net.craftminecraft.bungee.bungeeban;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.collect.ImmutableList;

import net.craftminecraft.bungee.bungeeban.banstore.BanEntry;
import net.craftminecraft.bungee.bungeeban.banstore.IBanStore;
import net.craftminecraft.bungee.bungeeban.util.MainConfig;
import net.craftminecraft.bungee.bungeeban.util.Utils;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;


public class BanManager {
	private static Pattern pattern = Pattern.compile(
			"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");

	private static IBanStore banstore;
	
	// Static class.
	private BanManager() {}
	
	public static void setBanStore(IBanStore banstore) {
		BanManager.banstore = banstore;
	}
	
	public static boolean ban(BanEntry entry) {
		if (entry.isGlobal()) {
			gkick(entry.getBanned(), Utils.formatMessage(entry.getReason(), entry));
		} else {
			kick(entry.getBanned(), entry.getServer(), Utils.formatMessage(entry.getReason(), entry));
		}
		
		String type = "ban";
		type += (entry.isIPBan()) ? "ip" : "";
		type = ((entry.isTempBan()) ? "temp" : "") + type;
		type = ((entry.isGlobal()) ? "g" : "") + type;
		if (banstore.ban(entry)) {
			for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
				if ((player != null && player.getServer() != null && 
						player.getServer().getInfo().getName().equals(entry.getServer()))
					|| entry.isGlobal() 
					|| MainConfig.getInstance().message_sendLocalMsgGlobally) {
					if (Utils.hasPermission(player, "see", type))
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType(type), entry));
				}
			}
			return true;
		} else {
			return false;
		}
	}

	public static BanEntry getBan(String playerorip, String server) {
		if (isIP(playerorip)) {
			return banstore.getIPBanList().get(playerorip, server);
		} else {
			return banstore.getBanList().get(playerorip.toLowerCase(), server);
		}
	}

	public static List<BanEntry> getBanList() {
		return ImmutableList.copyOf(banstore.getBanList().values());
	}

	@Deprecated
	public static List<BanEntry> getBanList(String playerorip) {
		return getPlayerBanList(playerorip.toLowerCase());
	}

	public static List<BanEntry> getPlayerBanList(String player) {
		return ImmutableList.copyOf(banstore.getBanList().row(player.toLowerCase()).values());
	}

	public static List<BanEntry> getIPBanList(String ip) {
		return ImmutableList.copyOf(banstore.getIPBanList().row(ip).values());
	}

	public static List<BanEntry> getServerBanList(String server) {
		ArrayList<BanEntry> entries = new ArrayList<BanEntry>();
		entries.addAll(banstore.getIPBanList().column(server).values());
		entries.addAll(banstore.getBanList().column(server).values());
		return ImmutableList.copyOf(entries);
	}

	public static List<BanEntry> getServerPlayerBanList(String server) {
		return ImmutableList.copyOf(banstore.getBanList().column(server).values());
	}

	public static List<BanEntry> getServerIPBanList(String server) {
		return ImmutableList.copyOf(banstore.getIPBanList().column(server).values());
	}

	public static boolean gunban(String playerorip) {
		BanEntry.Builder builder = new BanEntry.Builder(playerorip.toLowerCase()).global();
		BanEntry entry;
		if (isIP(playerorip)) {
			entry = builder.ipban().build();
			if(banstore.gunbanIP(playerorip.toLowerCase())) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if (Utils.hasPermission(player, "see", "gunbanip"))
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("gunbanip"), entry));
				}
				return true;
			}
		} else {
			entry = builder.build();
			if (banstore.gunban(playerorip.toLowerCase())) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if (Utils.hasPermission(player, "see", "gunban"))
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("gunban"), entry));
				}
				return true;
			}
		}
		return false;
	}
	
	public static boolean unban(String playerorip, String server) {
		BanEntry.Builder builder = new BanEntry.Builder(playerorip.toLowerCase(), server);
		BanEntry entry;
		if (isIP(playerorip)) {
			entry = builder.ipban().build();
			if (banstore.unbanIP(playerorip.toLowerCase(), server)) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if ((MainConfig.getInstance().message_sendLocalMsgGlobally
						|| player.getServer().getInfo().getName().equalsIgnoreCase(server))
						&& Utils.hasPermission(player, "see", "unbanip")) {
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("unbanip"), entry));
					}
				}
				return true;
			}
		} else {
			entry = builder.build();
			if (banstore.unban(playerorip.toLowerCase(), server)) {
				for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
					if ((player.getServer().getInfo().getName().equalsIgnoreCase(server)
						|| MainConfig.getInstance().message_sendLocalMsgGlobally)
						&& Utils.hasPermission(player, "see", "unban")) {
						player.sendMessage(Utils.formatMessage(MainConfig.getInstance().getMessageByType("unban"), entry));
					}
				}
				return true;
			}
		}
		return false;
	}
	
{'fraction_non_alphanumeric': 0.15339395609442455, 'fraction_numerical': 0.006245981445761, 'mean_word_length': 4.819347942276857, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7059426', 'n_tokens_mistral': 4045, 'n_tokens_neox': 3535, 'n_words': 560}