Hey, so I'm trying to make it so when you throw a "bomb", after 2 seconds, it explodes and breaks all blocks in an X radius.
My code:
After 2 seconds, the explosion sound plays, but no blocks are broken?
My code:
Code:
package me.hawauh.prisonbombs;
import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public class ActualBombs implements Listener {
public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks) {
return true;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (e.getAction() == Action.RIGHT_CLICK_AIR) {
if (e.getItem().getItemMeta().equals(GetBombMethods.getBomb1Item().getItemMeta())) {
p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
final Item grenade = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.FIREBALL));
grenade.setVelocity(p.getLocation().getDirection().multiply(1.0D));
p.sendMessage("§bYou have thrown a §7Regular Bomb");
new BukkitRunnable() {
public void run() {
p.sendMessage("§b§lBang! Your bomb exploded!");
grenade.getWorld().createExplosion(grenade.getLocation().getX(), grenade.getLocation().getY(),
grenade.getLocation().getZ(), 1, false, true);
}
}.runTaskLaterAsynchronously(JavaPlugin.getPlugin(Main.class), 40);
}
if (e.getItem().getItemMeta().equals(GetBombMethods.getBomb2Item().getItemMeta())) {
p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
final Item grenade = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.MAGMA_CREAM));
grenade.setVelocity(p.getLocation().getDirection().multiply(1.2D));
p.sendMessage("§bYou have thrown a §7Block Buster");
new BukkitRunnable() {
public void run() {
p.sendMessage("§b§lBang! Your bomb exploded!");
grenade.getWorld().createExplosion(grenade.getLocation().getX(), grenade.getLocation().getY(),
grenade.getLocation().getZ(), 1, false, true);
}
}.runTaskLaterAsynchronously(JavaPlugin.getPlugin(Main.class), 40);
}
if (e.getItem().getItemMeta().equals(GetBombMethods.getBomb3Item().getItemMeta())) {
p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
final Item grenade = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.FLINT));
grenade.setVelocity(p.getLocation().getDirection().multiply(1.5D));
p.sendMessage("§bYou have thrown a §7Grenade");
new BukkitRunnable() {
public void run() {
p.sendMessage("§b§lBang! Your grenade exploded!");
grenade.getWorld().createExplosion(grenade.getLocation().getX(), grenade.getLocation().getY(),
grenade.getLocation().getZ(), 1, false, true);
}
}.runTaskLaterAsynchronously(JavaPlugin.getPlugin(Main.class), 40);
}
if (e.getItem().getItemMeta().equals(GetBombMethods.getBomb4Item().getItemMeta())) {
p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
final Item grenade = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.EMERALD));
grenade.setVelocity(p.getLocation().getDirection().multiply(1.5D));
p.sendMessage("§bYou have thrown a §7Cluster Bomb");
new BukkitRunnable() {
public void run() {
p.sendMessage("§b§lBang! Your bomb exploded!");
grenade.getWorld().createExplosion(grenade.getLocation().getX(), grenade.getLocation().getY(),
grenade.getLocation().getZ(), 5, false, true);
}
}.runTaskLaterAsynchronously(JavaPlugin.getPlugin(Main.class), 40);
}
}
}
}
After 2 seconds, the explosion sound plays, but no blocks are broken?
