From f3e107da900f8467a4689ce7b3bce24921b255e2 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 5 Apr 2014 23:27:10 -0700 Subject: [PATCH] Handle running multiple platforms at a time better. --- build.gradle | 3 ++ .../bukkit/BukkitServerInterface.java | 15 +++++++ .../worldedit/forge/ForgeServerInterface.java | 15 +++++++ .../sk89q/worldedit/forge/WorldEditMod.java | 7 +++- .../java/com/sk89q/worldedit/WorldEdit.java | 6 +-- .../worldedit/command/WorldEditCommands.java | 35 +++++++++++----- .../extension/platform/Platform.java | 27 ++++++++++++ .../extension/platform/PlatformManager.java | 41 ++++++++++++++++++- .../platform/ServerInterfaceAdapter.java | 15 +++++++ 9 files changed, 148 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index bb97da82d..d48aba710 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 955f7d84d..6a34748a9 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -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(); } diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java index c61f0eeb5..b226b5d80 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java @@ -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(); + } } diff --git a/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java b/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java index c3d41166c..f7dec3dfb 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java +++ b/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java @@ -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(); + } + } diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index cb328c3c2..cf137bb4d 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -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; } } diff --git a/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index a791d86e2..a4ce0f806 100644 --- a/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -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( diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java b/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java index deaa7056d..2d506a07c 100644 --- a/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java +++ b/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java @@ -89,4 +89,31 @@ public interface Platform { */ LocalConfiguration getConfiguration(); + /** + * Get the version of WorldEdit that this platform provides. + *

+ * 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. + *

+ * 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(); + } diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 931e23bdd..5f10187ee 100644 --- a/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -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. + *

+ * The returned list is a copy of the original and is mutable. + * + * @return a list of platforms + */ + public synchronized List getPlatforms() { + return new ArrayList(platforms); + } + + /** + * Get the primary platform. + * + * @return the primary platform (may be null) + */ + public @Nullable Platform getPrimaryPlatform() { + return primary; + } + /** * Get the command manager. * diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/ServerInterfaceAdapter.java b/src/main/java/com/sk89q/worldedit/extension/platform/ServerInterfaceAdapter.java index e916cfcfb..5f1bd80f4 100644 --- a/src/main/java/com/sk89q/worldedit/extension/platform/ServerInterfaceAdapter.java +++ b/src/main/java/com/sk89q/worldedit/extension/platform/ServerInterfaceAdapter.java @@ -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(); + } + }