I have changed the events to PlayerLogged(In/Out)Event, so now the entire class looks like this:
@Mod("creatediscord")
public class CreateDiscord {
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public CreateDiscord() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event) {
// some preinit code
LOGGER.info("Running CreateDiscord");
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
// do something when the server starts
JDABuilder jdaBuilder = JDABuilder.createDefault("Bot token :)");
JDA jda;
//ENABLE STUFF
jdaBuilder.addEventListeners(new RegistryEvents());
//ACTIVITY
jdaBuilder.setStatus(OnlineStatus.IDLE);
try {
jda = jdaBuilder.build();
} catch (LoginException e) {
e.printStackTrace();
}
}
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber
public static class RegistryEvents extends ListenerAdapter {
public static TextChannel textChannel;
@SubscribeEvent
public static void onEvent(PlayerEvent.PlayerLoggedInEvent e) {
// register join
textChannel.sendMessage(e.getPlayer().getDisplayName().getString() + " joined the game").queue();
}
@SubscribeEvent
public static void onEvent(PlayerEvent.PlayerLoggedOutEvent e) {
// register leave
textChannel.sendMessage(e.getPlayer().getDisplayName().getString() + " left the game").queue();
}
public void onReady(ReadyEvent e) {
textChannel = e.getJDA().getTextChannelById("Channel ID :)");
}
}
}
My build.gradle looks like this:
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '4.0.0'
id 'java'
}
apply plugin: 'net.minecraftforge.gradle'
// extraLine "PK: org/apache/commons/collections4 me/sansserif/org/apache/commons/collections4"
group = 'me.sansserif'
version = '1.0'
archivesBaseName = 'CreateDiscord'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
shadowJar {
// Relocate fluent-hc to prevent conflicts with other mods that include it
//relocate 'org.apache.commons.collections.collections4', 'me.sansserif.org.apache.commons.collections4'
configurations = [project.configurations.shadow]
classifier ''
relocate('org.apache.commons', 'org.creatediscord.apache.commons') //relocated packages needed by JDA
relocate('gnu.trove', 'gnu.creatediscord.trove')
}
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20210309-1.16.5'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
creatediscord {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
creatediscord {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'creatediscord', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
creatediscord {
source sourceSets.main
}
}
}
}
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
configurations {
shade
compile.extendsFrom shade
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
shadow 'net.dv8tion:JDA:4.2.1_253' //the discord api
shadow 'org.apache.commons:commons-collections4:4.4' //a package needed by jda
shadow 'gnu.trove:trove:3.0.3' //when i started the mod, it threw NoClassDefFoundError, so I added it too
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.16.5-36.1.4'
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// These dependencies get remapped to your current MCP mappings
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"Specification-Title" : "creatediscord",
"Specification-Vendor" : "SansSerif",
"Specification-Version" : "1", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.version,
"Implementation-Vendor" : "SansSerif",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
configurations.shade.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}
}
project.tasks.build.dependsOn shadowJar
jar.finalizedBy('reobfJar')
But even after changing the events to PlayerLogged..Event, it throws this:
[08:16:10] [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: 'net.minecraft.util.text.ITextComponent net.minecraft.entity.player.PlayerEntity.getDisplayName()'
Index: 2
Listeners:
0: NORMAL
1: ASM: net.minecraftforge.common.ForgeInternalHandler@38a07bdc playerLogin(Lnet/minecraftforge/event/entity/player/PlayerEvent$PlayerLoggedInEvent;)V
2: ASM: class me.sansserif.creatediscord.CreateDiscord$RegistryEvents onEvent(Lnet/minecraftforge/event/entity/player/PlayerEvent$PlayerLoggedInEvent;)V
java.lang.NoSuchMethodError: 'net.minecraft.util.text.ITextComponent net.minecraft.entity.player.PlayerEntity.getDisplayName()'
at me.sansserif.creatediscord.CreateDiscord$RegistryEvents.onEvent(CreateDiscord.java:72)
at net.minecraftforge.eventbus.ASMEventHandler_15_RegistryEvents_onEvent_PlayerLoggedInEvent.invoke(.dynamic)
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:44)
at net.minecraft.server.management.PlayerList.func_72355_a(PlayerList.java:231)
at net.minecraft.network.login.ServerLoginNetHandler.func_147326_c(ServerLoginNetHandler.java:118)
at net.minecraft.network.login.ServerLoginNetHandler.func_73660_a(ServerLoginNetHandler.java:65)
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:222)
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:134)
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:865)
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:291)
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:787)
at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:642)
at net.minecraft.server.MinecraftServer.func_240783_a_(MinecraftServer.java:232)
at java.base/java.lang.Thread.run(Thread.java:834)
[08:16:12] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
java.lang.NoSuchMethodError: 'net.minecraft.util.text.ITextComponent net.minecraft.entity.player.PlayerEntity.getDisplayName()'
at me.sansserif.creatediscord.CreateDiscord$RegistryEvents.onEvent(CreateDiscord.java:72) ~[creatediscord:1.0] {re:classloading}
at net.minecraftforge.eventbus.ASMEventHandler_15_RegistryEvents_onEvent_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?] {}
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:44) ~[forge:?] {re:classloading}
at net.minecraft.server.management.PlayerList.func_72355_a(PlayerList.java:231) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
at net.minecraft.network.login.ServerLoginNetHandler.func_147326_c(ServerLoginNetHandler.java:118) ~[?:?] {re:classloading}
at net.minecraft.network.login.ServerLoginNetHandler.func_73660_a(ServerLoginNetHandler.java:65) ~[?:?] {re:classloading}
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:222) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:134) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:865) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:291) ~[?:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:787) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:642) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.server.MinecraftServer.func_240783_a_(MinecraftServer.java:232) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at java.lang.Thread.run(Thread.java:834) [?:?] {}
[08:16:13] [Server thread/FATAL] [ne.mi.co.ForgeMod/]: Preparing crash report with UUID b9d7c1a7-859d-4190-a0bc-74c8187051af
EDIT: I didnt really answer the question how did I create the mod Jar, I just press Run in IntelliJ and copy the projectdir/build/libs/mod.jar to the serverdir/mods/
Also, thanks for a fast reply and have a good day!