package markehme.factionsplus;

import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;

public class FactionsPlusUpdate {
	static public void checkUpdates() {
		String content = null;
		URLConnection connection = null;
		String v = FactionsPlus.version;
		
		if(FactionsPlus.config.getBoolean("disableUpdateCheck")) {
			return;
		}
		
		FactionsPlus.info("Checking for updates ... ");
		
		Scanner scanner=null;
		try {
			connection =  new URL("http://www.markeh.me/factionsplus.php?v=" + v).openConnection();
			scanner = new Scanner(connection.getInputStream());
			scanner.useDelimiter("\\Z");
			content = scanner.next();
		} catch ( Exception ex ) {
		    ex.printStackTrace();
		    FactionsPlus.info("Failed to check for updates.");
		    return;
		}finally{
			if (null != scanner) {
				scanner.close();
			}
		}

		// advanced checking
		if(!content.trim().equalsIgnoreCase(v.trim())){
			int web, current;
			String tempWeb = content.trim().replace(".", "");
			String tempThis = v.trim().replace(".", "");

			web = Integer.parseInt(tempWeb);
			current = Integer.parseInt(tempThis);
			
			// Check if version lengths are the same
			if(tempWeb.length() == tempThis.length()){
				if(web > current){
					// Version lengths different, unable to advance compare
					FactionsPlus.log.warning("! -=====================================- !");
					FactionsPlus.log.warning("FactionsPlus has an update, you");
					FactionsPlus.log.warning("can upgrade to version " + content.trim() + " via");
					FactionsPlus.log.warning("http://dev.bukkit.org/server-mods/factionsplus/");
					FactionsPlus.log.warning("! -=====================================- !");
				} else {
					FactionsPlus.info("Up to date!");
				}
			} else {
				// Version lengths different, unable to advance compare
				FactionsPlus.log.warning("! -=====================================- !");
				FactionsPlus.log.warning("FactionsPlus has an update, you");
				FactionsPlus.log.warning("can upgrade to version " + content.trim() + " via");
				FactionsPlus.log.warning("http://dev.bukkit.org/server-mods/factionsplus/");
				FactionsPlus.log.warning("! -=====================================- !");
			}
		} else {
			FactionsPlus.info("Up to date!");
		}
	}
}

@@ -321,17 +321,37 @@
 Boolean(
-%22
+FactionsPlus.confStr_
 disableU
@@ -360,17 +360,16 @@
 ateCheck
-%22
 )) %7B%0D%0A%09%09

use the right conf option for updates check flag