Fixed dummy connection objects being private causing reflection-access to not work (#28)

This commit is contained in:
OmerBenGera 2021-10-15 17:59:53 +03:00
parent cebeae9690
commit a787fdd72a
6 changed files with 122 additions and 62 deletions

View File

@ -69,7 +69,21 @@ public final class ChunkLoaderNPC_v1_12_R1 extends EntityPlayer implements Chunk
return false;
}
private static class DummyNetworkManager extends NetworkManager{
public static class DummyNetworkManager extends NetworkManager{
private static Field channelField;
private static Field socketAddressField;
static {
try {
channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
} catch (Exception error) {
error.printStackTrace();
}
}
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
@ -78,23 +92,21 @@ public final class ChunkLoaderNPC_v1_12_R1 extends EntityPlayer implements Chunk
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
if (channelField != null) {
channelField.set(this, new DummyChannel());
}
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
if (socketAddressField != null) {
socketAddressField.set(this, null);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
public static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);

View File

@ -71,7 +71,21 @@ public final class ChunkLoaderNPC_v1_15_R1 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
private static class DummyNetworkManager extends NetworkManager{
public static class DummyNetworkManager extends NetworkManager{
private static Field channelField;
private static Field socketAddressField;
static {
try {
channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
} catch (Exception error) {
error.printStackTrace();
}
}
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
@ -80,23 +94,21 @@ public final class ChunkLoaderNPC_v1_15_R1 extends EntityPlayer implements Chunk
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
if (channelField != null) {
channelField.set(this, new DummyChannel());
}
Field socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
if (socketAddressField != null) {
socketAddressField.set(this, null);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
public static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);

View File

@ -82,7 +82,21 @@ public final class ChunkLoaderNPC_v1_16_R3 extends EntityPlayer implements Chunk
entityPlayer.shouldBeRemoved = true;
}
private static class DummyNetworkManager extends NetworkManager{
public static class DummyNetworkManager extends NetworkManager{
private static Field channelField;
private static Field socketAddressField;
static {
try {
channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
} catch (Exception error) {
error.printStackTrace();
}
}
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
@ -91,23 +105,21 @@ public final class ChunkLoaderNPC_v1_16_R3 extends EntityPlayer implements Chunk
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
if (channelField != null) {
channelField.set(this, new DummyChannel());
}
Field socketAddressField = NetworkManager.class.getDeclaredField("socketAddress");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
if (socketAddressField != null) {
socketAddressField.set(this, null);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
public static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);

View File

@ -76,7 +76,7 @@ public final class ChunkLoaderNPC_v1_17_R1 extends EntityPlayer implements Chunk
worldServer.a(entityPlayer, RemovalReason.d);
}
private static class DummyNetworkManager extends NetworkManager {
public static class DummyNetworkManager extends NetworkManager {
DummyNetworkManager(){
super(EnumProtocolDirection.a);
@ -86,7 +86,7 @@ public final class ChunkLoaderNPC_v1_17_R1 extends EntityPlayer implements Chunk
}
private static class DummyPlayerConnection extends PlayerConnection {
public static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);

View File

@ -71,7 +71,21 @@ public final class ChunkLoaderNPC_v1_7_R4 extends EntityPlayer implements ChunkL
return false;
}
private static class DummyNetworkManager extends NetworkManager {
public static class DummyNetworkManager extends NetworkManager {
private static Field channelField;
private static Field socketAddressField;
static {
try {
channelField = NetworkManager.class.getDeclaredField("m");
channelField.setAccessible(true);
socketAddressField = NetworkManager.class.getDeclaredField("n");
socketAddressField.setAccessible(true);
} catch (Exception error) {
error.printStackTrace();
}
}
DummyNetworkManager(){
super(false);
@ -80,23 +94,21 @@ public final class ChunkLoaderNPC_v1_7_R4 extends EntityPlayer implements ChunkL
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("m");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
if (channelField != null) {
channelField.set(this, new DummyChannel());
}
Field socketAddressField = NetworkManager.class.getDeclaredField("n");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
if (socketAddressField != null) {
socketAddressField.set(this, null);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
public static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);

View File

@ -71,7 +71,21 @@ public final class ChunkLoaderNPC_v1_8_R3 extends EntityPlayer implements ChunkL
return false;
}
private static class DummyNetworkManager extends NetworkManager{
public static class DummyNetworkManager extends NetworkManager {
private static Field channelField;
private static Field socketAddressField;
static {
try {
channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
} catch (Exception error) {
error.printStackTrace();
}
}
DummyNetworkManager(){
super(EnumProtocolDirection.SERVERBOUND);
@ -80,23 +94,21 @@ public final class ChunkLoaderNPC_v1_8_R3 extends EntityPlayer implements ChunkL
private void updateFields() {
try {
Field channelField = NetworkManager.class.getDeclaredField("channel");
channelField.setAccessible(true);
channelField.set(this, new DummyChannel());
channelField.setAccessible(false);
if (channelField != null) {
channelField.set(this, new DummyChannel());
}
Field socketAddressField = NetworkManager.class.getDeclaredField("l");
socketAddressField.setAccessible(true);
socketAddressField.set(this, null);
}
catch (NoSuchFieldException|SecurityException|IllegalArgumentException|IllegalAccessException e) {
e.printStackTrace();
if (socketAddressField != null) {
socketAddressField.set(this, null);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
private static class DummyPlayerConnection extends PlayerConnection {
public static class DummyPlayerConnection extends PlayerConnection {
DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) {
super(minecraftServer, new DummyNetworkManager(), entityPlayer);