Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 13:52:50 +02:00
Make the injectors work in any 1.8 version. Now looks through fields for suitable in case of different field names also construct slot using known arguments.
Dieser Commit ist enthalten in:
Ursprung
c704b3709a
Commit
fee986d215
@ -12,12 +12,12 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.ViaVersionAPI;
|
import us.myles.ViaVersion.api.ViaVersionAPI;
|
||||||
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -33,7 +33,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
ViaVersion.setInstance(this);
|
ViaVersion.setInstance(this);
|
||||||
if(System.getProperty("ViaVersion") != null){
|
if (System.getProperty("ViaVersion") != null) {
|
||||||
getLogger().severe("ViaVersion is already loaded, we don't support reloads. Please reboot if you wish to update.");
|
getLogger().severe("ViaVersion is already loaded, we don't support reloads. Please reboot if you wish to update.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,18 +58,29 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
Class<?> serverClazz = ReflectionUtil.nms("MinecraftServer");
|
Class<?> serverClazz = ReflectionUtil.nms("MinecraftServer");
|
||||||
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
|
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
|
||||||
Object connection = serverClazz.getDeclaredMethod("getServerConnection").invoke(server);
|
Object connection = serverClazz.getDeclaredMethod("getServerConnection").invoke(server);
|
||||||
|
// loop through all fields checking if list
|
||||||
List<ChannelFuture> futures = ReflectionUtil.get(connection, "g", List.class);
|
boolean injected = false;
|
||||||
if (futures.size() == 0) {
|
for (Field field : connection.getClass().getDeclaredFields()) {
|
||||||
throw new Exception("Could not find server to inject (Please ensure late-bind in your spigot.yml is false)");
|
field.setAccessible(true);
|
||||||
|
Object value = field.get(connection);
|
||||||
|
if (value instanceof List) {
|
||||||
|
for (Object o : (List) value) {
|
||||||
|
if (o instanceof ChannelFuture) {
|
||||||
|
ChannelFuture future = (ChannelFuture) o;
|
||||||
|
ChannelPipeline pipeline = future.channel().pipeline();
|
||||||
|
ChannelHandler bootstrapAcceptor = pipeline.first();
|
||||||
|
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
|
||||||
|
ChannelInitializer newInit = new ViaVersionInitializer(oldInit);
|
||||||
|
ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit);
|
||||||
|
injected = true;
|
||||||
|
} else {
|
||||||
|
break; // not the right list.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!injected) {
|
||||||
for (ChannelFuture future : futures) {
|
throw new Exception("Could not find server to inject (Please ensure late-bind in your spigot.yml is false)");
|
||||||
ChannelPipeline pipeline = future.channel().pipeline();
|
|
||||||
ChannelHandler bootstrapAcceptor = pipeline.first();
|
|
||||||
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
|
|
||||||
ChannelInitializer newInit = new ViaVersionInitializer(oldInit);
|
|
||||||
ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import us.myles.ViaVersion.packets.State;
|
|||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@ -102,7 +103,9 @@ public class IncomingTransformer {
|
|||||||
if (slot == 45 && windowID == 0) {
|
if (slot == 45 && windowID == 0) {
|
||||||
try {
|
try {
|
||||||
Class<?> setSlot = ReflectionUtil.nms("PacketPlayOutSetSlot");
|
Class<?> setSlot = ReflectionUtil.nms("PacketPlayOutSetSlot");
|
||||||
Object setSlotPacket = setSlot.getConstructors()[1].newInstance(windowID, slot, null);
|
Constructor setSlotConstruct = setSlot.getDeclaredConstructor(int.class, int.class, ReflectionUtil.nms("ItemStack"));
|
||||||
|
// properly construct
|
||||||
|
Object setSlotPacket = setSlotConstruct.newInstance(windowID, slot, null);
|
||||||
info.getChannel().pipeline().writeAndFlush(setSlotPacket); // slot is empty
|
info.getChannel().pipeline().writeAndFlush(setSlotPacket); // slot is empty
|
||||||
slot = -999; // we're evil, they'll throw item on the ground
|
slot = -999; // we're evil, they'll throw item on the ground
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -113,6 +116,8 @@ public class IncomingTransformer {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class OutgoingTransformer {
|
|||||||
if (packet == null) {
|
if (packet == null) {
|
||||||
throw new RuntimeException("Outgoing Packet not found? " + packetID + " State: " + info.getState() + " Version: " + info.getProtocol());
|
throw new RuntimeException("Outgoing Packet not found? " + packetID + " State: " + info.getState() + " Version: " + info.getProtocol());
|
||||||
}
|
}
|
||||||
// if (packet != PacketType.PLAY_CHUNK_DATA && packet != PacketType.PLAY_KEEP_ALIVE && packet != PacketType.PLAY_TIME_UPDATE && (!packet.name().toLowerCase().contains("move") && !packet.name().contains("look")))
|
// if (packet != PacketType.PLAY_CHUNK_DATA && packet != PacketType.PLAY_KEEP_ALIVE && packet != PacketType.PLAY_TIME_UPDATE && (!packet.name().toLowerCase().contains("move") && !packet.name().toLowerCase().contains("look")))
|
||||||
// System.out.println("Packet Type: " + packet + " Original ID: " + packetID + " State:" + info.getState());
|
// System.out.println("Packet Type: " + packet + " Original ID: " + packetID + " State:" + info.getState());
|
||||||
if (packet.getPacketID() != -1) {
|
if (packet.getPacketID() != -1) {
|
||||||
packetID = packet.getNewPacketID();
|
packetID = packet.getNewPacketID();
|
||||||
@ -60,6 +60,7 @@ public class OutgoingTransformer {
|
|||||||
PacketUtil.writeVarInt(packetID, output);
|
PacketUtil.writeVarInt(packetID, output);
|
||||||
if (packet == PacketType.PLAY_NAMED_SOUND_EFFECT) {
|
if (packet == PacketType.PLAY_NAMED_SOUND_EFFECT) {
|
||||||
String name = PacketUtil.readString(input);
|
String name = PacketUtil.readString(input);
|
||||||
|
|
||||||
SoundEffect effect = SoundEffect.getByName(name);
|
SoundEffect effect = SoundEffect.getByName(name);
|
||||||
int catid = 0;
|
int catid = 0;
|
||||||
String newname = name;
|
String newname = name;
|
||||||
@ -511,7 +512,7 @@ public class OutgoingTransformer {
|
|||||||
output.writeBytes(input);
|
output.writeBytes(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String fixJson(String line) {
|
public static String fixJson(String line) {
|
||||||
if (line == null || line.equalsIgnoreCase("null")) {
|
if (line == null || line.equalsIgnoreCase("null")) {
|
||||||
line = "{\"text\":\"\"}";
|
line = "{\"text\":\"\"}";
|
||||||
} else {
|
} else {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren