From 845f339a3048728aeabeb45d720b69132291b5ea Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 13 Jan 2013 11:31:32 +0100 Subject: [PATCH] Add the ability to set the default injection hook method. This is useful for debugging. --- .../comphenix/protocol/ProtocolConfig.java | 39 ++++++++++++++++++- .../comphenix/protocol/ProtocolLibrary.java | 7 ++++ ProtocolLib/src/main/resources/config.yml | 6 ++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java index 040a8ef1..ce084d0a 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java @@ -23,6 +23,8 @@ import org.bukkit.configuration.Configuration; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.plugin.Plugin; +import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; + /** * Represents the configuration of ProtocolLib. * @@ -35,9 +37,10 @@ class ProtocolConfig { private static final String METRICS_ENABLED = "metrics"; - private static final String IGNORE_VERSION_CHECK = "ignore version check"; - + private static final String IGNORE_VERSION_CHECK = "ignore version check"; private static final String BACKGROUND_COMPILER_ENABLED = "background compiler"; + + private static final String INJECTION_METHOD = "injection method"; private static final String UPDATER_NOTIFY = "notify"; private static final String UPDATER_DOWNLAD = "download"; @@ -234,6 +237,38 @@ class ProtocolConfig { updater.set(UPDATER_LAST_TIME, lastTimeSeconds); } + /** + * Retrieve the default injection method. + * @return Default method. + */ + public PlayerInjectHooks getDefaultMethod() { + return PlayerInjectHooks.NETWORK_SERVER_OBJECT; + } + + /** + * Retrieve the injection method that has been set in the configuration, or use a default value. + * @return Injection method to use. + * @throws IllegalArgumentException If the configuration option is malformed. + */ + public PlayerInjectHooks getInjectionMethod() throws IllegalArgumentException { + String text = global.getString(INJECTION_METHOD); + + // Default hook if nothing has been set + PlayerInjectHooks hook = getDefaultMethod(); + + if (text != null) + hook = PlayerInjectHooks.valueOf(text.toUpperCase().replace(" ", "_")); + return hook; + } + + /** + * Set the starting injection method to use. + * @return Injection method. + */ + public void setInjectionMethod(PlayerInjectHooks hook) { + global.set(INJECTION_METHOD, hook.name()); + } + /** * Save the current configuration file. */ diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index c8c3e0a8..ec800646 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -136,6 +136,13 @@ public class ProtocolLibrary extends JavaPlugin { protocolManager = new PacketFilterManager(getClassLoader(), getServer(), unhookTask, detailedReporter); detailedReporter.addGlobalParameter("manager", protocolManager); + // Update injection hook + try { + protocolManager.setPlayerHook(config.getInjectionMethod()); + } catch (IllegalArgumentException e) { + detailedReporter.reportWarning(config, "Cannot parse injection method. Using default.", e); + } + // Initialize command handlers commandProtocol = new CommandProtocol(detailedReporter, this, updater, config); commandPacket = new CommandPacket(detailedReporter, this, logger, protocolManager); diff --git a/ProtocolLib/src/main/resources/config.yml b/ProtocolLib/src/main/resources/config.yml index 32f4e4c3..e3c48aff 100644 --- a/ProtocolLib/src/main/resources/config.yml +++ b/ProtocolLib/src/main/resources/config.yml @@ -15,4 +15,8 @@ global: background compiler: true # Disable version checking for the given Minecraft version. Backup your world first! - ignore version check: \ No newline at end of file + ignore version check: + + # Override the starting injecting method + injection method: + \ No newline at end of file