Save me & my money - How to make Discord bot inside Sponge plugin

Ill talk simply - what I want: (I seriously was trying lots of combinations, but NullPointerEx always is thrown).
At onServerStart(GameStartedServerEvent e):

  1. login to Discord bot with JDA
  2. External class (Bot.java) where ill put all listeners and possible commands.

I tried lots of things, but as I said before - NPE. Dont ask me for “my code”: here it is:

public void onServerStart(GameStartedServerEvent e)
{
}

NullpointerException is the easiest error to fix, why did you give up on the multitude of ways you have tried to it?

  • There are multiple plugins out there that add a discord bot to sponge. How come your recreating the wheel?

I had only JDA login - only that - and NPE appeared

Show us the NPE stacktrace and the few code you have cause I doubt you have no code at all. (no code = no NPE)

CLASS NOT FOUND: https://gist.github.com/LambdaTheDev/792f6bac773f2d66e7ca03d2aca97d18
Code (in GameStartedServerEvent):
{
JDA jda = new JDABuilder(Consts.bottoken).build();
}
no more

(Sry, NPE was in Discord4J, but It dont have events that i want)

ClassDefNotFound means its finding the class file but can not read it. Here is the official java explanation of it

https://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html

Is the class file provided with your jar file?

Yes, JAR contains JDA lib
Structure:
Plugin JAR:

  • code
  • JDA.jar

Manually checked with winrar

So inside your .jar file is JDA as a jar file?

Yes, it is as JAR (I using InteliJ)

thats why your getting the error then, it needs to be unpacked.

In Intelij you can do this by changing the library to “Compile” in “dependencies” (you can get to this screen by pressing F4 when the project is selected and then select the plugins module and then click the tab)

No, no, no. When I added it as pure Java code, I had to add 50 libs - I dont want to use my code - its always breaking. If its possible, Can I have just Library (Bot.java) Where:

  • i will have JDA connection;
  • Listeners and possible commands.

DONT ask for my code - No code. When I tried to add all necesary libs to compile, my jar grown up from 40 to 2066 kb.

Again. My question is why are you recreating the wheel?

Also why are you affrad to have a 2mb plugin? My own plugin “Ships” is 800kb and that doesnt have any libraries.

Also if were happy with the size of your plugin when it was a .jar, you will probably be happy with the size of your plugin when its compiled as having the unpacked classes inside your plugin is no different to having the .jar inside.

Also, from what I can gather. Are you asking for a plugin that does this with “I don’t want to use my own code” or are you asking someone to provide complete code? If the latter then you will find that most developers won’t do this as your not learning from other peoples code, if the former then you should put it in the “plugin requests” category.

Sorry for being rude, but this is really importent for me. But I almost solved my problem - but I get ClassNotFoundException, but main problem is… that class is in that JAR (not as jar file, but like normal class). Now I dont know what to do now…

ClassNotFoundException is where it can not find the class nor the file.

Check your .jar file for the .class file of the class. If it is there then something strange is happening. If its not there then its a issue with converting the library to compiled code.

Also make sure the class file is .class and not .java, they are two very different things.

And dont worry, didnt realise you were being rude XD

So the error is ClassDefNotFound, not ClassNotFound (slightly different). Its looking for a file called CaseInsensitiveMap.class and not finding it.

The class file in question is this one CaseInsensitiveMap (Apache Commons Collections 4.4 API)

Edit:
Sorry just seen it in your zip viewer. So im not 100% sure if this is the reason but I know Forge itself blocks some libraries from running, I believe all apache stuff is part of it. The work around for this is to refactor the apache package to something else, however all dependents must also be modified to suit to the refactor. This means you will need to put all the libs in Intelij as modules and then refactor the imports

Edit2:
Just doubled checked. All packages starting with “org.apache” are ignored. So yeah thats why your getting the error

Edit 3:
The simplest way i can think of doing this would be to combine all the libraries together into a single folder and then load the project in Intelij and then refactor the package from there. Intelij will change the dependents as long as they are in the same module (if they are in the same folder then it would be).

If you dont have the source code of the libs then compile all the libs without your code and then run a java decompiler on the output. I would recommend using CRF. There are “Online” decompilers that you can use if you want no download of programs. From there you will have the source code inside a folder so load it into Intelij and refactor

Sorry, its impossible for me. When I followed ur steps - when compiling InteliJ found errors, repairing one caused 2nd one… Im making plugin request…

Thanks for help…