How to return a value from Runnable

Discussion in 'Skript' started by UnrealMiner4, Jul 8, 2021.

Thread Status:
Not open for further replies.
  1. Hey, I'm trying to make a boolean method that checks the player's speed and then, if it is low enough, returns true. The thing is, that to check the speed, you have to wait at least one tick, and for that I use Runnable and runTaskLater thing. After that I want to return true or false, and how do I do it? Here's the code:
    Code (Java):
    public boolean isSlow(Player p) {
            //It gets player's location
            Double x1 = p.getLocation().getX();
            Double z1 = p.getLocation().getZ();
            Runnable r = new Runnable() {
               
                @Override
                public void run() {
                    //It gets player's location after a tick
                    Double x2 = p.getLocation().getX();
                    Double z2 = p.getLocation().getZ();
                    //It calculates his speed
                    Double speedx = Math.abs(x1-x2);
                    Double speedz = Math.abs(z1-z2);
                   //It checks if the speed is low enough
                    if(!(speedx < 0.1011f) && !(speedz < 0.1011f)) {
                        //What do I write here?
                    } else {
                        //...and here
                    }
                }
            };
            Bukkit.getScheduler().runTaskLater(Classes.plugin/*Plugin_Instance*/, r, 1);
        }
    Or maybe if you would recommend me another way to do that, I would really appreciate that!
     
Thread Status:
Not open for further replies.