Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Exception throwing with World#dropItem(Location, ItemStack) #10

Open
flowerinsnowdh opened this issue Dec 17, 2023 · 0 comments
Open

Exception throwing with World#dropItem(Location, ItemStack) #10

flowerinsnowdh opened this issue Dec 17, 2023 · 0 comments

Comments

@flowerinsnowdh
Copy link

Code

package online.flowerinsnow.custommap.util;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public abstract class InventoryUtils {
    private InventoryUtils() {
    }

    /**
     * <p>获取物品栏剩余空闲位置</p>
     * @param inventory <p>物品栏</p>
     * @param maximumSlot <p>最大槽位</p>
     * @return <p>物品栏剩余空闲位置<p/>
     */
    public static int getInventoryFreeSlotCount(@NotNull Inventory inventory, int maximumSlot) {
        int freeSlotCount = 0;
        for (int i = 0; i < maximumSlot; i++) {
            @Nullable ItemStack itemStack = inventory.getItem(i);
            if (itemStack == null || itemStack.getType() == Material.AIR) {
                freeSlotCount++;
            }
        }
        return freeSlotCount;
    }

    /**
     * <p>给予玩家一堆物品,并将物品栏装不下的物品掉落在玩家脚下</p>
     * @param player <p>玩家</p>
     * @param itemStacks <p>给予玩家的一堆物品</p>
     */
    public static void addItemStacksOrDrop(@NotNull Player player, @NotNull Collection<ItemStack> itemStacks) {
        ItemStack[] itemStacksToAdd = new ItemStack[itemStacks.size()];
        itemStacksToAdd = itemStacks.toArray(itemStacksToAdd);
        Collection<ItemStack> unfitItems = player.getInventory().addItem(itemStacksToAdd).values();
        // 将多余的物品掉落在地上
        unfitItems.forEach(unfitItem -> player.getWorld().dropItem(player.getLocation(), unfitItem));
    }
}

unfitItems.forEach(unfitItem -> player.getWorld().dropItem(player.getLocation(), unfitItem)); was the line 43

Logging

[16:08:19 WARN]: [CustomMap22] Task #18910 for CustomMap22 v1.1.33 generated an exception
java.lang.NullPointerException: Cannot invoke "io.papermc.paper.threadedregions.ThreadedRegionizer$ThreadedRegion.getData()" because "target" is null
        at me.earthme.molia.pool.WorldDataPool.getDataOffTickThread(WorldDataPool.java:45) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at me.earthme.molia.pool.WorldDataPool.getDataAnyThread(WorldDataPool.java:22) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at net.minecraft.server.level.ServerLevel.addEntity(ServerLevel.java:1876) ~[?:?]
        at net.minecraft.server.level.ServerLevel.addFreshEntity(ServerLevel.java:1790) ~[?:?]
        at org.bukkit.craftbukkit.v1_20_R2.CraftWorld.dropItem(CraftWorld.java:714) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at org.bukkit.craftbukkit.v1_20_R2.CraftWorld.dropItem(CraftWorld.java:700) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at online.flowerinsnow.custommap.util.InventoryUtils.lambda$addItemStacksOrDrop$0(InventoryUtils.java:43) ~[CustomMap-1.1.33.jar:?]
        at java.util.HashMap$Values.forEach(HashMap.java:1065) ~[?:?]
        at online.flowerinsnow.custommap.util.InventoryUtils.addItemStacksOrDrop(InventoryUtils.java:43) ~[CustomMap-1.1.33.jar:?]
        at online.flowerinsnow.custommap.miraimc.CustomMapMiraiMC.readyGive(CustomMapMiraiMC.java:509) ~[CustomMap-1.1.33.jar:?]
        at online.flowerinsnow.custommap.miraimc.CustomMapMiraiMC.inputImageInline(CustomMapMiraiMC.java:474) ~[CustomMap-1.1.33.jar:?]
        at online.flowerinsnow.custommap.miraimc.CustomMapMiraiMC.lambda$onGroupMessage$3(CustomMapMiraiMC.java:308) ~[CustomMap-1.1.33.jar:?]
        at org.bukkit.craftbukkit.v1_20_R2.scheduler.CraftTask.run(CraftTask.java:101) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at org.bukkit.craftbukkit.v1_20_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:481) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at me.earthme.molia.thread.CraftSchedulerRunner.doSchedulerTask(CraftSchedulerRunner.java:88) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
        at me.earthme.molia.thread.CraftSchedulerRunner.run(CraftSchedulerRunner.java:55) ~[molia-1.20.2.jar:git-Molia-"38ff6a5"]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant