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: 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(); @EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); event.setJoinMessage(""); player.sendMessage(prefix + GREEN + "Welcome back, " + GRAY + player.getName() + GREEN + "!"); item.giveItem(player); Location spawn = new Location(player.getWorld(), -212.5, 91, 445.5); player.teleport(spawn); if(player.hasPlayedBefore()) { 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.addEffect(builder.flicker(true).withColor(Color.BLUE).build()); fireworkmeta.addEffect(builder.trail(true).build()); fireworkmeta.addEffect(builder.withFade(Color.RED).build()); fireworkmeta.addEffect(builder.with(FireworkEffect.Type.CREEPER).build()); fireworkmeta.setPower(0);//maybe here is the thing I need to change? firework.setFireworkMeta(fireworkmeta); } } }
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()
Use firework.detonate() to make it instantly explode. You may need a BukkitRunnable to execute that code like 2 ticks later tho
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?
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)
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() { @Override public void run() { //code to be executed } }.runTaskLater(/*main class*/, /*delay in ticks*/);