Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Conditional Sleep With Lambda Expressions

Featured Replies

import org.osbot.rs07.utility.ConditionalSleep;

import java.util.function.BooleanSupplier;

public final class Sleep extends ConditionalSleep {

    private final BooleanSupplier condition;

    public Sleep(final BooleanSupplier condition, final int timeout) {
        super(timeout);
        this.condition = condition;
    }

    public Sleep(final BooleanSupplier condition, final int timeout, final int interval) {
        super(timeout, interval);
        this.condition = condition;
    }

    @Override
    public final boolean condition() throws InterruptedException {
        return condition.getAsBoolean();
    }

    public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) {
        return new Sleep(condition, timeout).sleep();
    }

    public static boolean sleepUntil(final BooleanSupplier condition, final int timeout, final int interval) {
        return new Sleep(condition, timeout, interval).sleep();
    }
}

 

Usage:

Sleep sleep = new Sleep(() -> myPlayer().isAnimating(), 5000);
sleep.sleep();

Or:

Sleep.sleepUntil(() -> myPlayer().isAnimating(), 5000);

 

Edited by Explv

public class CustomSleep extends ConditionalSleep{
	
	private BooleanSupplier condition;

	public CustomSleep(BooleanSupplier condition, int timeout) {
		super(timeout);
		this.condition = condition;
	}

	@Override
	public boolean condition() throws InterruptedException {
		return condition.getAsBoolean();
	}

}

Example usage

new CustomSleep(() -> myPlayer().isAnimating(), 2000).sleep();

 

1 minute ago, Tom said:

public class CustomSleep extends ConditionalSleep{
	
	private BooleanSupplier condition;

	public CustomSleep(BooleanSupplier condition, int timeout) {
		super(timeout);
		this.condition = condition;
	}

	@Override
	public boolean condition() throws InterruptedException {
		return condition.getAsBoolean();
	}

}

Example usage


new CustomSleep(() -> myPlayer().isAnimating(), 2000).sleep();

 

He just has an interval parameter to change how often to check I believe, otherwise it's the same. ._.

  • Author
1 minute ago, Eliot said:

Nice snippet, but I prefer 

 

 

You should be demoted REEEEEEEEEE

Edited by Explv

2 minutes ago, GoldenGates said:

He just has an interval parameter to change how often to check I believe, otherwise it's the same. ._.

Yeah but the snippet is mine and not his

3 hours ago, Easy said:

erOxiVI.png

Thanks for the blatantly obvious meme

  • 1 year later...

Thought I'd add a comment here instead of a new thread. Made a smol addition to the Sleep class that saves some lines of code down the road.

public static <k> k untilNotNull(final Supplier<k> locator, final int timeout, final int interval) {
  Sleep.until(() -> locator.get() != null, timeout, interval);
  return locator.get();
}

Using this, you can essentially wait for an item to be not-null, and it'll return it. Like so:

RS2Object coal = Sleep.untilNotNull(() -> ctx.getObjects().closest(ent -> MiningEntity.COAL.hasOre(ent)), 15_000, 750);
if (coal == null)
  //ABORT

I could save an additional call to the locator by wrapping the <k> in a mutable final object, but meh.

 

Edited by NoxMerc

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.