mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
fix(bukkit): 修复方块破坏时物品为空导致的空指针异常
- 在 BlockEventListener 类中添加对空物品的处理- 当玩家手中物品为空时,使用 "minecraft:air" 作为物品 ID - 优化了方块破坏时的物品检查逻辑,提高了代码的健壮性
This commit is contained in:
@@ -16,6 +16,7 @@ import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
@@ -120,8 +121,14 @@ public class BlockEventListener implements Listener {
|
||||
|
||||
BukkitServerPlayer serverPlayer = plugin.adapt(player);
|
||||
Item<ItemStack> itemInHand = serverPlayer.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
Key itemId;
|
||||
if (itemInHand == null) {
|
||||
itemId = Key.of("minecraft:air");
|
||||
} else {
|
||||
itemId = itemInHand.id();
|
||||
}
|
||||
// do not drop if it's not the correct tool
|
||||
if (!state.settings().isCorrectTool(itemInHand.id())) {
|
||||
if (!state.settings().isCorrectTool(itemId)) {
|
||||
return;
|
||||
}
|
||||
// drop items
|
||||
|
||||
Reference in New Issue
Block a user