<commit_before>package de.tr7zw.changeme.nbtapi.utils;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import de.tr7zw.changeme.nbtapi.NBTItem;

/**
 * This class uses the Spiget API to check for updates
 *
 */
public class VersionChecker {

	private static final String USER_AGENT = "nbt-api Version check";
	private static final String REQUEST_URL = "https://api.spiget.org/v2/resources/7939/versions?size=100";

	protected static void checkForUpdates() throws Exception{
			URL url = new URL(REQUEST_URL);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.addRequestProperty("User-Agent", USER_AGENT);// Set User-Agent

			// If you're not sure if the request will be successful,
			// you need to check the response code and use #getErrorStream if it returned an error code
			InputStream inputStream = connection.getInputStream();
			InputStreamReader reader = new InputStreamReader(inputStream);

			// This could be either a JsonArray or JsonObject
			JsonElement element = new JsonParser().parse(reader);
			if (element.isJsonArray()) {
				// Is JsonArray
				JsonArray updates = (JsonArray) element;
				JsonObject latest = (JsonObject) updates.get(updates.size()-1);
				if(!latest.get("name").getAsString().contains(MinecraftVersion.VERSION)){ //Outdated
					MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage() + "' seems to be outdated!");
					MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION + "' Newest Version: " + latest.get("name").getAsString() + "'");
					MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Please update the nbt-api or the plugin that contains the api!");
					
				}else{
					MinecraftVersion.logger.log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
				}
			} else {
				// wut?!
				MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Error when looking for Updates! Got non Json Array: '" + element.toString() + "'");
			}
	}

}<commit_msg>Detect future Versions, real version checking<commit_after>package de.tr7zw.changeme.nbtapi.utils;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import de.tr7zw.changeme.nbtapi.NBTItem;

/**
 * This class uses the Spiget API to check for updates
 *
 */
public class VersionChecker {

	private static final String USER_AGENT = "nbt-api Version check";
	private static final String REQUEST_URL = "https://api.spiget.org/v2/resources/7939/versions?size=100";

	protected static void checkForUpdates() throws Exception {
		URL url = new URL(REQUEST_URL);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.addRequestProperty("User-Agent", USER_AGENT);// Set
																// User-Agent

		// If you're not sure if the request will be successful,
		// you need to check the response code and use #getErrorStream if it
		// returned an error code
		InputStream inputStream = connection.getInputStream();
		InputStreamReader reader = new InputStreamReader(inputStream);

		// This could be either a JsonArray or JsonObject
		JsonElement element = new JsonParser().parse(reader);
		if (element.isJsonArray()) {
			// Is JsonArray
			JsonArray updates = (JsonArray) element;
			JsonObject latest = (JsonObject) updates.get(updates.size() - 1);
			int versionDifference = getVersionDifference(latest.get("name").getAsString());
			if (versionDifference == -1) { // Outdated
				MinecraftVersion.logger.log(Level.WARNING,
						"[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage() + "' seems to be outdated!");
				MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
						+ "' Newest Version: " + latest.get("name").getAsString() + "'");
				MinecraftVersion.logger.log(Level.WARNING,
						"[NBTAPI] Please update the nbt-api or the plugin that contains the api!");

			} else if (versionDifference == 0) {
				MinecraftVersion.logger.log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
			} else if (versionDifference == 1) {
				MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage()
						+ "' seems to be a future Version, not yet released on Spigot!");
				MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
						+ "' Newest Version: " + latest.get("name").getAsString() + "'");
			}
		} else {
			// wut?!
			MinecraftVersion.logger.log(Level.WARNING,
					"[NBTAPI] Error when looking for Updates! Got non Json Array: '" + element.toString() + "'");
		}
	}

	// -1 = we are outdated
	// 0 = up to date
	// 1 = using a future version
	// This method is only able to compare the Format 0.0.0(-SNAPSHOT)
	private static int getVersionDifference(String version) {
		String current = MinecraftVersion.VERSION;
		if (current.equals(version))
			return 0;
		String pattern = "\\.";
		if (current.split(pattern).length != 3 || version.split(pattern).length != 3)
			return -1;
		int curMaj = Integer.parseInt(current.split(pattern)[0]);
		int curMin = Integer.parseInt(current.split(pattern)[1]);
		String curPatch = current.split(pattern)[2];
		int relMaj = Integer.parseInt(version.split(pattern)[0]);
		int relMin = Integer.parseInt(version.split(pattern)[1]);
		String relPatch = version.split(pattern)[2];
		if (curMaj < relMaj)
			return -1;
		if (curMaj > relMaj)
			return 1;
		if (curMin < relMin)
			return -1;
		if (curMin > relMin)
			return 1;
		int curPatchN = Integer.parseInt(curPatch.split("-")[0]);
		int relPatchN = Integer.parseInt(relPatch.split("-")[0]);
		if (curPatchN < relPatchN)
			return -1;
		if (curPatchN > relPatchN)
			return 1;
		if (!relPatch.contains("-") && curPatch.contains("-"))
			return -1; // Release has no - but we do = We use a Snapshot of the
						// release
		if (relPatch.contains("-") && curPatch.contains("-"))
			return 0; // Release and cur are Snapshots/alpha/beta
		return 1;
	}

}
{'fraction_non_alphanumeric': 0.13111455108359132, 'fraction_numerical': 0.00804953560371517, 'mean_word_length': 4.0280155642023345, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '4629918', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2008, 'n_words': 531}