Archiviert
13
0

Crash if multiple copies of ProtocolLib are running simultaneously.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-12-27 12:12:11 +01:00
Ursprung 695a4f3b0e
Commit 447f01a3dd
4 geänderte Dateien mit 125 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -139,7 +139,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.4.5-R0.3-SNAPSHOT</version> <version>1.4.6-R0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -154,6 +154,36 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </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> </dependencies>
<reporting> <reporting>
<plugins> <plugins>
@ -181,6 +211,7 @@
</snapshotRepository> </snapshotRepository>
</distributionManagement> </distributionManagement>
<properties> <properties>
<powermock.version>1.5</powermock.version>
<project.build.sourceEncoding>cp1252</project.build.sourceEncoding> <project.build.sourceEncoding>cp1252</project.build.sourceEncoding>
</properties> </properties>
</project> </project>

Datei anzeigen

@ -216,6 +216,7 @@
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>
<version>1.8.4</version> <version>1.8.4</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.powermock</groupId> <groupId>org.powermock</groupId>

Datei anzeigen

@ -7,13 +7,14 @@ import org.bukkit.Server;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain; import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;
/** /**
* Determine the current Minecraft version. * Determine the current Minecraft version.
* *
* @author Kristian * @author Kristian
*/ */
class MinecraftVersion implements Comparable<MinecraftVersion> { public class MinecraftVersion implements Comparable<MinecraftVersion> {
/** /**
* Regular expression used to parse version strings. * Regular expression used to parse version strings.
*/ */
@ -23,6 +24,9 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
private final int minor; private final int minor;
private final int build; private final int build;
// The development stage
private final String development;
/** /**
* Determine the current Minecraft version. * Determine the current Minecraft version.
* @param server - the Bukkit server that will be used to examine the MC 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. * @param versionOnly - the version in text form.
*/ */
public MinecraftVersion(String versionOnly) { public MinecraftVersion(String versionOnly) {
int[] numbers = parseVersion(versionOnly); String[] section = versionOnly.split("-");
int[] numbers = parseVersion(section[0]);
this.major = numbers[0]; this.major = numbers[0];
this.minor = numbers[1]; this.minor = numbers[1];
this.build = numbers[2]; 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. * @param build - build version number.
*/ */
public MinecraftVersion(int major, int minor, int build) { 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.major = major;
this.minor = minor; this.minor = minor;
this.build = build; this.build = build;
this.development = development;
} }
private int[] parseVersion(String version) { private int[] parseVersion(String version) {
@ -93,12 +111,23 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
return build; 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. * Retrieve the version String (major.minor.build) only.
* @return A normal version string. * @return A normal version string.
*/ */
public String getVersion() { public String getVersion() {
if (development == null)
return String.format("%s.%s.%s", major, minor, build); return String.format("%s.%s.%s", major, minor, build);
else
return String.format("%s.%s.%s-%s", major, minor, build, development);
} }
@Override @Override
@ -110,6 +139,8 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
compare(major, o.major). compare(major, o.major).
compare(minor, o.minor). compare(minor, o.minor).
compare(build, o.build). compare(build, o.build).
// No development String means it's a release
compare(development, o.development, Ordering.natural().nullsLast()).
result(); result();
} }
@ -125,7 +156,8 @@ class MinecraftVersion implements Comparable<MinecraftVersion> {
return major == other.major && return major == other.major &&
minor == other.minor && minor == other.minor &&
build == other.build; build == other.build &&
Objects.equal(development, other.development);
} }
return false; return false;

Datei anzeigen

@ -17,11 +17,14 @@
package com.comphenix.protocol; package com.comphenix.protocol;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -97,6 +100,9 @@ public class ProtocolLibrary extends JavaPlugin {
private CommandProtocol commandProtocol; private CommandProtocol commandProtocol;
private CommandPacket commandPacket; private CommandPacket commandPacket;
// Whether or not disable is not needed
private boolean skipDisable;
@Override @Override
public void onLoad() { public void onLoad() {
// Load configuration // Load configuration
@ -104,7 +110,6 @@ public class ProtocolLibrary extends JavaPlugin {
// Add global parameters // Add global parameters
DetailedErrorReporter detailedReporter = new DetailedErrorReporter(this); DetailedErrorReporter detailedReporter = new DetailedErrorReporter(this);
updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info");
reporter = detailedReporter; reporter = detailedReporter;
try { try {
@ -121,6 +126,12 @@ public class ProtocolLibrary extends JavaPlugin {
} }
try { try {
// Check for other versions
checkConflictingVersions();
// Set updater
updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info");
unhookTask = new DelayedSingleTask(this); unhookTask = new DelayedSingleTask(this);
protocolManager = new PacketFilterManager(getClassLoader(), getServer(), unhookTask, detailedReporter); protocolManager = new PacketFilterManager(getClassLoader(), getServer(), unhookTask, detailedReporter);
detailedReporter.addGlobalParameter("manager", protocolManager); 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) { private void registerCommand(String name, CommandExecutor executor) {
try { try {
if (executor == null) if (executor == null)
@ -331,6 +381,10 @@ public class ProtocolLibrary extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
if (skipDisable) {
return;
}
// Disable compiler // Disable compiler
if (backgroundCompiler != null) { if (backgroundCompiler != null) {
backgroundCompiler.shutdownAll(); backgroundCompiler.shutdownAll();