9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 03:19:14 +00:00

新方案

This commit is contained in:
XiaoMoMi
2025-10-11 01:49:14 +08:00
parent cbe733f1ee
commit 2ce14a4e68
3 changed files with 24 additions and 11 deletions

View File

@@ -95,6 +95,17 @@ public final class BlockEventListener implements Listener {
Object soundId = FastNMS.INSTANCE.field$SoundEvent$location(soundEvent);
player.playSound(block.getLocation().add(0.5, 0.5, 0.5), soundId.toString(), SoundCategory.BLOCKS, 1f, 0.8f);
}
ItemStack itemInHand = event.getItemInHand();
Item<ItemStack> wrap = this.plugin.itemManager().wrap(itemInHand);
Optional<CustomItem<ItemStack>> optionalCustomItem = wrap.getCustomItem();
if (optionalCustomItem.isPresent()) {
CustomItem<ItemStack> customItem = optionalCustomItem.get();
// 阻止放置方块
if (customItem.settings().disableVanillaBehavior()) {
event.setCancelled(true);
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)

View File

@@ -283,17 +283,18 @@ public class ItemEventListener implements Listener {
}
}
}
// custom item
else {
if (optionalCustomItem.get().settings().disableVanillaBehavior()) {
// 允许尝试放置方块
if (serverPlayer.isSecondaryUseActive() || !InteractUtils.isInteractable(player, blockData, hitResult, itemInHand)) {
if (InteractUtils.canPlaceBlock(new BlockPlaceContext(new UseOnContext(serverPlayer, hand, itemInHand, hitResult)))) {
event.setCancelled(true);
}
}
}
}
// 迁移到了BlockPlaceEvent里
// // custom item
// else {
// if (optionalCustomItem.get().settings().disableVanillaBehavior()) {
// // 允许尝试放置方块
// if (serverPlayer.isSecondaryUseActive() || !InteractUtils.isInteractable(player, blockData, hitResult, itemInHand)) {
// if (InteractUtils.canPlaceBlock(new BlockPlaceContext(new UseOnContext(serverPlayer, hand, itemInHand, hitResult)))) {
// event.setCancelled(true);
// }
// }
// }
// }
}
// 优先检查物品行为,再执行自定义事件

View File

@@ -38,6 +38,7 @@ import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.Lightable;
import org.bukkit.block.data.type.*;
import org.bukkit.entity.*;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;