Fix 1.9.4+ support and also fix sponge support to work better.

Tested on SpongeVanilla + SpongeForge
(1.8.8 & 1.9.4)
This commit is contained in:
Myles 2016-09-26 13:11:46 +01:00
parent 8396c5a3e3
commit 14daca5fea
6 changed files with 23 additions and 54 deletions

View File

@ -4,4 +4,5 @@ Stop using new Gson() everywhere
Java docs (for platforms etc)
Config implementation for sponge
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.

View File

@ -24,6 +24,8 @@ public class BukkitViaBulkChunkTranslator extends BulkChunkTranslatorProvider {
if (((ViaVersionPlugin) Via.getPlatform()).isSpigot()) {
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) {
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to initialise chunks reflection", e);
}

View File

@ -30,7 +30,7 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
try {
idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Couldn't find idle packet, help!", e);
return; // We'll hope this is 1.9.4+
}
try {
idlePacket = idlePacketClass.newInstance();
@ -66,11 +66,15 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
@Override
public Object getFlyingPacket() {
if (idlePacket == null)
throw new NullPointerException("Could not locate flying packet");
return idlePacket2;
}
@Override
public Object getGroundPacket() {
if (idlePacket == null)
throw new NullPointerException("Could not locate flying packet");
return idlePacket;
}

View File

@ -4,6 +4,8 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
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.Via;
import us.myles.ViaVersion.api.platform.ViaInjector;
@ -118,64 +120,17 @@ public class SpongeViaInjector implements ViaInjector {
}
public static Object getServer() throws Exception {
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
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!");
return Sponge.getServer();
}
@Override
public int getServerProtocolVersion() throws Exception {
MinecraftVersion mcv = Sponge.getPlatform().getMinecraftVersion();
try {
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
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;
}
}
}
return (int) mcv.getClass().getDeclaredMethod("getProtocol").invoke(mcv);
} 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 {

View File

@ -15,9 +15,12 @@ public class SpongeViaBulkChunkTranslator extends BulkChunkTranslatorProvider {
private static ReflectionUtil.ClassReflection mapChunkRef;
static {
try {
mapChunkBulkRef = new ReflectionUtil.ClassReflection(Class.forName("net.minecraft.network.play.server.S26PacketMapChunkBulk"));
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) {
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to initialise chunks reflection", e);
}

View File

@ -14,7 +14,7 @@ public class SpongeViaMovementTransmitter extends MovementTransmitterProvider {
try {
idlePacketClass = Class.forName("net.minecraft.network.play.client.C03PacketPlayer");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Couldn't find idle packet, help!", e);
return; // We'll hope this is 1.9.4+
}
try {
idlePacket = idlePacketClass.newInstance();
@ -31,11 +31,15 @@ public class SpongeViaMovementTransmitter extends MovementTransmitterProvider {
@Override
public Object getFlyingPacket() {
if (idlePacket == null)
throw new NullPointerException("Could not locate flying packet");
return idlePacket2;
}
@Override
public Object getGroundPacket() {
if (idlePacket == null)
throw new NullPointerException("Could not locate flying packet");
return idlePacket;
}
}