Crash if multiple copies of ProtocolLib are running simultaneously.
Dieser Commit ist enthalten in:
Ursprung
695a4f3b0e
Commit
447f01a3dd
@ -139,7 +139,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.5-R0.3-SNAPSHOT</version>
|
||||
<version>1.4.6-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -154,6 +154,36 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.8.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>powermock-module-junit4-common</artifactId>
|
||||
<groupId>org.powermock</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>powermock-api-support</artifactId>
|
||||
<groupId>org.powermock</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<reporting>
|
||||
<plugins>
|
||||
@ -181,6 +211,7 @@
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<properties>
|
||||
<powermock.version>1.5</powermock.version>
|
||||
<project.build.sourceEncoding>cp1252</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
@ -216,6 +216,7 @@
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.8.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
|
@ -7,13 +7,14 @@ import org.bukkit.Server;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
/**
|
||||
* Determine the current Minecraft version.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
public class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
/**
|
||||
* Regular expression used to parse version strings.
|
||||
*/
|
||||
@ -23,6 +24,9 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
private final int minor;
|
||||
private final int build;
|
||||
|
||||
// The development stage
|
||||
private final String development;
|
||||
|
||||
/**
|
||||
* Determine the current Minecraft version.
|
||||
* @param server - the Bukkit server that will be used to examine the MC version.
|
||||
@ -36,11 +40,13 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
* @param versionOnly - the version in text form.
|
||||
*/
|
||||
public MinecraftVersion(String versionOnly) {
|
||||
int[] numbers = parseVersion(versionOnly);
|
||||
String[] section = versionOnly.split("-");
|
||||
int[] numbers = parseVersion(section[0]);
|
||||
|
||||
this.major = numbers[0];
|
||||
this.minor = numbers[1];
|
||||
this.build = numbers[2];
|
||||
this.development = section.length > 1 ? section[1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,9 +56,21 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
* @param build - build version number.
|
||||
*/
|
||||
public MinecraftVersion(int major, int minor, int build) {
|
||||
this(major, minor, build, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a version object directly.
|
||||
* @param major - major version number.
|
||||
* @param minor - minor version number.
|
||||
* @param build - build version number.
|
||||
* @param development - development stage.
|
||||
*/
|
||||
public MinecraftVersion(int major, int minor, int build, String development) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.build = build;
|
||||
this.development = development;
|
||||
}
|
||||
|
||||
private int[] parseVersion(String version) {
|
||||
@ -93,12 +111,23 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the development stage.
|
||||
* @return Development stage, or NULL if this is a release.
|
||||
*/
|
||||
public String getDevelopmentStage() {
|
||||
return development;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the version String (major.minor.build) only.
|
||||
* @return A normal version string.
|
||||
*/
|
||||
public String getVersion() {
|
||||
if (development == null)
|
||||
return String.format("%s.%s.%s", major, minor, build);
|
||||
else
|
||||
return String.format("%s.%s.%s-%s", major, minor, build, development);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,6 +139,8 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
compare(major, o.major).
|
||||
compare(minor, o.minor).
|
||||
compare(build, o.build).
|
||||
// No development String means it's a release
|
||||
compare(development, o.development, Ordering.natural().nullsLast()).
|
||||
result();
|
||||
}
|
||||
|
||||
@ -125,7 +156,8 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
|
||||
return major == other.major &&
|
||||
minor == other.minor &&
|
||||
build == other.build;
|
||||
build == other.build &&
|
||||
Objects.equal(development, other.development);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -17,11 +17,14 @@
|
||||
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -97,6 +100,9 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
private CommandProtocol commandProtocol;
|
||||
private CommandPacket commandPacket;
|
||||
|
||||
// Whether or not disable is not needed
|
||||
private boolean skipDisable;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// Load configuration
|
||||
@ -104,7 +110,6 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
|
||||
// Add global parameters
|
||||
DetailedErrorReporter detailedReporter = new DetailedErrorReporter(this);
|
||||
updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info");
|
||||
reporter = detailedReporter;
|
||||
|
||||
try {
|
||||
@ -121,6 +126,12 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
}
|
||||
|
||||
try {
|
||||
// Check for other versions
|
||||
checkConflictingVersions();
|
||||
|
||||
// Set updater
|
||||
updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info");
|
||||
|
||||
unhookTask = new DelayedSingleTask(this);
|
||||
protocolManager = new PacketFilterManager(getClassLoader(), getServer(), unhookTask, detailedReporter);
|
||||
detailedReporter.addGlobalParameter("manager", protocolManager);
|
||||
@ -253,6 +264,45 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkConflictingVersions() {
|
||||
Pattern ourPlugin = Pattern.compile("ProtocolLib-(.*)\\.jar");
|
||||
MinecraftVersion currentVersion = new MinecraftVersion(this.getDescription().getVersion());
|
||||
MinecraftVersion newestVersion = null;
|
||||
|
||||
try {
|
||||
// Scan the plugin folder for newer versions of ProtocolLib
|
||||
File pluginFolder = new File("plugins/");
|
||||
|
||||
for (File candidate : pluginFolder.listFiles()) {
|
||||
if (candidate.isFile()) {
|
||||
Matcher match = ourPlugin.matcher(candidate.getName());
|
||||
|
||||
if (match.matches()) {
|
||||
MinecraftVersion version = new MinecraftVersion(match.group(1));
|
||||
|
||||
if (newestVersion == null || newestVersion.compareTo(version) < 0) {
|
||||
newestVersion = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
reporter.reportWarning(this, "Unable to detect conflicting plugin versions.", e);
|
||||
}
|
||||
|
||||
// See if the newest version is actually higher
|
||||
if (newestVersion != null && currentVersion.compareTo(newestVersion) < 0) {
|
||||
// We don't need to set internal classes or instances to NULL - that would break the other loaded plugin
|
||||
skipDisable = true;
|
||||
|
||||
throw new IllegalStateException(
|
||||
String.format("Detected a newer version of ProtocolLib (%s) in plugin folder than the current (%s). Disabling.",
|
||||
newestVersion.getVersion(), currentVersion.getVersion())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommand(String name, CommandExecutor executor) {
|
||||
try {
|
||||
if (executor == null)
|
||||
@ -331,6 +381,10 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (skipDisable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable compiler
|
||||
if (backgroundCompiler != null) {
|
||||
backgroundCompiler.shutdownAll();
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren