SPIGOT-7160: LootTable.fillInventory() is not considered a plugin-issued event

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot 2022-09-19 21:43:51 +10:00
parent c397b790df
commit c38953dda8

View file

@ -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<ItemStack> populateLoot(Random random, LootContext context) {
Preconditions.checkArgument(context != null, "LootContext cannot be null");
LootTableInfo nmsContext = convertContext(context, random);
List<net.minecraft.world.item.ItemStack> nmsItems = handle.getRandomItems(nmsContext);
Collection<ItemStack> 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);