Hello StackOverflow community,
I'm trying to run a Discord bot inside of a Minecraft (Spigot) plugin. Every time I try to do so, I get the following error:
[21:19:32] [Server thread/INFO]: [DiscordWhitelist] Loading DiscordWhitelist v1.0
[21:19:32] [Server thread/INFO]: [DiscordWhitelist] Enabling DiscordWhitelist v1.0
[21:19:32] [Server thread/ERROR]: Error occurred while enabling DiscordWhitelist v1.0 (Is it up to date?)
java.lang.NoClassDefFoundError: net/dv8tion/jda/api/JDABuilder
at discordwhitelist.DiscordWhitelist.onEnable(DiscordWhitelist.java:20) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:492) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:406) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.reload(CraftServer.java:879) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.Bukkit.reload(Bukkit.java:651) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand(CraftServer.java:761) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchServerCommand(CraftServer.java:746) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at net.minecraft.server.v1_16_R3.DedicatedServer.handleCommandQueue(DedicatedServer.java:426) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:395) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1127) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:966) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:273) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_291]
Caused by: java.lang.ClassNotFoundException: net.dv8tion.jda.api.JDABuilder
at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:138) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:99) ~[spigot.jar:3082-Spigot-9fb885e-d49530f]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_291]
... 18 more
This error seems to indicate, that the package JDA isn't loaded, while building the .jar file. One way to fix this issue is by using ShadowJar, to create one fat .jar file. Unfortunately, this isn't ideal, because of the eventual size of the .jar. Using ShadowJar, the plugin will end up being 7000+KB, which greatly exceeds the maximum filesize of most Minecraft plugin sharing sites.
So, in short, I need to find a way to shade only some of the packages.
I've been unable to figure out how to do this using search, so I'm hoping this post will find its way to the right people.
For reference, I'm using the latest version of IntelliJ. I'm making the plugin using Gradle. Here's the code (so far), and the build.gradle file:
package discordwhitelist;
import org.bukkit.plugin.java.JavaPlugin;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import javax.security.auth.login.LoginException;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
public class DiscordWhitelist extends JavaPlugin {
String statusMessage = "im a dumb bot";
String token = "REDACTED";
@Override
public void onEnable() {
try { //runs bot
JDA jda = new JDABuilder(token)
.addEventListeners(new DiscordHandlers())
.setActivity(Activity.playing(statusMessage))
.build();
jda.awaitReady();
System.out.println("Finished Building JDA!");
} catch (LoginException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onDisable() {
}
}
plugins {
id 'java'
}
group 'wickn.discordwhitelist'
version '2.0'
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
mavenCentral() // for transitive dependencies
maven {
name 'm2-dv8tion'
url 'https://m2.dv8tion.net/releases'
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compile ('net.dv8tion:JDA:4.2.1_265')
}
test {
useJUnitPlatform()
}