mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Add BlockExplosionHitEvent (#349)
* Add BlockExplosionHitEvent * Remove import
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
package org.dreeam.leaf.event;
|
||||||
|
|
||||||
|
import org.bukkit.ExplosionResult;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.block.BlockEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a block executes its explosion hit actions.
|
||||||
|
* If the event is cancelled, the block will not execute the explosion hit actions.
|
||||||
|
*/
|
||||||
|
public class BlockExplosionHitEvent extends BlockEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled;
|
||||||
|
private final Entity source;
|
||||||
|
private final ExplosionResult result;
|
||||||
|
|
||||||
|
public BlockExplosionHitEvent(@NotNull Block block, Entity source, ExplosionResult result) {
|
||||||
|
super(block);
|
||||||
|
this.source = source;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the entity responsible for the explosion.
|
||||||
|
*
|
||||||
|
* @return Entity responsible for the explosion
|
||||||
|
*/
|
||||||
|
public Entity getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the result of the explosion.
|
||||||
|
*
|
||||||
|
* @return the result of the explosion
|
||||||
|
*/
|
||||||
|
public ExplosionResult getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Pascalpex <pascalpex@gmail.com>
|
||||||
|
Date: Wed, 4 Jun 2025 17:03:32 +0200
|
||||||
|
Subject: [PATCH] Add BlockExplosionHitEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
|
||||||
|
index 6030c4eefd77969a1a9251de76d4291dcb0a2092..ea9c641fe9a9685307b6de2999ea4ff5342269b7 100644
|
||||||
|
--- a/net/minecraft/world/level/ServerExplosion.java
|
||||||
|
+++ b/net/minecraft/world/level/ServerExplosion.java
|
||||||
|
@@ -623,9 +623,13 @@ public class ServerExplosion implements Explosion {
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
- this.level
|
||||||
|
- .getBlockState(blockPos)
|
||||||
|
- .onExplosionHit(this.level, blockPos, this, (itemStack, blockPos1) -> addOrAppendStack(list, itemStack, blockPos1));
|
||||||
|
+ // Leaf start - BlockExplosionHitEvent
|
||||||
|
+ if(new org.dreeam.leaf.event.BlockExplosionHitEvent(CraftLocation.toBukkit(blockPos, bworld).getBlock(), this.source == null ? null : this.source.getBukkitEntity(), org.bukkit.craftbukkit.CraftExplosionResult.toBukkit(this.blockInteraction)).callEvent()) {
|
||||||
|
+ this.level
|
||||||
|
+ .getBlockState(blockPos)
|
||||||
|
+ .onExplosionHit(this.level, blockPos, this, (itemStack, blockPos1) -> addOrAppendStack(list, itemStack, blockPos1));
|
||||||
|
+ }
|
||||||
|
+ // Leaf end
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ServerExplosion.StackCollector stackCollector : list) {
|
||||||
Reference in New Issue
Block a user