Hot Summer Deals are Here!
Celebrate with up to 90% off on 14,400 resources
04
Days
16
Hours
26
Mins
08
Secs

Why isn't my createExplosion method breaking blocks?

Status
This thread has been locked.

Plus.

livin
Supreme
Feedback score
16
Posts
311
Reactions
158
Resources
0
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:
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?
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

SeasonGuy

Feedback score
0
Posts
12
Reactions
2
Resources
0
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:
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?
perhaps explosion too small? 4 is tnt

also may want to run task synchronous not asynchronous
 

Plus.

livin
Supreme
Feedback score
16
Posts
311
Reactions
158
Resources
0
perhaps explosion too small? 4 is tnt

also may want to run task synchronous not asynchronous
Everything is working okay, like the timer works, the particles and sounds for the explosion works, but the blocks just don'tk break and idk why
 

SeasonGuy

Feedback score
0
Posts
12
Reactions
2
Resources
0
Everything is working okay, like the timer works, the particles and sounds for the explosion works, but the blocks just don'tk break and idk why
run task synchronously!! async task not good to call methods that are not thread safe (definitly not modifying world! they wont allow it either)
 

Plus.

livin
Supreme
Feedback score
16
Posts
311
Reactions
158
Resources
0
run task synchronously!! async task not good to call methods that are not thread safe (definitly not modifying world! they wont allow it either)
It wont let me! It's asking me to change it back to Async
 
Status
This thread has been locked.
Top