FearlessPixl

Custom local script error

Recommended Posts

Hi all,

 

I just set up the rsbot-api project in Intellij, got my test script to show up in the OSRS client, but I'm getting this error:

"[SEVERE] Script: Error loading script
java.lang.ClassCastException: class scripts.TestScript
    at java.lang.Class.asSubclass(Class.java:3404)
    at org.powerbot.misc.ScriptList.this(ScriptList.java:206)
    at org.powerbot.gui.cOm1.this(BotPreferences.java:402)"

 

I'm not really sure what info would be helpful here so I'll just post my script code for now:

 

package scripts;

import org.powerbot.script.PollingScript;
import org.powerbot.script.Script;
import org.powerbot.script.rt4.ClientContext;

/**
 * @author fearlesspixl
 * @since 1/10/2019
 */
@Script.Manifest(name = "TestScript", properties = "author=fearlesspixl; client=4;", description = "A")
public class TestScript extends PollingScript<ClientContext> {

	@Override
	public void start() {
		if (!ctx.game.loggedIn()) {
			log.info("You need to log in");
		} else {
			log.info("Hello!");
		}
	}

	@Override
	public void poll() {
	}

}

Any help is appreciated!

Share this post


Link to post


Coma   

I can run it no problem. You may have old class files in your out directory. In IntelliJ, right click the module and select "Rebuild Module." This will clean and recompile the project.

 

nwKU8Vn.png

Share this post


Link to post

No, it's up to date. I'm very familiar with Java and IntelliJ. Is Maven known to cause any scripting issues? I've compiled with Maven and IntelliJ and I have the problem either way though..

Share this post


Link to post
Coma   

The exception you posted is thrown when the main script class can't be cast to org.powerbot.script.Script.

 

My guesses are:

1. As I mentioned above;

2. You're not loading the script you think you are;

 

Rebuild the project. Double check that you're loading class files from the correct directory.

Share this post


Link to post

I even updated the name of the script class as well as the name in the annotation. The script name updated in the list of available local scripts but still throws the same error.

 

That proves that the script is up to date and that the correct script is being loaded, right?

Share this post


Link to post

Is it possible for me to spawn a bot client from a test case so I can debug this further?

 

Here's what I'm trying to do:

@Test
public void test() {
   try (BotChrome botChrome = new BotChrome()) {
      botChrome.run();

      try (Bot bot = new Bot(botChrome)) {
         bot.run();

         try (ZipInputStream zis = createZipInput()) {
            final ScriptClassLoader loader = new ScriptClassLoader(bot.ctx, zis);

            loader.loadClass(TestScript.class.getName()).asSubclass(Script.class);
         }
      }
   } catch (ClassNotFoundException | IOException e) {
      e.printStackTrace();
      Assert.fail();
   }
}

 

and this is the error I'm getting:

 

java.lang.NoSuchMethodError: org.powerbot.script.Input.this(Ljava/lang/Object;)Ljava/lang/String;

    at org.powerbot.gui.BotChrome.<clinit>(BotChrome.java:25)
    at fearlesspixl.testScript.TestScriptTest.test(TestScriptTest.java:24)

Edited by FearlessPixl
added error message

Share this post


Link to post
Coma   

I would have thought those classes were obfuscated away, so I'm surprised you can reference them at all.

 

Does whatever toolchain you're using modify classes during the compilation process or anything?

Share this post


Link to post

Haha yeah I was wondering the same thing.

 

As far as I know it does not. But like I said, I've also tried the regular IntelliJ compiler which should definitely not have any issues as far as that is concerned.

Share this post


Link to post
Coma   

Nuclear option:

  • Delete the RSBot jar and redownload it.
  • Make a new IntelliJ project.
  • Add nothing but this class and the RSBot reference.

Share this post


Link to post

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