mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 17:52:28 +01:00
SPIGOT-7160: LootTable.fillInventory() is not considered a plugin-issued event
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
c397b790df
commit
c38953dda8
1 changed files with 7 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue