From c38953dda8b499cb12275f437c2e6368c263b62d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 19 Sep 2022 21:43:51 +1000 Subject: [PATCH] SPIGOT-7160: LootTable.fillInventory() is not considered a plugin-issued event By: Doc --- .../main/java/org/bukkit/craftbukkit/CraftLootTable.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java index 2c47b3c4ec..b8b6036bdd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit; +import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -42,6 +43,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { @Override public Collection populateLoot(Random random, LootContext context) { + Preconditions.checkArgument(context != null, "LootContext cannot be null"); LootTableInfo nmsContext = convertContext(context, random); List nmsItems = handle.getRandomItems(nmsContext); Collection bukkit = new ArrayList<>(nmsItems.size()); @@ -58,12 +60,14 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { @Override public void fillInventory(Inventory inventory, Random random, LootContext context) { + Preconditions.checkArgument(inventory != null, "Inventory cannot be null"); + Preconditions.checkArgument(context != null, "LootContext cannot be null"); LootTableInfo nmsContext = convertContext(context, random); CraftInventory craftInventory = (CraftInventory) inventory; IInventory handle = craftInventory.getInventory(); // TODO: When events are added, call event here w/ custom reason? - getHandle().fill(handle, nmsContext); + getHandle().fillInventory(handle, nmsContext, true); } @Override @@ -72,7 +76,9 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { } private LootTableInfo convertContext(LootContext context, Random random) { + Preconditions.checkArgument(context != null, "LootContext cannot be null"); Location loc = context.getLocation(); + Preconditions.checkArgument(loc.getWorld() != null, "LootContext.getLocation#getWorld cannot be null"); WorldServer handle = ((CraftWorld) loc.getWorld()).getHandle(); LootTableInfo.Builder builder = new LootTableInfo.Builder(handle);