diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 1fcc2aed3c..6f69bd7bdd 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -70,6 +70,7 @@ import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe; import org.bukkit.craftbukkit.map.CraftMapView; import org.bukkit.scheduler.BukkitWorker; import org.bukkit.craftbukkit.scheduler.CraftScheduler; +import org.bukkit.craftbukkit.util.Versioning; import org.bukkit.util.permissions.DefaultPermissions; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.permissions.Permission; @@ -82,6 +83,7 @@ public final class CraftServer implements Server { private final String serverName = "Craftbukkit"; private final String serverVersion; private final String protocolVersion = "1.8.1"; + private final String bukkitVersion = Versioning.getBukkitVersion(); private final ServicesManager servicesManager = new SimpleServicesManager(); private final BukkitScheduler scheduler = new CraftScheduler(this); private final SimpleCommandMap commandMap = new SimpleCommandMap(this); @@ -191,6 +193,10 @@ public final class CraftServer implements Server { public String getVersion() { return serverVersion + " (MC: " + protocolVersion + ")"; } + + public String getBukkitVersion() { + return bukkitVersion; + } @SuppressWarnings("unchecked") public Player[] getOnlinePlayers() { diff --git a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java new file mode 100644 index 0000000000..157b532a0e --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java @@ -0,0 +1,29 @@ +package org.bukkit.craftbukkit.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Bukkit; + +public final class Versioning { + public static String getBukkitVersion() { + String result = "Unknown-Version"; + + InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/org.bukkit/bukkit/pom.properties"); + Properties properties = new Properties(); + + if (stream != null) { + try { + properties.load(stream); + + result = properties.getProperty("version"); + } catch (IOException ex) { + Logger.getLogger(Versioning.class.getName()).log(Level.SEVERE, "Could not get Bukkit version!", ex); + } + } + + return result; + } +}