Handle running multiple platforms at a time better.

This commit is contained in:
sk89q
2014-04-05 23:27:10 -07:00
parent d1a69fd985
commit f3e107da90
9 changed files with 148 additions and 16 deletions

View File

@ -89,4 +89,31 @@ public interface Platform {
*/
LocalConfiguration getConfiguration();
/**
* Get the version of WorldEdit that this platform provides.
* </p>
* This version should match WorldEdit releases because it may be
* checked to match.
*
* @return the version
*/
String getVersion();
/**
* Get a friendly name of the platform.
* </p>
* The name can be anything (reasonable). An example name may be
* "Bukkit" or "Forge".
*
* @return the platform name
*/
String getPlatformName();
/**
* Get the version of the platform, which can be anything.
*
* @return the platform version
*/
String getPlatformVersion();
}

View File

@ -64,11 +64,30 @@ public class PlatformManager {
*/
public synchronized void register(Platform platform) throws PlatformRejectionException {
checkNotNull(platform);
logger.log(Level.INFO, "Got request to register " + platform.getClass() + " with WorldEdit [" + super.toString() + "]");
logger.log(Level.FINE, "Got request to register " + platform.getClass() + " with WorldEdit [" + super.toString() + "]");
platforms.add(platform);
// Register primary platform
if (this.primary == null) {
commandManager.register(platform);
this.primary = platform;
} else {
// Make sure that versions are in sync
if (!primary.getVersion().equals(platform.getVersion())) {
logger.log(Level.WARNING,
"\n**********************************************\n" +
"** There is a mismatch in available WorldEdit platforms!\n" +
"**\n" +
"** {0} v{1} is trying to register WE version v{2}\n" +
"** but the primary platform, {3} v{4}, uses WE version v{5}\n" +
"**\n" +
"** Things may break! Please make sure that your WE versions are in sync.\n" +
"**********************************************\n",
new Object[]{
platform.getClass(), platform.getPlatformVersion(), platform.getVersion(),
primary.getClass(), primary.getPlatformVersion(), primary.getVersion()
});
}
}
}
@ -91,6 +110,26 @@ public class PlatformManager {
return removed;
}
/**
* Get a list of loaded platforms.
* </p>
* The returned list is a copy of the original and is mutable.
*
* @return a list of platforms
*/
public synchronized List<Platform> getPlatforms() {
return new ArrayList<Platform>(platforms);
}
/**
* Get the primary platform.
*
* @return the primary platform (may be null)
*/
public @Nullable Platform getPrimaryPlatform() {
return primary;
}
/**
* Get the command manager.
*

View File

@ -91,4 +91,19 @@ class ServerInterfaceAdapter extends ServerInterface {
return platform.getConfiguration();
}
@Override
public String getVersion() {
return platform.getVersion();
}
@Override
public String getPlatformName() {
return platform.getPlatformName();
}
@Override
public String getPlatformVersion() {
return platform.getPlatformVersion();
}
}