Jump to content

The public type Sleep must be defined in its own file


Recommended Posts

Posted

I'm still new to this so instead of using conditional sleeps all the time I decided to do this code at the top of my file.

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();

}

}

I get this error in eclipse The public type Sleep must be defined in its own file.

 

I try and run this code and get this error in the log when running.

 

if(inventory.contains(Items))

{

if(!myPlayer().isAnimating() || !myPlayer().isMoving()) {

inventory.getItem("Knife").interact("Use");

sleep(random(400,2000));

inventory.getItem(Items).interact("use");

Sleep.sleepUntil(() -> !inventory.contains(Items) || getDialogues().clickContinue() || myPlayer().isMoving(), 15000);

log("can I continue to cook or no?");

continuecooking = 1;

log("Continuein to cook activated.");

}

}

 

The error in the console when running shows

[ERROR][Bot #1][02/12 01:57:38 PM]: Error in bot executor or from Error class (and not Exception)!
java.lang.Error: Unresolved compilation problem:

 at core.Sleep.sleepUntil(Main.java:43)
 at core.Main.onLoop(Main.java:204)
 at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ji:48)
 at java.lang.Thread.run(Unknown Source)

 

Posted
On 2/12/2019 at 7:33 PM, luciuspragg said:

Java doesn't support two public classes in a single .java file. You'll need to put the declaration in a separate .java file.

 

I must ask, this looks a lot more convoluted than just using conditional sleeps, what about them do you not like?

It appears to be using BooleanSupplier which is mostly syntax sugar. That way, instead of doing:

new ConditionalSleep(1000) {
		
		@Override
		public boolean condition() throws InterruptedException {
			return myPlayer().isUnderAttack();
		}
		
	}.sleep();

His Sleep class wraps it up and reduces it down to just:

new Sleep(myPlayer()::isUnderAttack, 1000).sleep();

Or similarly if you call the static methods in the Sleep class.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...