Skip to content

Commit

Permalink
Implement BlockExplodeEvent (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mystiflow authored and mastercoms committed Jun 2, 2018
1 parent 1e7632e commit 5b8c8e2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/main/java/net/glowstone/Explosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.blocktype.BlockTnt;
import net.glowstone.entity.GlowEntity;
Expand All @@ -24,6 +25,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
Expand Down Expand Up @@ -68,6 +70,7 @@ public final class Explosion {
}
}

@Nullable
private final Entity source;
private final Location location;
private final boolean incendiary;
Expand Down Expand Up @@ -102,8 +105,8 @@ public Explosion(Entity source, GlowWorld world, double x, double y, double z, f
* @param incendiary Whether or not blocks should be set on fire
* @param breakBlocks Whether blocks should break through this explosion
*/
public Explosion(Entity source, Location location, float power, boolean incendiary,
boolean breakBlocks) {
public Explosion(@Nullable Entity source, Location location, float power,
boolean incendiary, boolean breakBlocks) {
if (!(location.getWorld() instanceof GlowWorld)) {
throw new IllegalArgumentException("Supplied location does not have a valid GlowWorld");
}
Expand All @@ -127,14 +130,26 @@ public boolean explodeWithEvent() {

Set<BlockVector> droppedBlocks = calculateBlocks();

// The 'blocks' list should mutable for event calls.
List<Block> blocks = toBlockList(droppedBlocks);
EntityExplodeEvent event = EventFactory.getInstance().callEvent(
new EntityExplodeEvent(source, location, blocks, yield));
if (event.isCancelled()) {
return false;
}

yield = event.getYield();
if (source != null) {
EntityExplodeEvent event = EventFactory.getInstance().callEvent(
new EntityExplodeEvent(source, location, blocks, yield));
if (event.isCancelled()) {
return false;
}

yield = event.getYield();
} else {
BlockExplodeEvent event = EventFactory.getInstance().callEvent(
new BlockExplodeEvent(location.getBlock(), blocks, yield));
if (event.isCancelled()) {
return false;
}

yield = event.getYield();
}

playOutSoundAndParticles();

Expand Down

0 comments on commit 5b8c8e2

Please sign in to comment.