Revert "Remove unused code"

This reverts commit 6d779dad05.
This commit is contained in:
NotMyFault 2020-02-20 20:08:25 +01:00
parent 464f5e09ae
commit f2aa9dccd1
2 changed files with 42 additions and 2 deletions

View File

@ -61,14 +61,18 @@ import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
@ -76,6 +80,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -1602,6 +1607,18 @@ import java.util.zip.ZipInputStream;
} }
} }
Settings.load(configFile); 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); Settings.save(configFile);
config = YamlConfiguration.loadConfiguration(configFile); config = YamlConfiguration.loadConfiguration(configFile);
} }

View File

@ -3,6 +3,14 @@ package com.github.intellectualsites.plotsquared.plot;
public class PlotVersion { public class PlotVersion {
public final int year, month, day, hash, build; 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) { public PlotVersion(String version, String commit, String date) {
String[] split = version.substring(version.indexOf('=') + 1).split("\\."); String[] split = version.substring(version.indexOf('=') + 1).split("\\.");
this.build = Integer.parseInt(split[1]); this.build = Integer.parseInt(split[1]);
@ -13,8 +21,23 @@ public class PlotVersion {
this.day = Integer.parseInt(split1[2]); this.day = Integer.parseInt(split1[2]);
} }
@Override public static PlotVersion tryParse(String version, String commit, String date) {
public String toString() { 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) { if (hash == 0 && build == 0) {
return "PlotSquared-NoVer-SNAPSHOT"; return "PlotSquared-NoVer-SNAPSHOT";
} else { } else {