From 70b6f5cb75653f37c0b3bb996988ea9e032edb4f Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 21 Oct 2015 20:28:50 +0200 Subject: [PATCH] MassiveCore - Version Synchronized Warnings --- .../massivecore/MassiveCoreMConf.java | 2 + .../massivecore/MassivePlugin.java | 58 +++++++++++++++++-- .../massivecore/SimpleConfig.java | 2 +- .../massivecraft/massivecore/store/Coll.java | 2 +- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/com/massivecraft/massivecore/MassiveCoreMConf.java b/src/com/massivecraft/massivecore/MassiveCoreMConf.java index 72e40a2c..478a3346 100644 --- a/src/com/massivecraft/massivecore/MassiveCoreMConf.java +++ b/src/com/massivecraft/massivecore/MassiveCoreMConf.java @@ -24,6 +24,8 @@ public class MassiveCoreMConf extends Entity // FIELDS // -------------------------------------------- // + public boolean checkVersionSynchronization = true; + public int maxTabCompletions = 100; public List aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore"); diff --git a/src/com/massivecraft/massivecore/MassivePlugin.java b/src/com/massivecraft/massivecore/MassivePlugin.java index 086b5a36..a1c72968 100644 --- a/src/com/massivecraft/massivecore/MassivePlugin.java +++ b/src/com/massivecraft/massivecore/MassivePlugin.java @@ -20,8 +20,18 @@ import com.massivecraft.massivecore.xlib.gson.GsonBuilder; public abstract class MassivePlugin extends JavaPlugin implements Listener { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + // Gson - public Gson gson; + protected Gson gson = null; + public Gson getGson() { return this.gson; } + public void setGson(Gson gson) { this.gson = gson; } + + protected boolean versionSynchronized = false; + public boolean isVersionSynchronized() { return this.versionSynchronized; } + public void setVersionSynchronized(boolean versionSynchronized) { this.versionSynchronized = versionSynchronized; } // -------------------------------------------- // // ENABLE @@ -38,7 +48,8 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener log("=== ENABLE START ==="); // Create Gson - this.gson = this.getGsonBuilder().create(); + Gson gson = this.getGsonBuilder().create(); + this.setGson(gson); // Listener Bukkit.getPluginManager().registerEvents(this, this); @@ -60,13 +71,52 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener public void postEnable() { - log(Txt.parse("=== ENABLE COMPLETE (Took "+(System.currentTimeMillis()-timeEnableStart)+"ms) ===")); + long ms = System.currentTimeMillis()-timeEnableStart; + + this.checkVersionSynchronization(); + + log(Txt.parse("=== ENABLE COMPLETE (Took " + ms + "ms) ===")); + } + + public void checkVersionSynchronization() + { + // If this plugin is version synchronized ... + if ( ! this.isVersionSynchronized()) return; + + // ... and checking is enabled ... + if ( ! MassiveCoreMConf.get().checkVersionSynchronization) return; + + // ... get the version numbers ... + String thisVersion = this.getDescription().getVersion(); + String massiveVersion = MassiveCore.get().getDescription().getVersion(); + + // ... and if the version numbers are different ... + if (thisVersion.equals(massiveVersion)) return; + + // ... log a warning message ... + String thisName = this.getDescription().getName(); + String massiveName = MassiveCore.get().getDescription().getName(); + + log(Txt.parse("WARNING: You are using " + thisName + " " + thisVersion + " and " + massiveName + " " + massiveVersion + "!")); + log(Txt.parse("WARNING: They must be the exact same version to work properly!")); + log(Txt.parse("WARNING: Remember to always update all plugins at the same time!")); + log(Txt.parse("WARNING: You should stop your server and properly update.")); + + // ... and pause for 10 seconds. + try + { + Thread.sleep(10000L); + } + catch (InterruptedException ignored) + { + + } } @Override public void onEnable() { - if (!this.preEnable()) return; + if ( ! this.preEnable()) return; this.postEnable(); } diff --git a/src/com/massivecraft/massivecore/SimpleConfig.java b/src/com/massivecraft/massivecore/SimpleConfig.java index f88cbcaa..f512a97e 100644 --- a/src/com/massivecraft/massivecore/SimpleConfig.java +++ b/src/com/massivecraft/massivecore/SimpleConfig.java @@ -44,7 +44,7 @@ public class SimpleConfig { if (this.plugin instanceof MassivePlugin) { - return ((MassivePlugin)this.plugin).gson; + return ((MassivePlugin)this.plugin).getGson(); } return MassiveCore.gson; } diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index 4867e484..ede99b2b 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -80,7 +80,7 @@ public class Coll extends CollAbstract { if (this.getPlugin() instanceof MassivePlugin) { - return ((MassivePlugin)this.getPlugin()).gson; + return ((MassivePlugin)this.getPlugin()).getGson(); } else {