Solved Creating Chain of Explosions

Discussion in 'Plugin Development' started by SmearySubset, Jun 14, 2021.

Thread Status:
Not open for further replies.
  1. Offline


    I am trying to create a chain of 5 explosions that each occur further and further away from the player. I'd like them to be a couple blocks apart, but I'm unsure of how to set the new location to a further away value. In my code below, where "Change explosion location here" is commented, I tried the following statement but it did not work: explosionLocation.subtract(player.getEyeLocation().toVector());

    P.S. How do I paste the code into the code box feature on the forums? Sorry if it's out of format below. I'm new here.


    public void dragonsBreath(Players player) {
    player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1, 1);

    dragonsBreathTaskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(GameManager.plugin, new Runnable() {

    int count = 1;
    Location explosionLocation = player.getEyeLocation().toVector().add(player.getEyeLocation().getDirection()).toLocation(player.getWorld());

    public void run() {
    player.getWorld().createExplosion(explosionLocation, 2F, false, false);
    // Change explosion location here
    if(count > 5)
    }}, 0, 3); }
  2. Offline


    Code block is here or you just put
    or use some code snips hosting sites: hatebin, hastebin, github gists, etc. (not pastebin)

    Reformatted code here.
    While working with Vectors, you can refer to this.

    .scheduleSyncRepeatingTask() is now deprecated and it was replaced with anonymous BukkitRunnable objects.
    Now you schedule via
    new BukkitRunnable() {
    int count 0
    public void run() {
    // Cancelling the task but just in another way.
    if(count >= 5cancel();
    // codes
    About what you want to do:
    // Firstly, you store the location to start from.
    Location loc p.getLocation();
    // The original direction to add to the loc. Normalizing causes the length to be 1, so you multiply by something to change the distance between each explosion.
    Vector dir loc.getDirection().normalize().multiply(5);

    // Schedule the repeating task with count here.
    public void run() {
    // Adds the vector to the original location.
    loc loc.add(dir);
    // Do your stuff with the new location.
    For example, I made the plugin set the block at the new location a wool block:
  3. Offline


    @Shqep Thanks, it works! Also, I'm currently coding in 1.15.2 and my IDE does not say that SyncRepeatingTask is deprecated. Deprecation only affects certain versions of Minecraft right? Or is one deprecated method deprecated for all versions?
  4. Offline


    It's more of "advised against" than "deprecated". They want you to use anonymous BukkitRunnables as plugin developers. I think they didn't annotate it with @Deprecated because there are still possible usages in the server's internal stuff idk.
  5. Offline


Thread Status:
Not open for further replies.

Share This Page