Skip to content

Commit a38301f

Browse files
author
FungY911
committed
fix first time update error
[WebServer] Failed to check for updates: Cannot invoke "String.equals(Object)" because "tk.fungy.wsformc.Updater.currentVersion" is null
1 parent 89eef41 commit a38301f

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/main/java/tk/fungy/wsformc/FileManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void startup() throws UnknownHostException {
3737
URL url = new URL("http://checkip.amazonaws.com");
3838
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
3939
ipaddr = reader.readLine();
40-
Main.getInstance().getLogger().info(ipaddr);
40+
Main.getInstance().getLogger().info("IP of device: " + ipaddr);
4141
} catch (Exception e) {
4242
Main.getInstance().getLogger().info("Failed to get your public ip. Returned error is: " + e.getMessage());
4343
}

src/main/java/tk/fungy/wsformc/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public void onEnable() {
3434
getLogger().info("Loading Assets.");
3535
instance.getCommand("wsm").setExecutor(new Command());
3636
instance.getCommand("webserver").setExecutor(new Command());
37-
Updater.startUpdater();
3837
if (WebServer.running) {
3938
if (Command.ws == null) Command.ws = new WebServer();
4039
getLogger().info("Starting Webserbver.");
4140
Command.ws.start();
4241
}
42+
Updater.startUpdater();
4343
}
4444

4545
@Override

src/main/java/tk/fungy/wsformc/Updater.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.net.URL;
1515

1616
public class Updater implements Listener {
17-
private static final String currentVersion = new FileManager().getStringFromConfig("Version");
17+
private static String currentVersion = new FileManager().getStringFromConfig("Version");
1818
private static String latestVersion;
1919
public static void startUpdater() {
2020
Bukkit.getScheduler().runTaskTimerAsynchronously(Main.instance, new Runnable() {
@@ -38,6 +38,10 @@ private static void checkForUpdates() {
3838
JsonObject latestRelease = releases.get(0).getAsJsonObject();
3939
latestVersion = latestRelease.get("tag_name").getAsString().replace("v", "");
4040

41+
if(currentVersion == null) {
42+
currentVersion = new FileManager().getStringFromConfig("Version");
43+
}
44+
4145
if (!currentVersion.equals(latestVersion)) {
4246
Bukkit.getLogger().warning(Colors.translate("[WebServer] A new update is available: " + latestVersion + " Your version is: " + currentVersion));
4347
} else {

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ WebServer:
3232
ssl: false # toggle: true/false, set this to true only if you have generated certificate and webserver pointed to domain
3333

3434
No-Permission: "nemas prava L"
35-
Version: 1.0 # Do not edit this line!
35+
Version: "1.0" # Do not edit this line!

0 commit comments

Comments
 (0)