From 02cd9d4ec0c9ee827ec95d7764434b79acbc6b4a Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Mon, 12 Apr 2021 16:08:03 +0100 Subject: [PATCH] Work around getItemMeta returning null in some cases (Fixes #432) --- .../Acrobot/Breeze/Utils/MaterialUtil.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java index 770f7b9..7464010 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java @@ -102,24 +102,41 @@ public class MaterialUtil { if (!one.hasItemMeta() && !two.hasItemMeta()) { return true; } - Map oneSerMeta = one.getItemMeta().serialize(); - Map twoSerMeta = two.getItemMeta().serialize(); + ItemMeta oneMeta = one.getItemMeta(); + ItemMeta twoMeta = two.getItemMeta(); + // return true if both are null or same, false if only one is null + if (oneMeta == twoMeta || oneMeta == null || twoMeta == null) { + return oneMeta == twoMeta; + } + Map oneSerMeta = oneMeta.serialize(); + Map twoSerMeta = twoMeta.serialize(); if (oneSerMeta.equals(twoSerMeta)) { return true; } // Try to use same parsing as the YAML dumper in the ItemDatabase when generating the code as the last resort ItemStack oneDumped = YAML.loadAs(YAML.dump(one), ItemStack.class); - if (oneDumped.isSimilar(two) || oneDumped.getItemMeta().serialize().equals(twoSerMeta)) { + if (oneDumped.isSimilar(two)) { + return true; + } + + ItemMeta oneDumpedMeta = oneDumped.getItemMeta(); + if (oneDumpedMeta != null && oneDumpedMeta.serialize().equals(twoSerMeta)) { return true; } ItemStack twoDumped = YAML.loadAs(YAML.dump(two), ItemStack.class); - if (oneDumped.isSimilar(twoDumped) || oneDumped.getItemMeta().serialize().equals(twoDumped.getItemMeta().serialize())) { + if (oneDumped.isSimilar(twoDumped)) { return true; } - return false; + ItemMeta twoDumpedMeta = twoDumped.getItemMeta(); + if (oneDumpedMeta != null && twoDumpedMeta != null && oneDumpedMeta.serialize().equals(twoDumpedMeta.serialize())) { + return true; + } + + // return true if both are null or same, false otherwise + return oneDumpedMeta == twoDumpedMeta; } /**