Location Y decrease every 5 tick... Probably easy fix.

Discussion in 'Spigot Plugin Development' started by fujiboy4, Jun 7, 2016.

  1. Code (Text):
    if (!map.containsKey(p.getUniqueId().toString())) {
                   
                    timer5 = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                        int i = 15;

                        @Override
                        public void run() {
                            i--;
                            FireworkEffect fireworkEffect = FireworkEffect.builder().flicker(true).trail(true)
                                    .with(Type.BURST).withColor(Color.RED).build();

                            Location location = new Location(p.getWorld(), getConfig().getDouble("Fireworks.spawn1.x"),
                                    getConfig().getDouble("Fireworks.spawn1.x"),
                                    getConfig().getDouble("Fireworks.spawn1.z"));

                            new InstantFirework(fireworkEffect, location);
                            if (i <= 0) {
                                Bukkit.getScheduler().cancelTask(timer5);
                                FireworkEffect fireworkEffect2 = FireworkEffect.builder().flicker(true).trail(true)
                                        .with(Type.BALL_LARGE).withColor(Color.RED).withFade(Color.WHITE).build();

                                Location location2 = new Location(p.getWorld(), getConfig().getDouble("Fireworks.spawn2.x"),
                                        getConfig().getDouble("Fireworks.spawn2.y"),
                                        getConfig().getDouble("Fireworks.spawn2.z"));

                                new InstantFirework(fireworkEffect2, location2);
                                map.remove(p.getUniqueId().toString());
                            }
                        }

                    }, 0L, 5L);
                    map.put(p.getUniqueId().toString(), timer5);
                }
    Not sure why I can't do this... But it is probably an easy fix. Ok so, I want the fireworks to come down 1 block every 5 ticks till it hits the bottom of the spawn. Which 15 blocks is how high i set the locations apart.
    The fireworks launch but they just stay up in the air and don't move downward. (Explosions)

    Thanks.
     
  2. MiniDigger

    Supporter

    you never decrease the location. you need to add your 'i' to the y value of your locations
     
  3. i would reccommend reducing the locations y value by 1 every time, untill 'i' reaches 0 in which case the runnable can be canceled like you have already done

    would also like to add that bumping should only be done once every 24 hours, this forum has people answering your questions out of their own time for free, we are not paid to do this, we have no obligation to be here and answer questions but we do it anyway so please be patient and wait for someone to answer your question.
     
  4. Ok this is what I have done, I created another variable, called "time" and every time that the runnable runs, it will go up by 1. Then I subtract the "time" from the y in the config. Supposedly, time is getting bigger therefore making a bigger gap between the first and second run... But, all it does is stay at the same location. Oh and btw, when 2 players join at somewhat the same time, the runnable crashes and repeatedly shoots fireworks and doesnt stop... I though the hashmap would take care of that..