java - Bukkit drop exploded blocks -
i using bukkit 1.8.3 api java 7.
i have code explodes blocks upon when break it. launches explosion breaks blocks around block broke. problem exploded blocks not dropping, 1 player has broke already. have tried fix adding event (also, events registered):
@eventhandler public void onentitydamage(entitydamagebyblockevent e) { if(e.getcause().equals(damagecause.block_explosion)) { if (explosive) { e.setcancelled(true); } } }
this stops player being damaged, not blocks being dropped. thought since dropped block entity work. not. how exploded blocks drop?
this code use explode block in first place:
loc.getworld().createexplosion(loc, lvl1);
loc
block location. lvl1
float radius of explosion.
this cause of simple: explosions don't drop of blocks default.
you can, however, change this: listen blockexplodeevent
, , call setyield
value of 1. add event handler:
@eventhandler public void onblockexplosion(blockexplodeevent e) { e.setyield(1); }
you might want add kind of check whether explosion caused plugin, though.
if doesn't work, can use code instead:
@eventhandler public void onblockexplosion(blockexplodeevent e) { (block block : e.blocklist()) { block.breaknaturally(); } }
the above code works, break other plugin stuff blocklist
, of blocks become air. such, strongly recommend using first code if can.
blockexplodeevent seems in newest versions; if don't have it, you'll need update. it's found in both 1.8 releases, recent updates.
here's pom you'll need:
<repositories> <repository> <id>spigot-repo</id> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupid>org.bukkit</groupid> <artifactid>bukkit</artifactid> <version>1.8.3-r0.1-snapshot</version> </dependency> </dependencies>
you need maven -> update, , make sure "force update of shapshots/releases" checked.
Comments
Post a Comment