Plugin Logger does not do anything

Hey, just started sponge plugin development, so please bear with me :slight_smile:

I’m trying to show a simple info-message as shown in a tutorial, however, my plugin doesn’t want to. it shows up in the logs and goes trough all the various States but does not do anything.

Sponge Build:spongeforge-1.10.2-2171-5.1.0-BETA-2003
Forge Build:12.18.3.2185
Java Version:openJDK 64-Bit Server VM, version 1.8.0_121

Forge Logs:
[…]
[15:15:17] [main/DEBUG] [FML/]: Examining for coremod candidacy DemoKrat.jar
[15:15:17] [main/DEBUG] [FML/]: Not found coremod data in DemoKrat.jar
[…]
[15:15:50] [Server thread/DEBUG] [FML/]: Examining file DemoKrat.jar for potential mods
[15:15:50] [Server thread/TRACE] [FML/]: Located mcmod.info file in file DemoKrat.jar
[15:15:50] [Server thread/DEBUG] [FML/]: Identified a mod of type Lorg/spongepowered/api/plugin/Plugin; (com.redfx.demokrat.DemoKrat) - loading
[15:15:50] [Server thread/INFO] [FML/]: Forge Mod Loader has identified 6 mods to load
[15:15:50] [Server thread/TRACE] [FML/]: Received a system property request ‘’
[15:15:50] [Server thread/TRACE] [FML/]: System property request managing the state of 0 mods
[…]
[15:15:50] [Server thread/TRACE] [FML/]: All mod requirements are satisfied
[15:15:50] [Server thread/TRACE] [FML/]: Sorting mods into an ordered list
[15:15:50] [Server thread/TRACE] [FML/]: Mod sorting completed successfully
[15:15:50] [Server thread/DEBUG] [FML/]: Mod sorting data
[15:15:50] [Server thread/DEBUG] [FML/]: demokrat(DemoKrat:0.1): DemoKrat.jar ()
[…]
[15:15:51] [Server thread/INFO] [FML/FML]: Attempting connection with missing mods [mcp, FML, Forge, spongeapi, sponge, demokrat] at CLIENT
[15:15:51] [Server thread/INFO] [FML/FML]: Attempting connection with missing mods [mcp, FML, Forge, spongeapi, sponge, demokrat] at SERVER
[… sending events to plugin…]
[15:15:53] [Server thread/TRACE] [demokrat/demokrat]: Sending event FMLInitializationEvent to mod demokrat
[15:15:53] [Server thread/TRACE] [demokrat/demokrat]: Sent event FMLInitializationEvent to mod demokrat
[15:15:53] [Server thread/DEBUG] [FML/]: Bar Step: Initialization - DemoKrat took 0,001s
[15:15:53] [Server thread/DEBUG] [FML/]: Bar Finished: Initialization took 0,072s

Plugin Source:

package com.redfx.demokrat;


import com.google.inject.Inject;
import com.redfx.demokrat.commands.VoteResult;

import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;

import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;



@Plugin(id = "demokrat", name = "DemoKrat", version = "1.0")
public class DemoKrat {
	
	
	private Logger logger;
	
	@Inject
	private Logger getLogger() {
		return logger;
	}
	
	@Listener
	private void onInitialize(GameInitializationEvent event) {
		this.getLogger().info("Demokrat is Enabled");
	}
}

thanks in advance.

Put the @Inject annotation on the field instead of the method

Ok I tried rebuilded jars two times with @Inject on the field,still no luck, sadly :confused:

it must be smth else

Info doesn’t show up in initialization; otherwise there would be a massive amount of mixin spam. Just for testing purposes, try using error instead.

Still no Luck…could there be something wrong with my gradle configuration although the class file and my mcmod.info is present in the archive?

Gradle shouldn’t mess with that.

Weird, that looks like functional code. Not sure what could be wrong. Are you sure you compiled it and put it in the server correctly? :stuck_out_tongue:

100% sure :grin: :

[17:15:02] [Server thread/DEBUG] [FML/]: Identified a mod of type Lorg/spongepowered/api/plugin/Plugin; (com.redfx.demokrat.DemoKrat) - loading
[17:15:02] [Server thread/DEBUG] [FML/]: 	demokrat(DemoKrat:1.0): DemoKrat.jar ()

It also gets the event:
[17:15:04] [Server thread/TRACE] [demokrat/demokrat]: Sending event FMLInitializationEvent to mod demokrat
[17:15:04] [Server thread/TRACE] [demokrat/demokrat]: Sent event FMLInitializationEvent to mod demokrat
[17:15:04] [Server thread/DEBUG] [FML/]: Bar Step: Initialization - DemoKrat took 0,001s
[17:15:04] [Server thread/DEBUG] [FML/]: Bar Finished: Initialization took 0,060s

Private event listeners are not supported. All event listeners must be public methods.

1 Like

Ohhhh there we go.

Incidentally, why?

We generate event handler classes using ASM at runtime for optimal performance. Since these classes invoke the event listener methods using regular method calls, it will only work if they are visible for the event handler class.

Could Sponge issue a warning if someone tries to register a listener with an invalid listener method?

2 Likes

but what about setVisible? it just seems like poor practices to have your public-facing API allow manual invocation of listener methods

I thought we did. Feel free to open an issue on SpongeCommon.

Even though there is no method setVisible it wouldn’t work anyway because you can only bypass access restrictions when invoking methods using reflection, not with direct method calls. There is also no need to expose it as public API, you could have an interface implemented by your main plugin class which exposes only the needed methods.

Decided not to. I made a PR instead. :wink:

1 Like

This functionality on MinecraftDev would be great too

2 Likes