From f2aa9dccd1230d9061bd20fb27bd2ae2330c08d2 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 20 Feb 2020 20:08:25 +0100 Subject: [PATCH] Revert "Remove unused code" This reverts commit 6d779dad050cea295a3828985da26e7014460079. --- .../plotsquared/plot/PlotSquared.java | 17 ++++++++++++ .../plotsquared/plot/PlotVersion.java | 27 +++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 681c2dd33..429e1396b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -61,14 +61,18 @@ import lombok.NonNull; import lombok.Setter; import org.jetbrains.annotations.Nullable; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; import java.sql.SQLException; import java.util.ArrayDeque; import java.util.ArrayList; @@ -76,6 +80,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -1602,6 +1607,18 @@ import java.util.zip.ZipInputStream; } } Settings.load(configFile); + //Sets the version information for the settings.yml file + try (InputStream stream = getClass().getResourceAsStream("/plugin.properties")) { + try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) { + String versionString = br.readLine(); + String commitString = br.readLine(); + String dateString = br.readLine(); + this.version = PlotVersion.tryParse(versionString, commitString, dateString); + System.out.println("Version is " + this.version); + } + } catch (IOException throwable) { + throwable.printStackTrace(); + } Settings.save(configFile); config = YamlConfiguration.loadConfiguration(configFile); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java index d6abb880d..ea533e598 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java @@ -3,6 +3,14 @@ package com.github.intellectualsites.plotsquared.plot; public class PlotVersion { public final int year, month, day, hash, build; + public PlotVersion(int year, int month, int day, int hash, int build) { + this.year = year; + this.month = month; + this.day = day; + this.hash = hash; + this.build = build; + } + public PlotVersion(String version, String commit, String date) { String[] split = version.substring(version.indexOf('=') + 1).split("\\."); this.build = Integer.parseInt(split[1]); @@ -13,8 +21,23 @@ public class PlotVersion { this.day = Integer.parseInt(split1[2]); } - @Override - public String toString() { + public static PlotVersion tryParse(String version, String commit, String date) { + try { + return new PlotVersion(version, commit, date); + } catch (Exception e) { + e.printStackTrace(); + return new PlotVersion(0, 0, 0, 0, 0); + } + } + + public String versionString() { + if (hash == 0 && build == 0) { + return "NoVer-SNAPSHOT"; + } else { + return "5." + build; + } + } + @Override public String toString() { if (hash == 0 && build == 0) { return "PlotSquared-NoVer-SNAPSHOT"; } else {