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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user