|
| 1 | +package io.github.redstoneboy0509.javaez; |
| 2 | + |
| 3 | +import java.io.BufferedReader; |
| 4 | +import java.io.InputStreamReader; |
| 5 | +import java.net.URL; |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +/** |
| 10 | + * Main class for JavaEZ |
| 11 | + * @author RedstoneBoy0509 |
| 12 | + * @since 1.1 |
| 13 | + */ |
| 14 | +public class JavaEZ { |
| 15 | + |
| 16 | + /** |
| 17 | + * The current version of JavaEZ. |
| 18 | + * @since 1.1 |
| 19 | + */ |
| 20 | + public static final String VERSION = "1.1"; |
| 21 | + |
| 22 | + /** |
| 23 | + * Prints info about your version of JavaEZ |
| 24 | + * @since 1.1 |
| 25 | + */ |
| 26 | + public static void info() { |
| 27 | + System.out.println("=[JavaEZ Info]="); |
| 28 | + System.out.println("JavaEZ running on version " + VERSION); |
| 29 | + String latestVersion = getLatestVersion(); |
| 30 | + boolean areWeUpdated = latestVersion.equalsIgnoreCase(VERSION); |
| 31 | + if(!areWeUpdated) { |
| 32 | + System.out.println("Attention: your JavaEZ is not at latest version, please consider updating!"); |
| 33 | + System.out.println("Latest version: " + latestVersion); |
| 34 | + } else System.out.println("JavaEZ is up to date!"); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Gets the latest version |
| 39 | + * @return The latest version |
| 40 | + * @since 1.1 |
| 41 | + */ |
| 42 | + public static String getLatestVersion() { |
| 43 | + List<String> versions = getVersions(); |
| 44 | + return versions.isEmpty() ? "Unknown" : versions.get(versions.size() - 1); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Returns a list of all known versions on the Internet |
| 49 | + * @return a list of all existent versions |
| 50 | + * @since 1.1 |
| 51 | + */ |
| 52 | + public static List<String> getVersions() { |
| 53 | + try { |
| 54 | + URL url = new URL("https://gist.githubusercontent.com/RedstoneBoy0509/fb10258f9ae7d858f94b8cbaa651548f/raw/"); |
| 55 | + BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); |
| 56 | + List<String> list = new ArrayList<>(); |
| 57 | + String line; |
| 58 | + while((line = reader.readLine()) != null) { |
| 59 | + if(line.isEmpty()) continue; |
| 60 | + list.add(line); |
| 61 | + } |
| 62 | + reader.close(); |
| 63 | + return list; |
| 64 | + } catch(Exception ex) { |
| 65 | + return new ArrayList<>(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments