Archiviert
13
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Dan Mulloy 2018-07-09 22:31:23 -04:00
Commit c9dd6e2ba7
4 geänderte Dateien mit 280 neuen und 258 gelöschten Zeilen

Datei anzeigen

@ -158,7 +158,7 @@ public class WirePacket {
* bytes from that packet
*
* @param packet Existing packet
* @return The ByteBuf
* @return the byte array
*/
public static byte[] bytesFromPacket(PacketContainer packet) {
checkNotNull(packet, "packet cannot be null!");
@ -177,6 +177,8 @@ public class WirePacket {
byte[] bytes = getBytes(buffer);
buffer.release();
// Rewrite them to the packet to avoid issues with certain packets
if (packet.getType() == PacketType.Play.Server.CUSTOM_PAYLOAD
|| packet.getType() == PacketType.Play.Client.CUSTOM_PAYLOAD) {
@ -195,6 +197,8 @@ public class WirePacket {
return ret;
}
store.release();
return bytes;
}
@ -220,7 +224,11 @@ public class WirePacket {
throw new RuntimeException("Failed to serialize packet contents.", ex);
}
return new WirePacket(id, getBytes(buffer));
byte[] bytes = getBytes(buffer);
buffer.release();
return new WirePacket(id, bytes);
}
public static void writeVarInt(ByteBuf output, int i) {

Datei anzeigen

@ -1852,7 +1852,7 @@ public class MinecraftReflection {
}
// ---- ItemStack conversions
private static Object itemStackAir = null;
private static Method asNMSCopy = null;
private static Method asCraftMirror = null;
@ -1943,7 +1943,16 @@ public class MinecraftReflection {
if (is(getCraftItemStackClass(), specific)) {
// If it's already a CraftItemStack, use its handle
return new BukkitUnwrapper().unwrapItem(specific);
Object unwrapped = new BukkitUnwrapper().unwrapItem(specific);
if (unwrapped != null) {
return unwrapped;
} else {
if (itemStackAir == null) {
// Easiest way to get the Material.AIR ItemStack?
itemStackAir = getMinecraftItemStack(new ItemStack(Material.AIR));
}
return itemStackAir;
}
}
try {

Datei anzeigen

@ -1,6 +1,7 @@
package com.comphenix.protocol.utility;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -20,6 +21,7 @@ import net.minecraft.server.v1_12_R1.ServerPing.ServerPingPlayerSample;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.junit.AfterClass;
@ -137,6 +139,9 @@ public class MinecraftReflectionTest {
ItemStack stack = new ItemStack(Material.GOLD_SWORD);
Object nmsStack = MinecraftReflection.getMinecraftItemStack(stack);
assertEquals(stack, MinecraftReflection.getBukkitItemStack(nmsStack));
// The NMS handle for CraftItemStack is null with Material.AIR, make sure it is handled correctly
assertNotNull(MinecraftReflection.getMinecraftItemStack(CraftItemStack.asCraftCopy(new ItemStack(Material.AIR))));
}
@Test