<commit_before>package com.alecgorge.minecraft.jsonapi;

import java.io.BufferedReader;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;

import org.json.simpleForBukkit.JSONArray;
import org.json.simpleForBukkit.JSONObject;
import org.json.simpleForBukkit.parser.JSONParser;
import org.json.simpleForBukkit.parser.ParseException;

import com.alecgorge.java.http.MutableHttpRequest;
import com.alecgorge.minecraft.jsonapi.api.v2.APIv2Handler;
import com.alecgorge.minecraft.jsonapi.config.UsersConfig;
import com.alecgorge.minecraft.jsonapi.dynamic.APIWrapperMethods;
import com.alecgorge.minecraft.jsonapi.dynamic.Caller;
import com.alecgorge.minecraft.jsonapi.streams.ChatMessage;
import com.alecgorge.minecraft.jsonapi.streams.ChatStream;
import com.alecgorge.minecraft.jsonapi.streams.ConnectionMessage;
import com.alecgorge.minecraft.jsonapi.streams.ConnectionStream;
import com.alecgorge.minecraft.jsonapi.streams.ConsoleMessage;
import com.alecgorge.minecraft.jsonapi.streams.ConsoleStream;
import com.alecgorge.minecraft.jsonapi.streams.FormattedChatMessage;
import com.alecgorge.minecraft.jsonapi.streams.FormattedChatStream;
import com.alecgorge.minecraft.jsonapi.streams.PerformanceStream;
import com.alecgorge.minecraft.jsonapi.streams.StreamingResponse;

public class JSONServer extends NanoHTTPD {
	public UsersConfig logins;
	private JSONAPI inst;
	private Logger outLog = JSONAPI.instance.outLog;
	private Caller caller;

	public ChatStream chat = new ChatStream("chat");
	public FormattedChatStream formattedChat = new FormattedChatStream("formatted_chat");
	public ConsoleStream console = new ConsoleStream("console");
	public ConnectionStream connections = new ConnectionStream("connections");
	public PerformanceStream performance = new PerformanceStream("performance");

	private static boolean initted = false;

	public JSONServer(UsersConfig auth, final JSONAPI plugin, final long startupDelay) throws IOException {
		super(plugin.port, plugin.bindAddress);
		inst = plugin;

		caller = new Caller(inst);
		caller.loadFile(new File(inst.getDataFolder() + File.separator + "methods.json"));
		
		outLog.info("[JSONAPI] Loaded methods.json.");

		(new Thread(new Runnable() {
			@Override
			public void run() {
				float seconds = startupDelay / 1000;
				outLog.info("[JSONAPI] Waiting " + String.format("%2.3f", seconds) + " seconds to load methods so that all the other plugins load...");
				outLog.info("[JSONAPI] Any requests in this time will not work...");

				try {
					if (!initted) {
						Thread.sleep(startupDelay);
						initted = true;
					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				File[] files = (new File(inst.getDataFolder() + File.separator + "methods" + File.separator)).listFiles(new FilenameFilter() {
					@Override
					public boolean accept(File dir, String name) {
						return name.endsWith(".json");
					}
				});

				if (files != null && files.length > 0) {
					for (File f : files) {
						caller.loadFile(f);
					}
				}
				
				String[] methodsFiles = new String[] { "chat.json", "dynmap.json", "econ.json", "fs.json", "permissions.json",
													   "players.json", "plugins.json", "remotetoolkit.json", "server.json",
													   "streams.json", "system.json", "worlds.json", "jsonapi.json" };
				
				for(String m : methodsFiles) {
					caller.loadInputStream(inst.getResource("jsonapi4/methods/" + m));
				}
				
				caller.registerMethods(APIWrapperMethods.getInstance());
				
				outLog.info("[JSONAPI] " + caller.methodCount + " methods loaded in " + caller.methods.size() + " namespaces.");
				
				connectionInfo();
			}
		})).start();

		this.logins = auth;
	}

	
	void connectionInfo() {
        outLog.info("[JSONAPI] ------[Connection information]-------");
		outLog.info("[JSONAPI] JSON Server listening on " + inst.port);
		outLog.info("[JSONAPI] JSON Stream Server listening on " + (inst.port + 1));
		outLog.info("[JSONAPI] JSON WebSocket Stream Server listening on " + (inst.port + 2));
		outLog.info("[JSONAPI] Active and listening for requests.");

		try {
			URL whatismyip = new URL("http://tools.alecgorge.com/ip.php");
            BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));

            String ip = in.readLine();
            
            URL checkURL = new URL("http://tools.alecgorge.com/port_check.php");
            
            outLog.info("[JSONAPI] External IP: " + ip);

            for(int i : new int[] { inst.port, inst.port + 1, inst.port + 2 }) {
            	MutableHttpRequest reqReg = new MutableHttpRequest(checkURL);
	            reqReg.addGetValue("host", ip);
	            reqReg.addGetValue("port", String.valueOf(i));
	            
	            if(reqReg.get().getStatusCode() == 200) {
	            	outLog.info("[JSONAPI] Port " + i + " is properly forwarded and is externally accessible.");
	            }
	            else {
	            	outLog.info("[JSONAPI] Port " + i + " is not properly forwarded.");
	            }
            }
            
		} catch (Exception e) {
			e.printStackTrace();
		}
		
        outLog.info("[JSONAPI] -------------------------------------");<commit_msg>Fix URLs so that they show the correct information again<commit_after>package com.alecgorge.minecraft.jsonapi;

import java.io.BufferedReader;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;

import org.json.simpleForBukkit.JSONArray;
import org.json.simpleForBukkit.JSONObject;
import org.json.simpleForBukkit.parser.JSONParser;
import org.json.simpleForBukkit.parser.ParseException;

import com.alecgorge.java.http.MutableHttpRequest;
import com.alecgorge.minecraft.jsonapi.api.v2.APIv2Handler;
import com.alecgorge.minecraft.jsonapi.config.UsersConfig;
import com.alecgorge.minecraft.jsonapi.dynamic.APIWrapperMethods;
import com.alecgorge.minecraft.jsonapi.dynamic.Caller;
import com.alecgorge.minecraft.jsonapi.streams.ChatMessage;
import com.alecgorge.minecraft.jsonapi.streams.ChatStream;
import com.alecgorge.minecraft.jsonapi.streams.ConnectionMessage;
import com.alecgorge.minecraft.jsonapi.streams.ConnectionStream;
import com.alecgorge.minecraft.jsonapi.streams.ConsoleMessage;
import com.alecgorge.minecraft.jsonapi.streams.ConsoleStream;
import com.alecgorge.minecraft.jsonapi.streams.FormattedChatMessage;
import com.alecgorge.minecraft.jsonapi.streams.FormattedChatStream;
import com.alecgorge.minecraft.jsonapi.streams.PerformanceStream;
import com.alecgorge.minecraft.jsonapi.streams.StreamingResponse;

public class JSONServer extends NanoHTTPD {
	public UsersConfig logins;
	private JSONAPI inst;
	private Logger outLog = JSONAPI.instance.outLog;
	private Caller caller;

	public ChatStream chat = new ChatStream("chat");
	public FormattedChatStream formattedChat = new FormattedChatStream("formatted_chat");
	public ConsoleStream console = new ConsoleStream("console");
	public ConnectionStream connections = new ConnectionStream("connections");
	public PerformanceStream performance = new PerformanceStream("performance");

	private static boolean initted = false;

	public JSONServer(UsersConfig auth, final JSONAPI plugin, final long startupDelay) throws IOException {
		super(plugin.port, plugin.bindAddress);
		inst = plugin;

		caller = new Caller(inst);
		caller.loadFile(new File(inst.getDataFolder() + File.separator + "methods.json"));
		
		outLog.info("[JSONAPI] Loaded methods.json.");

		(new Thread(new Runnable() {
			@Override
			public void run() {
				float seconds = startupDelay / 1000;
				outLog.info("[JSONAPI] Waiting " + String.format("%2.3f", seconds) + " seconds to load methods so that all the other plugins load...");
				outLog.info("[JSONAPI] Any requests in this time will not work...");

				try {
					if (!initted) {
						Thread.sleep(startupDelay);
						initted = true;
					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				File[] files = (new File(inst.getDataFolder() + File.separator + "methods" + File.separator)).listFiles(new FilenameFilter() {
					@Override
					public boolean accept(File dir, String name) {
						return name.endsWith(".json");
					}
				});

				if (files != null && files.length > 0) {
					for (File f : files) {
						caller.loadFile(f);
					}
				}
				
				String[] methodsFiles = new String[] { "chat.json", "dynmap.json", "econ.json", "fs.json", "permissions.json",
													   "players.json", "plugins.json", "remotetoolkit.json", "server.json",
													   "streams.json", "system.json", "worlds.json", "jsonapi.json" };
				
				for(String m : methodsFiles) {
					caller.loadInputStream(inst.getResource("jsonapi4/methods/" + m));
				}
				
				caller.registerMethods(APIWrapperMethods.getInstance());
				
				outLog.info("[JSONAPI] " + caller.methodCount + " methods loaded in " + caller.methods.size() + " namespaces.");
				
				connectionInfo();
			}
		})).start();

		this.logins = auth;
	}

	
	void connectionInfo() {
        outLog.info("[JSONAPI] ------[Connection information]-------");
		outLog.info("[JSONAPI] JSON Server listening on " + inst.port);
		outLog.info("[JSONAPI] JSON Stream Server listening on " + (inst.port + 1));
		outLog.info("[JSONAPI] JSON WebSocket Stream Server listening on " + (inst.port + 2));
		outLog.info("[JSONAPI] Active and listening for requests.");

		try {
			URL whatismyip = new URL("https://tools.alecgorge.com/ip.php");
            BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));

            String ip = in.readLine();
            
            URL checkURL = new URL("https://tools.alecgorge.com/port_check.php");
            
            outLog.info("[JSONAPI] External IP: " + ip);

            for(int i : new int[] { inst.port, inst.port + 1, inst.port + 2 }) {
            	MutableHttpRequest reqReg = new MutableHttpRequest(checkURL);
	            reqReg.addGetValue("host", ip);
	            reqReg.addGetValue("port", String.valueOf(i));
	            
	            if(reqReg.get().getStatusCode() == 200) {
	            	outLog.info("[JSONAPI] Port " + i + " is properly forwarded and is externally accessible.");
	            }
	            else {
	            	outLog.info("[JSONAPI] Port " + i + " is not properly forwarded.");
	            }
            }
            
		} catch (Exception e) {
			e.printStackTrace();
		}
		
        outLog.info("[JSONAPI] -------------------------------------");
{'fraction_non_alphanumeric': 0.13264118857961157, 'fraction_numerical': 0.0030430502103284706, 'mean_word_length': 3.416600790513834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3434528', 'n_tokens_mistral': 3729, 'n_tokens_neox': 3327, 'n_words': 705}