1.12.2 How to make firework explode where I stand?

Discussion in 'Spigot Plugin Development' started by DoggyPlayss, Feb 3, 2020.

  1. Hello, I wonder how can I make so when I join (or where I will use this cosmetic feature) the firework would explode right where I stand and I could see the effect without turning to the air instead of it shooting up and exploding at a certain point? Maybe I shouldn't even use firework summoning but rather I should summon the effect itself? If so how?

    Code (Java):
    package net.hexilion.Basics.Events;

    import net.hexilion.Basics.Items.SuperSword;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.Location;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.meta.FireworkMeta;

    import static org.bukkit.ChatColor.*;

    public class Join implements Listener
        public String prefix = (AQUA + "" + BOLD + "   +  ");
        private SuperSword item = new SuperSword();
        public void onJoin(PlayerJoinEvent event)
            Player player = event.getPlayer();
            player.sendMessage(prefix + GREEN + "Welcome back, " + GRAY + player.getName() + GREEN + "!");
            Location spawn = new Location(player.getWorld(), -212.5, 91, 445.5);
                Location fireworkloc = spawn.clone();
                fireworkloc.subtract(0, 0, 0);//this doesn't do the job...
                Firework firework = (Firework) player.getWorld().spawnEntity(fireworkloc, EntityType.FIREWORK);
                FireworkMeta fireworkmeta = firework.getFireworkMeta();
                FireworkEffect.Builder builder = FireworkEffect.builder();
                fireworkmeta.setPower(0);//maybe here is the thing I need to change?
  2. Wait so what is your problem? Is the firework not staying at your player or is it not exploding soon enough? Maybe you can get around it by using Firework#detonate()
  3. Use firework.detonate() to make it instantly explode. You may need a BukkitRunnable to execute that code like 2 ticks later tho
  4. I haven't use Runnable before could you give me an example of how it works or if possible what exactly I need to type in my code?
  5. Also I have this issue where I cannot see explosion on my alt when I test only tail of firework, but I can see on account I join with(and for which the explosion is for)
  6. See the javadocs for BukkitRunnable. Usage typically means creating an anonymous class of a BukkitRunnable (extending it works as well) and overriding the run method which executes your code. You can then run the runnable either after a set amount of time or run it repeatedly at certain intervals. As an example:
    Code (Java):
    new BukkitRunnable() {
        public void run() {
            //code to be executed
    }.runTaskLater(/*main class*/, /*delay in ticks*/);
    • Useful Useful x 1