Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Fix 1.9.4+ support and also fix sponge support to work better.
Tested on SpongeVanilla + SpongeForge (1.8.8 & 1.9.4)
Dieser Commit ist enthalten in:
Ursprung
8396c5a3e3
Commit
14daca5fea
1
TODOLIST
1
TODOLIST
@ -5,3 +5,4 @@ Java docs (for platforms etc)
|
|||||||
Config implementation for sponge
|
Config implementation for sponge
|
||||||
Port bukkit listeners to sponge maybe
|
Port bukkit listeners to sponge maybe
|
||||||
Fix task ids, methods for sponge
|
Fix task ids, methods for sponge
|
||||||
|
Find all the TODO's and check they're done.
|
@ -24,6 +24,8 @@ public class BukkitViaBulkChunkTranslator extends BulkChunkTranslatorProvider {
|
|||||||
if (((ViaVersionPlugin) Via.getPlatform()).isSpigot()) {
|
if (((ViaVersionPlugin) Via.getPlatform()).isSpigot()) {
|
||||||
obfuscateRef = Class.forName("org.spigotmc.AntiXray").getMethod("obfuscate", int.class, int.class, int.class, byte[].class, ReflectionUtil.nms("World"));
|
obfuscateRef = Class.forName("org.spigotmc.AntiXray").getMethod("obfuscate", int.class, int.class, int.class, byte[].class, ReflectionUtil.nms("World"));
|
||||||
}
|
}
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// Ignore as server is probably 1.9+
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to initialise chunks reflection", e);
|
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to initialise chunks reflection", e);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
try {
|
try {
|
||||||
idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying");
|
idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException("Couldn't find idle packet, help!", e);
|
return; // We'll hope this is 1.9.4+
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
idlePacket = idlePacketClass.newInstance();
|
idlePacket = idlePacketClass.newInstance();
|
||||||
@ -66,11 +66,15 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getFlyingPacket() {
|
public Object getFlyingPacket() {
|
||||||
|
if (idlePacket == null)
|
||||||
|
throw new NullPointerException("Could not locate flying packet");
|
||||||
return idlePacket2;
|
return idlePacket2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGroundPacket() {
|
public Object getGroundPacket() {
|
||||||
|
if (idlePacket == null)
|
||||||
|
throw new NullPointerException("Could not locate flying packet");
|
||||||
return idlePacket;
|
return idlePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import io.netty.channel.ChannelFuture;
|
|||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
import org.spongepowered.api.MinecraftVersion;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||||
@ -118,64 +120,17 @@ public class SpongeViaInjector implements ViaInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object getServer() throws Exception {
|
public static Object getServer() throws Exception {
|
||||||
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
|
return Sponge.getServer();
|
||||||
for (Method m : serverClazz.getDeclaredMethods()) {
|
|
||||||
if (m.getParameterCount() == 0) {
|
|
||||||
if ((m.getModifiers() & Modifier.STATIC) == Modifier.STATIC) {
|
|
||||||
if (m.getReturnType().equals(serverClazz)) {
|
|
||||||
return m.invoke(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Exception("Could not find MinecraftServer static field!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws Exception {
|
public int getServerProtocolVersion() throws Exception {
|
||||||
|
MinecraftVersion mcv = Sponge.getPlatform().getMinecraftVersion();
|
||||||
try {
|
try {
|
||||||
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
|
return (int) mcv.getClass().getDeclaredMethod("getProtocol").invoke(mcv);
|
||||||
Object server = getServer();
|
|
||||||
Class<?> pingClazz = Class.forName("net.minecraft.network.ServerStatusResponse");
|
|
||||||
Object ping = null;
|
|
||||||
// Search for ping method
|
|
||||||
for (Field f : serverClazz.getDeclaredFields()) {
|
|
||||||
if (f.getType() != null) {
|
|
||||||
if (f.getType().getSimpleName().equals("ServerStatusResponse")) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
ping = f.get(server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ping != null) {
|
|
||||||
Object serverData = null;
|
|
||||||
for (Field f : pingClazz.getDeclaredFields()) {
|
|
||||||
if (f.getType() != null) {
|
|
||||||
if (f.getType().getSimpleName().endsWith("MinecraftProtocolVersionIdentifier")) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
serverData = f.get(ping);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (serverData != null) {
|
|
||||||
int protocolVersion = -1;
|
|
||||||
for (Field f : serverData.getClass().getDeclaredFields()) {
|
|
||||||
if (f.getType() != null) {
|
|
||||||
if (f.getType() == int.class) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
protocolVersion = (int) f.get(serverData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (protocolVersion != -1) {
|
|
||||||
return protocolVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("Failed to get server", e);
|
throw new Exception("Failed to get server protocol", e);
|
||||||
}
|
}
|
||||||
throw new Exception("Failed to get server");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getServerConnection() throws Exception {
|
public static Object getServerConnection() throws Exception {
|
||||||
|
@ -15,9 +15,12 @@ public class SpongeViaBulkChunkTranslator extends BulkChunkTranslatorProvider {
|
|||||||
private static ReflectionUtil.ClassReflection mapChunkRef;
|
private static ReflectionUtil.ClassReflection mapChunkRef;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapChunkBulkRef = new ReflectionUtil.ClassReflection(Class.forName("net.minecraft.network.play.server.S26PacketMapChunkBulk"));
|
mapChunkBulkRef = new ReflectionUtil.ClassReflection(Class.forName("net.minecraft.network.play.server.S26PacketMapChunkBulk"));
|
||||||
mapChunkRef = new ReflectionUtil.ClassReflection(Class.forName("net.minecraft.network.play.server.S21PacketChunkData"));
|
mapChunkRef = new ReflectionUtil.ClassReflection(Class.forName("net.minecraft.network.play.server.S21PacketChunkData"));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// Ignore as server is probably 1.9+
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to initialise chunks reflection", e);
|
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to initialise chunks reflection", e);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public class SpongeViaMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
try {
|
try {
|
||||||
idlePacketClass = Class.forName("net.minecraft.network.play.client.C03PacketPlayer");
|
idlePacketClass = Class.forName("net.minecraft.network.play.client.C03PacketPlayer");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException("Couldn't find idle packet, help!", e);
|
return; // We'll hope this is 1.9.4+
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
idlePacket = idlePacketClass.newInstance();
|
idlePacket = idlePacketClass.newInstance();
|
||||||
@ -31,11 +31,15 @@ public class SpongeViaMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getFlyingPacket() {
|
public Object getFlyingPacket() {
|
||||||
|
if (idlePacket == null)
|
||||||
|
throw new NullPointerException("Could not locate flying packet");
|
||||||
return idlePacket2;
|
return idlePacket2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGroundPacket() {
|
public Object getGroundPacket() {
|
||||||
|
if (idlePacket == null)
|
||||||
|
throw new NullPointerException("Could not locate flying packet");
|
||||||
return idlePacket;
|
return idlePacket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren