Problems with my plugin

So I’ve been working on this for about 5 hours. I’ve tried different builds of the Sponge Server as well as the Forge server when trying to run my test server. I built a simple plugin and for whatever reason, it will say the “mod” is loaded, but none of my code seems to run.

I’ve tried using the built in logger, a custom logger and even System.out and none of them seem to print anything to the console.

I tried a few different plugins to see if they would work, and they did. So I then looked at the code of those plugins and implemented it into my own, replacing the code I had. Still, I had nothing.

This is what I have now:

@Plugin(id = "ServerControl", name = "ServerControl", version = "1.0-DEV")
public class ServerControl {

	private org.slf4j.Logger logger;

	@Inject
	public void setLogger(org.slf4j.Logger logger) {
		this.logger = logger;
	}

	@Subscribe
	public void onServerStart(ServerStartedEvent event) {
		//log.setupLogger(logger);
		logger.info("Working");
		//log.info("Initialized ServerControl");
	}
}

Keep in mind that many events are current unimplemented. It’s entirely possible that that’s the cause of this issue, as has been posted in nearly every resource available.

I tried a few different ways of implementing the logger, and I used almost all of the different initialization events.

@Inject
private org.slf4j.Logger logger;

edit: woo, i ninja’d someone.

If you want a logger instance, you need to use the @Inject annotation for private Logger.

I tried that, and it didn’t work. I’m so confused. It works for other people, but not for me. I can usually figure this stuff out on my own, but 5 hours of modifications and research didn’t do the trick

How are you running your plugin? Exporting a jar to the mods folder? Running Sponge in IDE?

Exporting to the mods folder.

Make sure the @Inject class is com.google and not Java’s

1 Like

It is. I’m so lost. Is there maybe some other information I could give you? Like the artifacts or something?

EDIT: I just tried creating a plugin using Eclipse instead of Intellij, and this time Forge realized it was a non-mod file. When creating and building the plugin in Intellij it marks it as a mod file.

try this:

@Inject
private org.slf4j.Logger logger;

public Logger getLogger() {
    return logger;
}

Rather, to know you’re using the right Inject.

@com.google.inject.Inject private org.slf4j.Logger logger;

1 Like

Doesn’t matter what I do. It still doesn’t seem to work.

I would recommend sitting on your thumbs, then. That’s what I do. :smile:

Lets get a bit more information,

  • Sponge Build
  • Forge Build
  • Client Type/Version (Forge/Vanilla and version)
  • Installed Plugins and/or Mods
  • Java Version
  • Operating System

Additionally if you could gist the complete source code that you’re trying to run it may help with replicating your issue.

3 Likes

Sponge Build: 1.8-1371-2.1DEV-433
Forge Build: 11.14.1.1397
I don’t have it installed in my client I was just testing by starting up the server.
I don’t have any other plugins or mods installed
I’m using JRE 1.8_20 or something like that
I’m using Windows 8.1

I feel like I have narrowed it down to the way I’m building it, because other plugins work just fine, none of mine, even when building with another IDE it doesn’t work.

Alright, the first thing I notice is you are targetting a very old version of SpongeAPI in your pom file, you should be targetting at least version 2.0.

The impact this version upgrade has on your code is that the Subscribe annotation was moved from util.event to just the event package. Once that is fixed and I run the server I see the message as I would expect.

[17:26:28] [Server thread/INFO] [ServerControl]: Working

1 Like

When I put 2.0 in there it returns an error (I only just started using Maven, I never used to like it because I never understood it, so I’m just now giving it a chance).

EDIT: well dang. Now I just feel like a darn fool that fixed it. What’s the latest version I can target?

According to the maven repo, you can target “2.0” or “2.1-SNAPSHOT”

2 Likes

2.0 will work. If you’re getting an error, you likely need to update your Maven Indices.

1 Like