Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Protocollib 5.0.0 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.8.0</version>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.injector.netty.ChannelListener;
import com.comphenix.protocol.injector.netty.InjectionFactory;
import com.comphenix.protocol.injector.netty.Injector;
import com.comphenix.protocol.injector.netty.ProtocolInjector;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.injector.netty.channel.InjectionFactory;
import com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector;
import com.comphenix.protocol.injector.temporary.TemporaryPlayerFactory;
import com.comphenix.protocol.reflect.FuzzyReflection;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import net.andylizi.haproxydetector.HAProxyDetectorHandler;
import net.andylizi.haproxydetector.ReflectionUtil;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

Expand All @@ -24,7 +26,7 @@ public class InjectionStrategy1 implements InjectionStrategy {
private final Logger logger;

private Field injectorFactoryField;
private ProtocolInjector injector;
private NetworkManagerInjector injector;
private InjectionFactory oldFactory;

public InjectionStrategy1(Logger logger) {this.logger = logger;}
Expand All @@ -38,16 +40,16 @@ public void inject() throws ReflectiveOperationException {

ProtocolManager pm = ProtocolLibrary.getProtocolManager();
Field injectorField = FuzzyReflection.fromObject(pm, true)
.getFieldByType("nettyInjector", ProtocolInjector.class);
.getFieldByType("nettyInjector", NetworkManagerInjector.class);
injectorField.setAccessible(true);
injector = (ProtocolInjector) injectorField.get(pm);
injector = (NetworkManagerInjector) injectorField.get(pm);

injectorFactoryField = FuzzyReflection.fromObject(injector, true)
.getFieldByType("factory", InjectionFactory.class);
injectorFactoryField.setAccessible(true);

oldFactory = (InjectionFactory) injectorFactoryField.get(injector);
InjectionFactory newFactory = new HAProxyInjectorFactory(oldFactory.getPlugin());
InjectionFactory newFactory = new HAProxyInjectorFactory(oldFactory.getPlugin(), oldFactory.getPlugin().getServer(), injector.getReporter());
ReflectionUtil.copyState(InjectionFactory.class, oldFactory, newFactory);
injectorFactoryField.set(injector, newFactory);
}
Expand All @@ -63,8 +65,8 @@ public void uninject() throws ReflectiveOperationException {
}

static class HAProxyInjectorFactory extends InjectionFactory {
public HAProxyInjectorFactory(Plugin plugin) {
super(plugin);
public HAProxyInjectorFactory(Plugin plugin, Server server, ErrorReporter errorReporter ) {
super(plugin, server, errorReporter);
}

@Override
Expand Down