Fixed protocol injection with latest netty on minecraft 1.11 and below (#1067)
This commit is contained in:
parent
7ce3f471bf
commit
0c01a11755
|
@ -38,6 +38,7 @@ import com.comphenix.protocol.updater.Updater;
|
||||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||||
import com.comphenix.protocol.utility.ChatExtensions;
|
import com.comphenix.protocol.utility.ChatExtensions;
|
||||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||||
|
import com.comphenix.protocol.utility.NettyVersion;
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
@ -170,7 +171,11 @@ public class ProtocolLib extends JavaPlugin {
|
||||||
// Print the state of the debug mode
|
// Print the state of the debug mode
|
||||||
if (config.isDebug()) {
|
if (config.isDebug()) {
|
||||||
logger.warning("Debug mode is enabled!");
|
logger.warning("Debug mode is enabled!");
|
||||||
|
logger.info("Detected netty version: " + NettyVersion.getVersion());
|
||||||
|
} else {
|
||||||
|
NettyVersion.getVersion(); // this will cache the version
|
||||||
}
|
}
|
||||||
|
|
||||||
// And the state of the error reporter
|
// And the state of the error reporter
|
||||||
if (config.isDetailedErrorReporting()) {
|
if (config.isDetailedErrorReporting()) {
|
||||||
detailedReporter.setDetailedReporting(true);
|
detailedReporter.setDetailedReporting(true);
|
||||||
|
|
|
@ -46,6 +46,7 @@ import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
|
||||||
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
|
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
|
||||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||||
import com.comphenix.protocol.reflect.VolatileField;
|
import com.comphenix.protocol.reflect.VolatileField;
|
||||||
|
import com.comphenix.protocol.utility.NettyVersion;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -146,10 +147,15 @@ public class ProtocolInjector implements ChannelListener {
|
||||||
protected void initChannel(final Channel channel) throws Exception {
|
protected void initChannel(final Channel channel) throws Exception {
|
||||||
try {
|
try {
|
||||||
synchronized (networkManagers) {
|
synchronized (networkManagers) {
|
||||||
// For some reason it needs to be delayed on 1.12, but the delay breaks 1.11 and below
|
// For some reason it needs to be delayed when using netty 4.1.24 (minecraft 1.12) or newer,
|
||||||
|
// but the delay breaks older minecraft versions
|
||||||
// TODO I see this more as a temporary hotfix than a permanent solution
|
// TODO I see this more as a temporary hotfix than a permanent solution
|
||||||
if (MinecraftVersion.getCurrentVersion().getMinor() >= 12) {
|
|
||||||
channel.eventLoop().submit(() ->
|
// Check if the netty version is greater than 4.1.24, that's the version bundled with spigot 1.12
|
||||||
|
NettyVersion ver = NettyVersion.getVersion();
|
||||||
|
if ((ver.isValid() && ver.isGreaterThan(4,1,24)) ||
|
||||||
|
MinecraftVersion.getCurrentVersion().getMinor() >= 12) { // fallback if netty version couldn't be detected
|
||||||
|
channel.eventLoop().submit(() ->
|
||||||
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject());
|
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject());
|
||||||
} else {
|
} else {
|
||||||
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject();
|
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject();
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package com.comphenix.protocol.utility;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import io.netty.util.Version;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NettyVersion {
|
||||||
|
private final static String NETTY_ARTIFACT_ID = "netty-common";
|
||||||
|
private static NettyVersion version;
|
||||||
|
|
||||||
|
public static NettyVersion getVersion() {
|
||||||
|
if(version == null) {
|
||||||
|
version = detectVersion();
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NettyVersion detectVersion() {
|
||||||
|
Map<String, Version> nettyArtifacts = Version.identify();
|
||||||
|
Version version = nettyArtifacts.get(NETTY_ARTIFACT_ID);
|
||||||
|
if(version != null) {
|
||||||
|
return new NettyVersion(version.artifactVersion());
|
||||||
|
}
|
||||||
|
return new NettyVersion(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean valid = false;
|
||||||
|
private int major, minor, revision;
|
||||||
|
|
||||||
|
public NettyVersion(String s) {
|
||||||
|
if(s == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String[] split = s.split( "\\.");
|
||||||
|
try {
|
||||||
|
this.major = Integer.parseInt(split[0]);
|
||||||
|
this.minor = Integer.parseInt(split[1]);
|
||||||
|
this.revision = Integer.parseInt(split[2]);
|
||||||
|
this.valid = true;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
ProtocolLibrary.getPlugin().getLogger().warning("Could not detect netty version: '" + s + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if(!valid) {
|
||||||
|
return "(invalid)";
|
||||||
|
}
|
||||||
|
return major + "." + minor + "." + revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(!(obj instanceof NettyVersion)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
NettyVersion v = (NettyVersion) obj;
|
||||||
|
return v.major == major && v.minor == minor && v.revision == revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMajor() {
|
||||||
|
return major;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinor() {
|
||||||
|
return minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRevision() {
|
||||||
|
return revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return this.valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGreaterThan(int major, int minor, int rev) {
|
||||||
|
return this.major > major || this.minor > minor || this.revision > rev;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue