9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00

refactor(bukkit): 调整方块破坏事件并优化 API

- 移除 CustomBlockBreakEvent 中的 BreakReason 参数
- 更新 BlockStartBreakEvent 中的 optionalPlayer 方法返回类型
- 优化 CustomBlockBreakEvent 类的结构和内容
This commit is contained in:
jhqwqmc
2025-02-12 22:06:24 +08:00
parent 2acbb42d22
commit 9aa1a57aea
3 changed files with 5 additions and 15 deletions

View File

@@ -32,6 +32,7 @@ public class BlockStartBreakEvent extends Event implements Cancellable {
return location;
}
@NotNull
public Player optionalPlayer() {
return optionalPlayer;
}
@@ -48,7 +49,6 @@ public class BlockStartBreakEvent extends Event implements Cancellable {
return handlerList;
}
@Override
public @NotNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@@ -1,6 +1,5 @@
package net.momirealms.craftengine.bukkit.api.event;
import net.momirealms.craftengine.core.block.BreakReason;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.world.BlockPos;
@@ -10,7 +9,6 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CustomBlockBreakEvent extends Event implements Cancellable {
private static final HandlerList handlerList = new HandlerList();
@@ -19,24 +17,18 @@ public class CustomBlockBreakEvent extends Event implements Cancellable {
private final ImmutableBlockState state;
private final Location location;
private final Player optionalPlayer;
private final BreakReason reason;
public CustomBlockBreakEvent(ImmutableBlockState state, Location location, BreakReason reason, Player optionalPlayer) {
public CustomBlockBreakEvent(ImmutableBlockState state, Location location, Player optionalPlayer) {
this.block = state.owner().value();
this.state = state;
this.location = location;
this.optionalPlayer = optionalPlayer;
this.reason = reason;
}
public CustomBlock block() {
return this.block;
}
public BreakReason reason() {
return this.reason;
}
public BlockPos blockPos() {
return new BlockPos(this.location.getBlockX(), this.location.getBlockY(), this.location.getBlockZ());
}
@@ -45,8 +37,7 @@ public class CustomBlockBreakEvent extends Event implements Cancellable {
return this.location;
}
@Nullable
public Player optionalPlayer() {
public @NotNull Player optionalPlayer() {
return this.optionalPlayer;
}
@@ -58,8 +49,7 @@ public class CustomBlockBreakEvent extends Event implements Cancellable {
return handlerList;
}
@NotNull
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@@ -105,7 +105,7 @@ public class BlockEventListener implements Listener {
ImmutableBlockState state = manager.getImmutableBlockStateUnsafe(stateId);
if (!state.isEmpty()) {
Location location = block.getLocation();
CustomBlockBreakEvent customBreakEvent = new CustomBlockBreakEvent(state, location, BreakReason.PLAYER_BREAK, event.getPlayer());
CustomBlockBreakEvent customBreakEvent = new CustomBlockBreakEvent(state, location, event.getPlayer());
boolean isCancelled = EventUtils.fireAndCheckCancel(customBreakEvent);
if (isCancelled) event.setCancelled(true);
net.momirealms.craftengine.core.world.World world = new BukkitWorld(location.getWorld());