/** * Determine if this workaround is required. * * @return TRUE if we must use this workaround, FALSE otherwise. */ public static boolean isRequired() { Boolean result = IS_REQUIRED; if (result != null) { return result; } try { // Used to check if custom NBT data survives the round trip NbtCompound proof = NbtFactory.ofCompound("", Collections.singletonList(NbtFactory.of("value", "TEST"))); ItemStack source = new ItemStack(Material.IRON_AXE); ItemStack stored = CompoundStore.getNativeStore(source, "com.comphenix.test").saveCompound(proof); StreamSerializer rawSerializer = new StreamSerializer(); SpigotSafeSerializer safeSerializer = new SpigotSafeSerializer(); // We are testing the raw serializer here ItemStack roundTrip = safeSerializer.deserializeItemStack(rawSerializer.serializeItemStack(stored)); NbtCompound extracted = CompoundStore.getNativeStore(roundTrip, "com.comphenix.test").loadCompound(); // Did it survive unscathed? result = !Objects.equal(proof, extracted); IS_REQUIRED = result; return result; } catch (IOException e) { throw new RuntimeException("Unexpected error during round trip test.", e); } }