<commit_before>package org.bukkit.virtualbukkit;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RealVirtualBukkit extends VirtualBukkit {
	private InetSocketAddress laddr = null;
	private Map<String, InetSocketAddress> vhosts = new ConcurrentHashMap<String, InetSocketAddress>();
	
	{
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream("vhosts.properties")));
			
			String line, bits[];
			while ((line = br.readLine()) != null) {
				bits = line.split("\\s");
				
				if (bits.length < 1)
					continue;
				
				if ("Listen".equals(bits[0])) {
					String host = "0.0.0.0";
					Integer port = null;
					
					if (bits.length == 2) {
						port = Integer.valueOf(bits[1]);
					} else if (bits.length == 3) {
						host = bits[1];
						port = Integer.valueOf(bits[2]);
					} else
						throw new Exception("Listen [host] <port>");
					
					this.laddr = new InetSocketAddress(host, port);
				} else if ("Default".equals(bits[0])) {
					String host = "localhost";
					Integer port = null;
					
					if (bits.length == 2) {
						if ("none".equalsIgnoreCase(bits[1]))
							continue;
						port = Integer.valueOf(bits[1]);
						if (port < 0)
							continue;
					} else if (bits.length == 3) {
						host = bits[1];
						port = Integer.valueOf(bits[2]);
					} else
						throw new Exception("Default [host] <port>");
					
					vhosts.put("", new InetSocketAddress(host, port));
				} else  if ("VirtualHost".equals(bits[0])) {
					String key = null;
					String host = "localhost";
					Integer port = null;
					
					if (bits.length == 3) {
						key = bits[1];
						port = Integer.valueOf(bits[2]);
					} else if (bits.length == 4) {
						key = bits[1];
						host = bits[2];
						port = Integer.valueOf(bits[3]);
					} else
						throw new Exception("VirtualHost <name> [host] <port>");
					
					vhosts.put(key, new InetSocketAddress(host, port));
				}
			}
			
			if (this.laddr == null)
				this.laddr = new InetSocketAddress("localhost", 25565);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		System.out.println("Listening on " + listeningAddress());
		if (vhosts.get("") != null)
			System.out.println("Default host is " + vhosts.get(""));
		for (Map.Entry<String, InetSocketAddress> entry : vhosts.entrySet())<commit_msg>bug fix<commit_after>package org.bukkit.virtualbukkit;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RealVirtualBukkit extends VirtualBukkit {
	private InetSocketAddress laddr = null;
	private Map<String, InetSocketAddress> vhosts = new ConcurrentHashMap<String, InetSocketAddress>();
	
	{
		BufferedReader br = null;
		try {
			String jarPath = RealVirtualBukkit.class.getProtectionDomain().getCodeSource().getLocation().getPath();
			File vhostsFile = new File(new File(jarPath).getParentFile(), "vhosts.properties");
			br = new BufferedReader(new InputStreamReader(new FileInputStream(vhostsFile)));
			
			String line, bits[];
			while ((line = br.readLine()) != null) {
				bits = line.split("\\s");
				
				if (bits.length < 1)
					continue;
				
				if ("Listen".equals(bits[0])) {
					String host = "0.0.0.0";
					Integer port = null;
					
					if (bits.length == 2) {
						port = Integer.valueOf(bits[1]);
					} else if (bits.length == 3) {
						host = bits[1];
						port = Integer.valueOf(bits[2]);
					} else
						throw new Exception("Listen [host] <port>");
					
					this.laddr = new InetSocketAddress(host, port);
				} else if ("Default".equals(bits[0])) {
					String host = "localhost";
					Integer port = null;
					
					if (bits.length == 2) {
						if ("none".equalsIgnoreCase(bits[1]))
							continue;
						port = Integer.valueOf(bits[1]);
						if (port < 0)
							continue;
					} else if (bits.length == 3) {
						host = bits[1];
						port = Integer.valueOf(bits[2]);
					} else
						throw new Exception("Default [host] <port>");
					
					vhosts.put("", new InetSocketAddress(host, port));
				} else  if ("VirtualHost".equals(bits[0])) {
					String key = null;
					String host = "localhost";
					Integer port = null;
					
					if (bits.length == 3) {
						key = bits[1];
						port = Integer.valueOf(bits[2]);
					} else if (bits.length == 4) {
						key = bits[1];
						host = bits[2];
						port = Integer.valueOf(bits[3]);
					} else
						throw new Exception("VirtualHost <name> [host] <port>");
					
					vhosts.put(key, new InetSocketAddress(host, port));
				}
			}
			
			if (this.laddr == null)
				this.laddr = new InetSocketAddress("localhost", 25565);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		if (listeningAddress() == null)
			System.exit(-1);
		
		System.out.println("Listening on " + listeningAddress());
		if (vhosts.get("") != null)
			System.out.println("Default host is " + vhosts.get(""));
		for (Map.Entry<String, InetSocketAddress> entry : vhosts.entrySet())
{'fraction_non_alphanumeric': 0.15060567709274997, 'fraction_numerical': 0.011751943590670765, 'mean_word_length': 2.863128491620112, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5102156', 'n_tokens_mistral': 2357, 'n_tokens_neox': 1749, 'n_words': 415}