Velocity and ticks - scheduleSyncDelayedTask

Discussion in 'Spigot Plugin Development' started by Invaerne, Jun 1, 2017.

  1. Hi guys,

    It seems that changing the maxspeed and velocity has also change the speed of ticks.

    This code right here should charge player every 5 seconds, and it works fine when the speed and velocity are set to the regular or slightly higher values. However, the problem starts to occur when I change the speed to much higher values.

    Can anyone think of a way to solve this problem?

    Code (Text):
                              Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable()
                              {
                                public void run()
                                {

                                    charge(p);
                                   
                                }
                              }
                              , 100L);
     
  2. Can you please restate your problem and show us your full scenario?
     
  3. Sure thing. I'm changing the velocity and maxspeed of a minecart while traveling.

    The scheduleSyncDelayedTask is inside the charge(p) method.

    Once the player changes the speed of minecart, they will be charged a certain amount of money every 5 seconds.
    This is working fine when the values of velocity and maxspeed are default, or slightly higher.

    However, once the player has changed the velocity and maxspeed to much higher values - traveling much faster, 4x the default speed of the minecart - the scheduleSyncDelayedTask is running every 1 or 2 seconds instead of 5.

    Therefore, I assume that the change of velocity and maxspeed had to also manipulate the speed of which bukkit is counting ticks.

    Is there any way of making scheduleSyncDelayedTask to stick to the seconds?
     
  4. When changing speeds be sure you are cancelling previous tasks if you're creating new task with new speed. Sounds to me like that's all it is.
     
  5. Try doing it with a BUkkitRunnable and have counter variables which go up by 20 ticks which is 1s and if the counter hits 5 do whatever you want to do