MassiveCore - Version Synchronized Warnings

This commit is contained in:
Olof Larsson 2015-10-21 20:28:50 +02:00
parent 9667e27fcb
commit 70b6f5cb75
4 changed files with 58 additions and 6 deletions

View File

@ -24,6 +24,8 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public boolean checkVersionSynchronization = true;
public int maxTabCompletions = 100; public int maxTabCompletions = 100;
public List<String> aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore"); public List<String> aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore");

View File

@ -20,8 +20,18 @@ import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
public abstract class MassivePlugin extends JavaPlugin implements Listener public abstract class MassivePlugin extends JavaPlugin implements Listener
{ {
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// Gson // 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 // ENABLE
@ -38,7 +48,8 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener
log("=== ENABLE START ==="); log("=== ENABLE START ===");
// Create Gson // Create Gson
this.gson = this.getGsonBuilder().create(); Gson gson = this.getGsonBuilder().create();
this.setGson(gson);
// Listener // Listener
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
@ -60,7 +71,46 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener
public void postEnable() public void postEnable()
{ {
log(Txt.parse("=== ENABLE <g>COMPLETE <i>(Took <h>"+(System.currentTimeMillis()-timeEnableStart)+"ms<i>) ===")); long ms = System.currentTimeMillis()-timeEnableStart;
this.checkVersionSynchronization();
log(Txt.parse("=== ENABLE <g>COMPLETE <i>(Took <h>" + ms + "ms<i>) ==="));
}
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("<b>WARNING: You are using <pink>" + thisName + " <aqua>" + thisVersion + " <b>and <pink>" + massiveName + " <aqua>" + massiveVersion + "<b>!"));
log(Txt.parse("<b>WARNING: They must be the exact same version to work properly!"));
log(Txt.parse("<b>WARNING: Remember to always update all plugins at the same time!"));
log(Txt.parse("<b>WARNING: You should stop your server and properly update."));
// ... and pause for 10 seconds.
try
{
Thread.sleep(10000L);
}
catch (InterruptedException ignored)
{
}
} }
@Override @Override

View File

@ -44,7 +44,7 @@ public class SimpleConfig
{ {
if (this.plugin instanceof MassivePlugin) if (this.plugin instanceof MassivePlugin)
{ {
return ((MassivePlugin)this.plugin).gson; return ((MassivePlugin)this.plugin).getGson();
} }
return MassiveCore.gson; return MassiveCore.gson;
} }

View File

@ -80,7 +80,7 @@ public class Coll<E> extends CollAbstract<E>
{ {
if (this.getPlugin() instanceof MassivePlugin) if (this.getPlugin() instanceof MassivePlugin)
{ {
return ((MassivePlugin)this.getPlugin()).gson; return ((MassivePlugin)this.getPlugin()).getGson();
} }
else else
{ {