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

@ -61,6 +61,9 @@ sourceSets {
minecraft {
version = "1.6.4-9.11.1.964"
forgeVersion = "9.11.1.964"
replaceIn "com/sk89q/worldedit/forge/WorldEditMod.java"
replace "%VERSION%", project.version
}
processResources {

View File

@ -119,6 +119,21 @@ public class BukkitServerInterface extends ServerInterface {
return plugin.getLocalConfiguration();
}
@Override
public String getVersion() {
return plugin.getDescription().getVersion();
}
@Override
public String getPlatformName() {
return "Bukkit-Official";
}
@Override
public String getPlatformVersion() {
return plugin.getDescription().getVersion();
}
public void unregisterCommands() {
dynamicCommands.unregisterCommands();
}

View File

@ -130,4 +130,19 @@ public class ForgeServerInterface extends ServerInterface {
public LocalConfiguration getConfiguration() {
return mod.getConfig();
}
@Override
public String getVersion() {
return mod.getInternalVersion();
}
@Override
public String getPlatformName() {
return "Forge-Official";
}
@Override
public String getPlatformVersion() {
return mod.getInternalVersion();
}
}

View File

@ -62,7 +62,7 @@ public class WorldEditMod {
logger.setParent(FMLLog.getLogger());
Logger.getLogger("com.sk89q").setParent(FMLLog.getLogger());
String modVersion = WorldEditMod.class.getAnnotation(Mod.class).version();
String modVersion = getInternalVersion();
String manifestVersion = WorldEdit.getVersion();
if (!manifestVersion.equalsIgnoreCase(modVersion) && !modVersion.equals("%VERSION%")) {
WorldEdit.setVersion(manifestVersion + " (" + modVersion + ")");
@ -176,4 +176,9 @@ public class WorldEditMod {
}
}
}
String getInternalVersion() {
return WorldEditMod.class.getAnnotation(Mod.class).version();
}
}

View File

@ -1042,12 +1042,10 @@ public class WorldEdit {
}
/**
* Set the version of WorldEdit.
*
* @param version the version
* @deprecated Declare your platform version with {@link Platform#getPlatformVersion()}
*/
@Deprecated
public static void setVersion(String version) {
WorldEdit.version = version;
}
}

View File

@ -19,19 +19,18 @@
package com.sk89q.worldedit.command;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Console;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
public class WorldEditCommands {
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
@ -54,7 +53,23 @@ public class WorldEditCommands {
EditSession editSession) throws WorldEditException {
player.print("WorldEdit version " + WorldEdit.getVersion());
player.print("http://www.sk89q.com/projects/worldedit/");
player.print("https://github.com/sk89q/worldedit/");
PlatformManager pm = we.getPlatformManager();
Platform primary = pm.getPrimaryPlatform();
player.printDebug("");
player.printDebug("Platforms:");
for (Platform platform : pm.getPlatforms()) {
String prefix = "";
if (primary != null && primary.equals(platform)) {
prefix = "[PRIMARY] ";
}
player.printDebug(String.format("- %s%s v%s (WE v%s)",
prefix, platform.getPlatformName(), platform.getPlatformVersion(), platform.getVersion()));
}
}
@Command(

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();
}
}