Making network manager

This commit is contained in:
Sekwah 2018-10-19 04:26:54 +01:00
parent 5078868fda
commit 70347779c2
3 changed files with 30 additions and 13 deletions

View File

@ -54,7 +54,7 @@ public class CraftBukkit {
this.plugin.getLogger().info("Bukkit version detected " + bukkitImpl);
Class<?> chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); // string to packet methods
Class<?> chatSerialClass = this.findClass(chatBaseComponent, "ChatSerializer");
Class<?> chatSerialClass = ReflectionHelper.findClass(chatBaseComponent, "ChatSerializer");
Class<?> chatMessageTypeClass = Class.forName(minecraftPackage + "ChatMessageType");
@ -92,7 +92,7 @@ public class CraftBukkit {
plugin.getLogger().warning("Attempting to use backup porekit locations");
// Fall back on your Porekit
Class<?> textBaseComponent = Class.forName("net.minecraft.util.text.ITextComponent"); // string to packet methods
this.serializeMessage = this.findClass(textBaseComponent, "Serializer").getMethod("func_150699_a", String.class); // md: jsonToComponent
this.serializeMessage = ReflectionHelper.findClass(textBaseComponent, "Serializer").getMethod("func_150699_a", String.class); // md: jsonToComponent
this.chatPacketConstructor = Class.forName("net.minecraft.network.play.server.SPacketChat").getConstructor(textBaseComponent, byte.class);
this.playerGetHandle = Class.forName("blue.lapis.pore.impl.entity.PorePlayer").getMethod("getHandle");
@ -125,16 +125,6 @@ public class CraftBukkit {
}
public Class<?> findClass(Class<?> classObj, String className){
for(Class<?> classes : classObj.getDeclaredClasses()){
if(classes.getSimpleName().equals(className)){
return classes;
}
}
return null;
}
/**
* Blocks the beacon from showing
* @param block

View File

@ -1,14 +1,32 @@
package com.sekwah.advancedportals.injector;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.reflection.ReflectionHelper;
import io.netty.channel.Channel;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class PacketInjector {
private Method getPlayerHandle;
private Field playerConnection;
private Field networkManager;
private Field networkChannel;
public PacketInjector(AdvancedPortalsPlugin plugin, String bukkitImpl) {
String craftBukkitPackage = "org.bukkit.craftbukkit." + bukkitImpl + ".";
String minecraftPackage = "net.minecraft.server." + bukkitImpl + ".";
try {
getPlayerHandle = Class.forName(craftBukkitPackage + "entity.CraftPlayer").getMethod("getHandle");
playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection");
networkManager = Class.forName(minecraftPackage + "PlayerConnection").getField("networkManager");
networkChannel = ReflectionHelper.getFieldByType(Class.forName(minecraftPackage + "NetworkManager"), Channel.class, true);
} catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException e) {
e.printStackTrace();
}
}
}

View File

@ -14,4 +14,13 @@ public class ReflectionHelper {
}
return null;
}
public static Class<?> findClass(Class<?> classObj, String className){
for(Class<?> classes : classObj.getDeclaredClasses()){
if(classes.getSimpleName().equals(className)){
return classes;
}
}
return null;
}
}