mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 01:49:30 +00:00
添加尝试破坏家具事件
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package net.momirealms.craftengine.bukkit.api.event;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FurnitureAttemptBreakEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final BukkitFurniture furniture;
|
||||
|
||||
public FurnitureAttemptBreakEvent(@NotNull Player player,
|
||||
@NotNull BukkitFurniture furniture) {
|
||||
super(player);
|
||||
this.furniture = furniture;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Player player() {
|
||||
return getPlayer();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitFurniture furniture() {
|
||||
return this.furniture;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location location() {
|
||||
return this.furniture.location();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ public class BlockEventListener implements Listener {
|
||||
Block block = blocks.get(i);
|
||||
Location location = block.getLocation();
|
||||
BlockPos blockPos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
ImmutableBlockState state = manager.getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
|
||||
ImmutableBlockState state = this.manager.getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
|
||||
if (state != null && !state.isEmpty()) {
|
||||
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(blockPos));
|
||||
ContextHolder.Builder builder = ContextHolder.builder()
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureBreakEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureInteractEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureAttemptBreakEvent;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
@@ -1539,9 +1540,14 @@ public class PacketConsumers {
|
||||
mainThreadTask = () -> {
|
||||
// todo 冒险模式破坏工具白名单
|
||||
if (serverPlayer.isAdventureMode() ||
|
||||
!furniture.isValid() ||
|
||||
!BukkitCraftEngine.instance().antiGrief().canBreak(platformPlayer, location)
|
||||
) return;
|
||||
!furniture.isValid()) return;
|
||||
|
||||
FurnitureAttemptBreakEvent preBreakEvent = new FurnitureAttemptBreakEvent(serverPlayer.platformPlayer(), furniture);
|
||||
if (EventUtils.fireAndCheckCancel(preBreakEvent))
|
||||
return;
|
||||
|
||||
if (!BukkitCraftEngine.instance().antiGrief().canBreak(platformPlayer, location))
|
||||
return;
|
||||
|
||||
FurnitureBreakEvent breakEvent = new FurnitureBreakEvent(serverPlayer.platformPlayer(), furniture);
|
||||
if (EventUtils.fireAndCheckCancel(breakEvent))
|
||||
|
||||
Reference in New Issue
Block a user