withType(
- GameProfile.class, BukkitConverters.getWrappedGameProfileConverter());
+ MinecraftReflection.getGameProfileClass(), BukkitConverters.getWrappedGameProfileConverter());
}
/**
@@ -930,12 +928,11 @@ public class PacketContainer implements Serializable {
try {
if (MinecraftReflection.isUsingNetty()) {
- ByteBuf buffer = createPacketBuffer();
- MinecraftMethods.getPacketWriteByteBufMethod().invoke(handle, buffer);
-
+ WrappedByteBuf buffer = createPacketBuffer();
+ MinecraftMethods.getPacketWriteByteBufMethod().invoke(handle, buffer.getHandle());
+
output.writeInt(buffer.readableBytes());
buffer.readBytes(output, buffer.readableBytes());
-
} else {
// Call the write-method
output.writeInt(-1);
@@ -968,10 +965,10 @@ public class PacketContainer implements Serializable {
// Call the read method
try {
if (MinecraftReflection.isUsingNetty()) {
- ByteBuf buffer = createPacketBuffer();
+ WrappedByteBuf buffer = createPacketBuffer();
buffer.writeBytes(input, input.readInt());
- MinecraftMethods.getPacketReadByteBufMethod().invoke(handle, buffer);
+ MinecraftMethods.getPacketReadByteBufMethod().invoke(handle, buffer.getHandle());
} else {
if (input.readInt() != -1)
throw new IllegalArgumentException("Cannot load a packet from 1.7.2 in 1.6.4.");
@@ -996,8 +993,8 @@ public class PacketContainer implements Serializable {
* Construct a new packet data serializer.
* @return The packet data serializer.
*/
- private ByteBuf createPacketBuffer() {
- return MinecraftReflection.getPacketDataSerializer(UnpooledByteBufAllocator.DEFAULT.buffer());
+ private WrappedByteBuf createPacketBuffer() {
+ return Netty.createPacketBuffer();
}
// ---- Metadata
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java
index 9f7c0582..16c358ca 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java
@@ -17,8 +17,6 @@
package com.comphenix.protocol.injector;
-import io.netty.channel.Channel;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
@@ -56,6 +54,9 @@ import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.async.AsyncFilterManager;
import com.comphenix.protocol.async.AsyncMarker;
+import com.comphenix.protocol.compat.netty.Netty;
+import com.comphenix.protocol.compat.netty.ProtocolInjector;
+import com.comphenix.protocol.compat.netty.WrappedChannel;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
@@ -68,7 +69,6 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.events.PacketListener;
-import com.comphenix.protocol.injector.netty.NettyProtocolInjector;
import com.comphenix.protocol.injector.netty.WirePacket;
import com.comphenix.protocol.injector.packet.InterceptWritePacket;
import com.comphenix.protocol.injector.packet.PacketInjector;
@@ -205,7 +205,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
private SpigotPacketInjector spigotInjector;
// Netty injector (for 1.7.2)
- private NettyProtocolInjector nettyInjector;
+ private ProtocolInjector nettyInjector;
// Plugin verifier
private PluginVerifier pluginVerifier;
@@ -273,7 +273,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// Use the correct injection type
if (MinecraftReflection.isUsingNetty()) {
- this.nettyInjector = new NettyProtocolInjector(builder.getLibrary(), this, reporter);
+ this.nettyInjector = Netty.getProtocolInjector(builder.getLibrary(), this, reporter);
this.playerInjection = nettyInjector.getPlayerInjector();
this.packetInjector = nettyInjector.getPacketInjector();
@@ -845,7 +845,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
@Override
public void sendWirePacket(Player receiver, WirePacket packet) throws InvocationTargetException {
- Channel channel = playerInjection.getChannel(receiver);
+ WrappedChannel channel = playerInjection.getChannel(receiver);
if (channel == null) {
throw new InvocationTargetException(new NullPointerException(), "Failed to obtain channel for " + receiver.getName());
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelListener.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelListener.java
index e0ecd05f..aaf724e6 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelListener.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelListener.java
@@ -4,12 +4,11 @@ import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketEvent;
-
/**
* Represents a listener for received or sent packets.
* @author Kristian
*/
-interface ChannelListener {
+public interface ChannelListener {
/**
* Invoked when a packet is being sent to the client.
*
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ClosedInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ClosedInjector.java
index ad61d630..aff4055e 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ClosedInjector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ClosedInjector.java
@@ -9,7 +9,7 @@ import com.comphenix.protocol.events.NetworkMarker;
* Represents a closed injector.
* @author Kristian
*/
-class ClosedInjector implements Injector {
+public class ClosedInjector implements Injector {
private Player player;
/**
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/Injector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/Injector.java
index 81063bb6..c247397a 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/Injector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/Injector.java
@@ -9,7 +9,7 @@ import com.comphenix.protocol.events.NetworkMarker;
* Represents an injected client connection.
* @author Kristian
*/
-interface Injector {
+public interface Injector {
/**
* Retrieve the current protocol version of the player.
* @return Protocol version.
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyNetworkMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyNetworkMarker.java
index a67f9983..3241b258 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyNetworkMarker.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyNetworkMarker.java
@@ -10,7 +10,7 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.NetworkMarker;
-class NettyNetworkMarker extends NetworkMarker {
+public class NettyNetworkMarker extends NetworkMarker {
public NettyNetworkMarker(@Nonnull ConnectionSide side, byte[] inputBuffer) {
super(side, inputBuffer, null);
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/WirePacket.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/WirePacket.java
index 34f2102f..05adcf9b 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/WirePacket.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/WirePacket.java
@@ -16,7 +16,7 @@
*/
package com.comphenix.protocol.injector.netty;
-import io.netty.buffer.ByteBuf;
+import com.comphenix.protocol.compat.netty.WrappedByteBuf;
/**
* @author dmulloy2
@@ -39,7 +39,7 @@ public class WirePacket {
return bytes;
}
- public void writeId(ByteBuf output) {
+ public void writeId(WrappedByteBuf output) {
int i = id;
while ((i & -128) != 0) {
output.writeByte(i & 127 | 128);
@@ -49,7 +49,7 @@ public class WirePacket {
output.writeByte(i);
}
- public void writeBytes(ByteBuf output) {
+ public void writeBytes(WrappedByteBuf output) {
output.writeBytes(bytes);
}
}
\ No newline at end of file
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java
index a9c41387..06fdb7a2 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java
@@ -1,17 +1,15 @@
package com.comphenix.protocol.injector.packet;
-import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.ByteBuffer;
import javax.annotation.Nonnull;
import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.compat.guava.Guava;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.NetworkMarker;
-import com.google.common.io.ByteSource;
import com.google.common.primitives.Bytes;
/**
@@ -40,26 +38,6 @@ public class LegacyNetworkMarker extends NetworkMarker {
@Override
protected DataInputStream addHeader(final DataInputStream input, final PacketType type) {
- ByteSource header = new ByteSource() {
- @Override
- public InputStream openStream() throws IOException {
- byte[] data = new byte[] { (byte) type.getLegacyId() };
- return new ByteArrayInputStream(data);
- }
- };
-
- ByteSource data = new ByteSource() {
- @Override
- public InputStream openStream() throws IOException {
- return input;
- }
- };
-
- // Combine them into a single stream
- try {
- return new DataInputStream(ByteSource.concat(header, data).openStream());
- } catch (IOException e) {
- throw new RuntimeException("Cannot add header.", e);
- }
+ return Guava.addHeader(input, type);
}
-}
+}
\ No newline at end of file
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java
index 11098470..49c23c32 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java
@@ -1,7 +1,5 @@
package com.comphenix.protocol.injector.player;
-import io.netty.channel.Channel;
-
import java.io.DataInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
@@ -11,6 +9,7 @@ import java.util.Set;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.compat.netty.WrappedChannel;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketContainer;
@@ -201,5 +200,5 @@ public interface PlayerInjectionHandler {
*/
public abstract boolean hasMainThreadListener(PacketType type);
- public abstract Channel getChannel(Player player);
+ public abstract WrappedChannel getChannel(Player player);
}
\ No newline at end of file
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java
index 4417bafe..f2f81676 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java
@@ -17,8 +17,6 @@
package com.comphenix.protocol.injector.player;
-import io.netty.channel.Channel;
-
import java.io.DataInputStream;
import java.io.InputStream;
import java.lang.ref.WeakReference;
@@ -39,6 +37,7 @@ import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.Packets;
+import com.comphenix.protocol.compat.netty.WrappedChannel;
import com.comphenix.protocol.concurrency.BlockingHashMap;
import com.comphenix.protocol.concurrency.IntegerSet;
import com.comphenix.protocol.error.ErrorReporter;
@@ -757,7 +756,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
}
@Override
- public Channel getChannel(Player player) {
+ public WrappedChannel getChannel(Player player) {
throw new UnsupportedOperationException();
}
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java
index 801fd84e..164428b3 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java
@@ -1,7 +1,5 @@
package com.comphenix.protocol.injector.spigot;
-import io.netty.channel.Channel;
-
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
@@ -9,6 +7,7 @@ import java.net.InetSocketAddress;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.compat.netty.WrappedChannel;
import com.comphenix.protocol.concurrency.PacketTypeSet;
import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketContainer;
@@ -86,7 +85,7 @@ class DummyPlayerHandler extends AbstractPlayerHandler {
}
@Override
- public Channel getChannel(Player player) {
+ public WrappedChannel getChannel(Player player) {
throw new UnsupportedOperationException();
}
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java
index 3a4845e7..af2d7d48 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java
@@ -1,10 +1,5 @@
package com.comphenix.protocol.utility;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.UnpooledByteBufAllocator;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.util.concurrent.GenericFutureListener;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
@@ -15,6 +10,7 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.compat.netty.Netty;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.FuzzyReflection;
@@ -98,7 +94,7 @@ public class MinecraftMethods {
public static Method getNetworkManagerHandleMethod() {
if (networkManagerHandle == null) {
networkManagerHandle = FuzzyReflection.fromClass(MinecraftReflection.getNetworkManagerClass(), true).
- getMethodByParameters("handle", MinecraftReflection.getPacketClass(), GenericFutureListener[].class);
+ getMethodByParameters("handle", MinecraftReflection.getPacketClass(), Netty.getGenericFutureListenerArray());
networkManagerHandle.setAccessible(true);
}
return networkManagerHandle;
@@ -113,7 +109,7 @@ public class MinecraftMethods {
public static Method getNetworkManagerReadPacketMethod() {
if (networkManagerPacketRead == null) {
networkManagerPacketRead = FuzzyReflection.fromClass(MinecraftReflection.getNetworkManagerClass(), true).
- getMethodByParameters("packetRead", ChannelHandlerContext.class, MinecraftReflection.getPacketClass());
+ getMethodByParameters("packetRead", Netty.getChannelHandlerContext(), MinecraftReflection.getPacketClass());
networkManagerPacketRead.setAccessible(true);
}
return networkManagerPacketRead;
@@ -177,8 +173,8 @@ public class MinecraftMethods {
// Create our proxy object
Object javaProxy = enhancer.create(
- new Class>[] { ByteBuf.class },
- new Object[] { UnpooledByteBufAllocator.DEFAULT.buffer() }
+ new Class>[] { MinecraftReflection.getByteBufClass() },
+ new Object[] { Netty.allocateUnpooled().getHandle() }
);
Object lookPacket = new PacketContainer(PacketType.Play.Client.CLOSE_WINDOW).getHandle();
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java
index 7a3d4bb8..f9ca4fab 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java
@@ -17,8 +17,6 @@
package com.comphenix.protocol.utility;
-import io.netty.buffer.ByteBuf;
-
import java.io.DataInputStream;
import java.io.DataOutput;
import java.lang.reflect.Array;
@@ -69,7 +67,6 @@ import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.comphenix.protocol.wrappers.nbt.NbtType;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
-import com.mojang.authlib.GameProfile;
/**
* Methods and constants specifically used in conjuction with reflecting Minecraft object.
@@ -571,6 +568,7 @@ public class MinecraftReflection {
/**
* Retrieve the GameProfile class in 1.7.2 and later.
+ *
* @return The game profile class.
* @throws IllegalStateException If we are running 1.6.4 or earlier.
*/
@@ -579,14 +577,18 @@ public class MinecraftReflection {
throw new IllegalStateException("GameProfile does not exist in version 1.6.4 and earlier.");
try {
- return GameProfile.class;
+ return getClass("com.mojang.authlib.GameProfile");
} catch (Throwable ex) {
- FuzzyReflection reflection = FuzzyReflection.fromClass(PacketType.Login.Client.START.getPacketClass(), true);
- FuzzyFieldContract contract = FuzzyFieldContract.newBuilder()
- .banModifier(Modifier.STATIC)
- .typeMatches(FuzzyMatchers.matchRegex("(.*)(GameProfile)", 1))
- .build();
- return reflection.getField(contract).getType();
+ try {
+ return getClass("net.minecraft.util.com.mojang.authlib.GameProfile");
+ } catch (Throwable ex1) {
+ FuzzyReflection reflection = FuzzyReflection.fromClass(PacketType.Login.Client.START.getPacketClass(), true);
+ FuzzyFieldContract contract = FuzzyFieldContract.newBuilder()
+ .banModifier(Modifier.STATIC)
+ .typeMatches(FuzzyMatchers.matchRegex("(.*)(GameProfile)", 1))
+ .build();
+ return reflection.getField(contract).getType();
+ }
}
}
@@ -663,10 +665,10 @@ public class MinecraftReflection {
if (isUsingNetty()) {
paketContract = FuzzyClassContract.newBuilder().
method(FuzzyMethodContract.newBuilder().
- parameterDerivedOf(ByteBuf.class).
+ parameterDerivedOf(getByteBufClass()).
returnTypeVoid()).
method(FuzzyMethodContract.newBuilder().
- parameterDerivedOf(ByteBuf.class, 0).
+ parameterDerivedOf(getByteBufClass(), 0).
parameterExactType(byte[].class, 1).
returnTypeVoid()).
build();
@@ -698,6 +700,14 @@ public class MinecraftReflection {
}
}
+ public static Class> getByteBufClass() {
+ try {
+ return getClass("io.netty.buffer.ByteBuf");
+ } catch (Throwable ex) {
+ return getClass("net.minecraft.util.io.netty.buffer.ByteBuf");
+ }
+ }
+
/**
* Retrieve the EnumProtocol class in 1.7.2.
* @return The Enum protocol class.
@@ -834,7 +844,7 @@ public class MinecraftReflection {
// Find a server ping object
AbstractFuzzyMatcher> serverPlayerContract = FuzzyClassContract.newBuilder().
constructor(FuzzyMethodContract.newBuilder().parameterExactArray(int.class, int.class)).
- field(FuzzyFieldContract.newBuilder().typeExact(GameProfile[].class)).
+ field(FuzzyFieldContract.newBuilder().typeExact(getArrayClass(getGameProfileClass()))).
build().
and(getMinecraftObjectMatcher());
@@ -1576,7 +1586,7 @@ public class MinecraftReflection {
Method method = FuzzyReflection.fromClass(packet).getMethod(
FuzzyMethodContract.newBuilder().
parameterCount(1).
- parameterDerivedOf(ByteBuf.class).
+ parameterDerivedOf(getByteBufClass()).
returnTypeVoid().
build()
);
@@ -1614,21 +1624,6 @@ public class MinecraftReflection {
}
}
- /**
- * Retrieve an instance of the packet data serializer wrapper.
- * @param buffer - the buffer.
- * @return The instance.
- */
- public static ByteBuf getPacketDataSerializer(ByteBuf buffer) {
- Class> packetSerializer = getPacketDataSerializerClass();
-
- try {
- return (ByteBuf) packetSerializer.getConstructor(ByteBuf.class).newInstance(buffer);
- } catch (Exception e) {
- throw new RuntimeException("Cannot construct packet serializer.", e);
- }
- }
-
/**
* Retrieve the NMS tile entity class.
* @return The tile entity class.
@@ -1923,4 +1918,19 @@ public class MinecraftReflection {
public static String getNetLoginHandlerName() {
return getNetLoginHandlerClass().getSimpleName();
}
+
+ /**
+ * Retrieve an instance of the packet data serializer wrapper.
+ * @param buffer - the buffer.
+ * @return The instance.
+ */
+ public static Object getPacketDataSerializer(Object buffer) {
+ Class> packetSerializer = getPacketDataSerializerClass();
+
+ try {
+ return packetSerializer.getConstructor(getByteBufClass()).newInstance(buffer);
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot construct packet serializer.", e);
+ }
+ }
}
\ No newline at end of file
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java
index 34fd9103..29fc1434 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java
@@ -13,6 +13,7 @@ import javax.annotation.Nonnull;
import org.bukkit.inventory.ItemStack;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
+import com.comphenix.protocol.compat.netty.Netty;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
@@ -109,7 +110,7 @@ public class StreamSerializer {
);
}
- nmsItem = READ_ITEM_METHOD.invoke(ByteBufAdapter.packetReader(input));
+ nmsItem = READ_ITEM_METHOD.invoke(Netty.packetReader(input).getHandle());
} else {
if (READ_ITEM_METHOD == null) {
READ_ITEM_METHOD = Accessors.getMethodAccessor(
@@ -153,7 +154,7 @@ public class StreamSerializer {
);
}
- nmsCompound = READ_NBT_METHOD.invoke(ByteBufAdapter.packetReader(input));
+ nmsCompound = READ_NBT_METHOD.invoke(Netty.packetReader(input).getHandle());
} else {
if (READ_NBT_METHOD == null) {
READ_NBT_METHOD = Accessors.getMethodAccessor(
@@ -206,7 +207,7 @@ public class StreamSerializer {
);
}
- return (String) READ_STRING_METHOD.invoke(ByteBufAdapter.packetReader(input), maximumLength);
+ return (String) READ_STRING_METHOD.invoke(Netty.packetReader(input).getHandle(), maximumLength);
} else {
if (READ_STRING_METHOD == null) {
READ_STRING_METHOD = Accessors.getMethodAccessor(
@@ -266,7 +267,7 @@ public class StreamSerializer {
);
}
- WRITE_ITEM_METHOD.invoke(ByteBufAdapter.packetWriter(output), nmsItem);
+ WRITE_ITEM_METHOD.invoke(Netty.packetWriter(output).getHandle(), nmsItem);
} else {
if (WRITE_ITEM_METHOD == null)
WRITE_ITEM_METHOD = Accessors.getMethodAccessor(
@@ -307,7 +308,7 @@ public class StreamSerializer {
);
}
- WRITE_NBT_METHOD.invoke(ByteBufAdapter.packetWriter(output), handle);
+ WRITE_NBT_METHOD.invoke(Netty.packetWriter(output).getHandle(), handle);
} else {
if (WRITE_NBT_METHOD == null) {
WRITE_NBT_METHOD = Accessors.getMethodAccessor(
@@ -348,7 +349,7 @@ public class StreamSerializer {
);
}
- WRITE_STRING_METHOD.invoke(ByteBufAdapter.packetWriter(output), text);
+ WRITE_STRING_METHOD.invoke(Netty.packetWriter(output).getHandle(), text);
} else {
if (WRITE_STRING_METHOD == null) {
WRITE_STRING_METHOD = Accessors.getMethodAccessor(
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java
index c574c2de..f42aa9b5 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java
@@ -1,10 +1,5 @@
package com.comphenix.protocol.wrappers;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.handler.codec.base64.Base64;
-import io.netty.util.IllegalReferenceCountException;
-
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
@@ -22,6 +17,8 @@ import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
+import com.comphenix.protocol.compat.netty.Netty;
+import com.comphenix.protocol.compat.netty.WrappedByteBuf;
import com.comphenix.protocol.injector.BukkitUnwrapper;
import com.comphenix.protocol.reflect.EquivalentConverter;
import com.comphenix.protocol.reflect.accessors.Accessors;
@@ -38,7 +35,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.io.ByteStreams;
-import com.mojang.authlib.GameProfile;
/**
* Represents a server ping packet data.
@@ -55,6 +51,9 @@ public class WrappedServerPing extends AbstractWrapper {
.build();
private static MinecraftVersion LAST_VERSION = MinecraftVersion.BOUNTIFUL_UPDATE;
+ private static Class> GAME_PROFILE = MinecraftReflection.getGameProfileClass();
+ private static Class> GAME_PROFILE_ARRAY = MinecraftReflection.getArrayClass(GAME_PROFILE);
+
// Server ping fields
private static Class> SERVER_PING = MinecraftReflection.getServerPingClass();
private static ConstructorAccessor SERVER_PING_CONSTRUCTOR = Accessors.getConstructorAccessor(SERVER_PING);
@@ -65,13 +64,13 @@ public class WrappedServerPing extends AbstractWrapper {
// For converting to the underlying array
private static EquivalentConverter> PROFILE_CONVERT =
- BukkitConverters.getArrayConverter(GameProfile.class, BukkitConverters.getWrappedGameProfileConverter());
+ BukkitConverters.getArrayConverter(GAME_PROFILE, BukkitConverters.getWrappedGameProfileConverter());
// Server ping player sample fields
private static Class> PLAYERS_CLASS = MinecraftReflection.getServerPingPlayerSampleClass();
private static ConstructorAccessor PLAYERS_CONSTRUCTOR = Accessors.getConstructorAccessor(PLAYERS_CLASS, int.class, int.class);
private static FieldAccessor[] PLAYERS_INTS = Accessors.getFieldAccessorArray(PLAYERS_CLASS, int.class, true);
- private static FieldAccessor PLAYERS_PROFILES = Accessors.getFieldAccessor(PLAYERS_CLASS, GameProfile[].class, true);
+ private static FieldAccessor PLAYERS_PROFILES = Accessors.getFieldAccessor(PLAYERS_CLASS, GAME_PROFILE_ARRAY, true);
private static FieldAccessor PLAYERS_MAXIMUM = PLAYERS_INTS[0];
private static FieldAccessor PLAYERS_ONLINE = PLAYERS_INTS[1];
@@ -91,7 +90,7 @@ public class WrappedServerPing extends AbstractWrapper {
// Get profile from player
private static FieldAccessor ENTITY_HUMAN_PROFILE = Accessors.getFieldAccessor(
- MinecraftReflection.getEntityPlayerClass().getSuperclass(), GameProfile.class, true);
+ MinecraftReflection.getEntityPlayerClass().getSuperclass(), GAME_PROFILE, true);
// Inner class
private Object players; // may be NULL
@@ -297,7 +296,7 @@ public class WrappedServerPing extends AbstractWrapper {
public void setPlayers(Iterable extends WrappedGameProfile> profile) {
if (players == null)
resetPlayers();
- PLAYERS_PROFILES.set(players, (profile != null) ? PROFILE_CONVERT.getGeneric(GameProfile[].class, profile) : null);
+ PLAYERS_PROFILES.set(players, (profile != null) ? PROFILE_CONVERT.getGeneric(GAME_PROFILE_ARRAY, profile) : null);
}
/**
@@ -308,9 +307,10 @@ public class WrappedServerPing extends AbstractWrapper {
List profiles = Lists.newArrayList();
for (Player player : players) {
- GameProfile profile = (GameProfile) ENTITY_HUMAN_PROFILE.get(BukkitUnwrapper.getInstance().unwrapItem(player));
+ Object profile = ENTITY_HUMAN_PROFILE.get(BukkitUnwrapper.getInstance().unwrapItem(player));
profiles.add(WrappedGameProfile.fromHandle(profile));
}
+
setPlayers(profiles);
}
@@ -438,7 +438,7 @@ public class WrappedServerPing extends AbstractWrapper {
return new EncodedCompressedImage("data:image/png;base64," + base64);
} catch (IllegalArgumentException e) {
// Remind the caller
- throw new IllegalReferenceCountException("Must be a pure base64 encoded string. Cannot be an encoded text.", e);
+ throw new IllegalArgumentException("Must be a pure base64 encoded string. Cannot be an encoded text.", e);
}
}
@@ -504,12 +504,9 @@ public class WrappedServerPing extends AbstractWrapper {
*/
public String toEncodedText() {
if (encoded == null) {
- final ByteBuf buffer = Unpooled.wrappedBuffer(getData());
- String computed = "data:" + mime + ";base64," +
- Base64.encode(buffer).toString(Charsets.UTF_8);
-
- encoded = computed;
+ encoded = Netty.toEncodedText(this);
}
+
return encoded;
}
}
@@ -541,7 +538,7 @@ public class WrappedServerPing extends AbstractWrapper {
this.mime = segment.substring(5);
} else if (segment.startsWith("base64,")) {
byte[] encoded = segment.substring(7).getBytes(Charsets.UTF_8);
- ByteBuf decoded = Base64.decode(Unpooled.wrappedBuffer(encoded));
+ WrappedByteBuf decoded = Netty.decode(encoded);
// Read into a byte array
byte[] data = new byte[decoded.readableBytes()];
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java
index bc478eda..b53687c0 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java
@@ -2,14 +2,43 @@ package com.comphenix.protocol.wrappers;
import java.security.PublicKey;
+import com.comphenix.protocol.reflect.accessors.Accessors;
+import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
+import com.comphenix.protocol.reflect.accessors.MethodAccessor;
import com.google.common.base.Objects;
-import com.mojang.authlib.properties.Property;
/**
* Represents a wrapper over a signed property.
* @author Kristian
*/
public class WrappedSignedProperty extends AbstractWrapper {
+ private static Class> PROPERTY;
+ private static ConstructorAccessor CONSTRUCTOR;
+ private static MethodAccessor GET_NAME;
+ private static MethodAccessor GET_SIGNATURE;
+ private static MethodAccessor GET_VALUE;
+ private static MethodAccessor HAS_SIGNATURE;
+ private static MethodAccessor IS_SIGNATURE_VALID;
+
+ static {
+ try {
+ PROPERTY = Class.forName("com.mojang.authlib.properties.Property");
+ } catch (ClassNotFoundException ex) {
+ try {
+ PROPERTY = Class.forName("net.minecraft.util.com.mojang.authlib.properties.Property");
+ } catch (ClassNotFoundException ex1) {
+ throw new RuntimeException("Failed to obtain Property class", ex);
+ }
+ }
+
+ CONSTRUCTOR = Accessors.getConstructorAccessor(PROPERTY, String.class, String.class, String.class);
+ GET_NAME = Accessors.getMethodAccessor(PROPERTY, "getName");
+ GET_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "getSignature");
+ GET_VALUE = Accessors.getMethodAccessor(PROPERTY, "getValue");
+ HAS_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "hasSignature");
+ IS_SIGNATURE_VALID = Accessors.getMethodAccessor(PROPERTY, "isSigntureValid", PublicKey.class);
+ }
+
/**
* Construct a new wrapped signed property from the given values.
* @param name - the name of the property.
@@ -17,7 +46,7 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @param signature - the BASE64-encoded signature of the value.
*/
public WrappedSignedProperty(String name, String value, String signature) {
- this(new Property(name, value, signature));
+ this(CONSTRUCTOR.invoke(name, value, signature));
}
/**
@@ -25,7 +54,7 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @param handle - the handle.
*/
private WrappedSignedProperty(Object handle) {
- super(Property.class);
+ super(PROPERTY);
setHandle(handle);
}
@@ -48,21 +77,13 @@ public class WrappedSignedProperty extends AbstractWrapper {
public static WrappedSignedProperty fromValues(String name, String value, String signature) {
return new WrappedSignedProperty(name, value, signature);
}
-
- /**
- * Retrieve the underlying signed property.
- * @return The GameProfile.
- */
- private Property getProfile() {
- return (Property) handle;
- }
/**
* Retrieve the name of the underlying property, such as "textures".
* @return Name of the property.
*/
public String getName() {
- return getProfile().getName();
+ return (String) GET_NAME.invoke(handle);
}
/**
@@ -70,7 +91,7 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @return The signature of the property.
*/
public String getSignature() {
- return getProfile().getSignature();
+ return (String) GET_SIGNATURE.invoke(handle);
}
/**
@@ -78,7 +99,7 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @return The value of the property.
*/
public String getValue() {
- return getProfile().getValue();
+ return (String) GET_VALUE.invoke(handle);
}
/**
@@ -86,7 +107,7 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @return TRUE if it does, FALSE otherwise.
*/
public boolean hasSignature() {
- return getProfile().hasSignature();
+ return (Boolean) HAS_SIGNATURE.invoke(handle);
}
/**
@@ -95,7 +116,7 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @return TRUE if it is, FALSE otherwise.
*/
public boolean isSignatureValid(PublicKey key) {
- return getProfile().isSignatureValid(key);
+ return (Boolean) IS_SIGNATURE_VALID.invoke(handle, key);
}
@Override