Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make possible cancelling and editing explosion when there is no entity #1511

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/main/java/cn/nukkit/event/level/ExplodeEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cn.nukkit.event.level;

import cn.nukkit.block.Block;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import cn.nukkit.level.Level;
import cn.nukkit.level.Position;

import java.util.List;

/**
* author: SergeyDertan
* Nukkit Project
*/
public class ExplodeEvent extends LevelEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();

protected final Position position;
protected List<Block> blocks;
protected double yield;

public static HandlerList getHandlers() {
return handlers;
}

public ExplodeEvent(Level level, Position position, List<Block> blocks, double yield) {
super(level);
this.position = position;
this.blocks = blocks;
this.yield = yield;
}

public Position getPosition() {
return this.position;
}

public List<Block> getBlockList() {
return this.blocks;
}

public void setBlockList(List<Block> blocks) {
this.blocks = blocks;
}

public double getYield() {
return this.yield;
}

public void setYield(double yield) {
this.yield = yield;
}
}
10 changes: 10 additions & 0 deletions src/main/java/cn/nukkit/level/Explosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.event.entity.EntityExplodeEvent;
import cn.nukkit.event.level.ExplodeEvent;
import cn.nukkit.inventory.InventoryHolder;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
Expand Down Expand Up @@ -133,6 +134,15 @@ public boolean explodeB() {
yield = ev.getYield();
this.affectedBlocks = ev.getBlockList();
}
} else {
ExplodeEvent ev = new ExplodeEvent(this.level, this.source, this.affectedBlocks, yield);
this.level.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
} else {
yield = ev.getYield();
this.affectedBlocks = ev.getBlockList();
}
}

double explosionSize = this.size * 2d;
Expand Down