Fix crash from invalid ingredient lists in VillagerAcquireTradeEvent

This commit is contained in:
Shane Freeder 2020-12-27 11:31:06 +00:00
parent dad7e25da8
commit 5b7474984b

View file

@ -54,7 +54,7 @@
Logger logger = AbstractVillager.LOGGER; Logger logger = AbstractVillager.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -246,7 +266,16 @@ @@ -246,7 +266,20 @@
MerchantOffer merchantrecipe = ((VillagerTrades.ItemListing) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random); MerchantOffer merchantrecipe = ((VillagerTrades.ItemListing) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
if (merchantrecipe != null) { if (merchantrecipe != null) {
@ -66,7 +66,11 @@
+ Bukkit.getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event);
+ } + }
+ if (!event.isCancelled()) { + if (!event.isCancelled()) {
+ recipeList.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft()); + // Paper start - Fix crash from invalid ingredient list
+ final CraftMerchantRecipe craftMerchantRecipe = CraftMerchantRecipe.fromBukkit(event.getRecipe());
+ if (craftMerchantRecipe.getIngredients().isEmpty()) return;
+ recipeList.add(craftMerchantRecipe.toMinecraft());
+ // Paper end - Fix crash from invalid ingredient list
+ } + }
+ // CraftBukkit end + // CraftBukkit end
++j; ++j;