Regression: Add back support for CraftBukkit 1.1.0

This commit is contained in:
Kristian S. Stangeland 2014-02-11 23:58:33 +01:00
parent 4e650ec7bf
commit a8378d4e6f
5 changed files with 77 additions and 11 deletions

View File

@ -17,14 +17,42 @@
package com.comphenix.protocol; package com.comphenix.protocol;
import org.bukkit.Bukkit;
/** /**
* Ignore this class. * Ignore this class.
* *
* @author Kristian * @author Kristian
*/ */
public class Application { public class Application {
private static Thread mainThread;
private static boolean primaryMethod = true;
public static void main(String[] args) { public static void main(String[] args) {
// For now, though we might consider making a proper application // For now, though we might consider making a proper application
System.out.println("This is a Bukkit library. Place it in the plugin-folder and restart the server!"); System.out.println("This is a Bukkit library. Place it in the plugin-folder and restart the server!");
} }
/**
* Determine if we are running on the main thread.
* @return TRUE if we are, FALSE otherwise.
*/
public static boolean isPrimaryThread() {
if (primaryMethod) {
try {
return Bukkit.isPrimaryThread();
} catch (Throwable e) {
primaryMethod = false;
}
}
// Fallback method
return Thread.currentThread().equals(mainThread);
}
/**
* Register the calling thread as the primary thread.
*/
static void registerPrimaryThread() {
mainThread = Thread.currentThread();
}
} }

View File

@ -737,7 +737,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
}; };
// Execute in the main thread if possible // Execute in the main thread if possible
if (Bukkit.getServer() == null || Bukkit.isPrimaryThread()) { if (Bukkit.getServer() == null || Application.isPrimaryThread()) {
try { try {
return Futures.immediateFuture(callable.call()); return Futures.immediateFuture(callable.call());
} catch (Exception e) { } catch (Exception e) {

View File

@ -101,6 +101,13 @@ public class ProtocolLibrary extends JavaPlugin {
static final String BUKKIT_DEV_SLUG = "protocollib"; static final String BUKKIT_DEV_SLUG = "protocollib";
static final int BUKKIT_DEV_ID = 45564; static final int BUKKIT_DEV_ID = 45564;
// Different commands
private enum ProtocolCommand {
FILTER,
PACKET,
PROTOCOL
}
/** /**
* The number of milliseconds per second. * The number of milliseconds per second.
*/ */
@ -159,6 +166,7 @@ public class ProtocolLibrary extends JavaPlugin {
public void onLoad() { public void onLoad() {
// Load configuration // Load configuration
logger = getLoggerSafely(); logger = getLoggerSafely();
Application.registerPrimaryThread();
// Initialize enhancer factory // Initialize enhancer factory
EnhancerFactory.getInstance().setClassLoader(getClassLoader()); EnhancerFactory.getInstance().setClassLoader(getClassLoader());
@ -230,12 +238,8 @@ public class ProtocolLibrary extends JavaPlugin {
reporter.reportWarning(config, Report.newBuilder(REPORT_CANNOT_PARSE_INJECTION_METHOD).error(e)); reporter.reportWarning(config, Report.newBuilder(REPORT_CANNOT_PARSE_INJECTION_METHOD).error(e));
} }
// Initialize command handlers
commandProtocol = new CommandProtocol(reporter, this, updater, config);
commandFilter = new CommandFilter(reporter, this, config);
commandPacket = new CommandPacket(reporter, this, logger, commandFilter, protocolManager);
// Send logging information to player listeners too // Send logging information to player listeners too
initializeCommands();
setupBroadcastUsers(PERMISSION_INFO); setupBroadcastUsers(PERMISSION_INFO);
} catch (Throwable e) { } catch (Throwable e) {
@ -244,6 +248,28 @@ public class ProtocolLibrary extends JavaPlugin {
} }
} }
/**
* Initialize all command handlers.
*/
private void initializeCommands() {
// Initialize command handlers
for (ProtocolCommand command : ProtocolCommand.values()) {
try {
switch (command) {
case PROTOCOL:
commandProtocol = new CommandProtocol(reporter, this, updater, config); break;
case FILTER:
commandFilter = new CommandFilter(reporter, this, config); break;
case PACKET:
commandPacket = new CommandPacket(reporter, this, logger, commandFilter, protocolManager); break;
}
} catch (Throwable e) {
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND).
messageParam(command.name(), e.getMessage()).error(e));
}
}
}
/** /**
* Retrieve a error reporter that may be filtered by the configuration. * Retrieve a error reporter that may be filtered by the configuration.
* @return The new default error reporter. * @return The new default error reporter.
@ -461,8 +487,9 @@ public class ProtocolLibrary extends JavaPlugin {
private void registerCommand(String name, CommandExecutor executor) { private void registerCommand(String name, CommandExecutor executor) {
try { try {
// Ignore these - they must have printed an error already
if (executor == null) if (executor == null)
throw new RuntimeException("Executor was NULL."); return;
PluginCommand command = getCommand(name); PluginCommand command = getCommand(name);

View File

@ -27,6 +27,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import com.comphenix.protocol.Application;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.async.AsyncMarker; import com.comphenix.protocol.async.AsyncMarker;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
@ -149,7 +150,7 @@ public class PacketEvent extends EventObject implements Cancellable {
* @return TRUE if we are, FALSE otherwise. * @return TRUE if we are, FALSE otherwise.
*/ */
public boolean isAsync() { public boolean isAsync() {
return !Bukkit.isPrimaryThread(); return !Application.isPrimaryThread();
} }
/** /**

View File

@ -235,8 +235,15 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
this.classLoader = builder.getClassLoader(); this.classLoader = builder.getClassLoader();
this.reporter = builder.getReporter(); this.reporter = builder.getReporter();
// The plugin verifier // The plugin verifier - we don't want to stop ProtocolLib just because its failing
try {
this.pluginVerifier = new PluginVerifier(builder.getLibrary()); this.pluginVerifier = new PluginVerifier(builder.getLibrary());
} catch (Throwable e) {
reporter.reportWarning(this, Report.newBuilder(REPORT_PLUGIN_VERIFIER_ERROR).
messageParam(e.getMessage()).error(e));
}
// Prepare version
this.minecraftVersion = builder.getMinecraftVersion(); this.minecraftVersion = builder.getMinecraftVersion();
this.loginPackets = new LoginPackets(minecraftVersion); this.loginPackets = new LoginPackets(minecraftVersion);
@ -356,6 +363,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @param plugin - plugin to check. * @param plugin - plugin to check.
*/ */
private void printPluginWarnings(Plugin plugin) { private void printPluginWarnings(Plugin plugin) {
if (pluginVerifier == null)
return;
try { try {
switch (pluginVerifier.verify(plugin)) { switch (pluginVerifier.verify(plugin)) {
case NO_DEPEND: case NO_DEPEND: