Mystery Eclipse issue with magical nonimporting imports

I’ve tried to revisit an early command-handling demo program to share as requested with a bugfixer working on one of the github errors…

I’ve struggled and struggled with java.lang.reflect.InvocationTargetException error messages Caused by: java.lang.NoSuchMethodError: org.spongepowered.api.util.command.spec.CommandSpec$Builder.setDescription(Lorg/spongepowered/api/text/Text;)Lorg/spongepowered/api/util/command/spec/CommandSpec$Builder;

Which after a bunch of failed attempts to create even new projects, and rewrite the code from scratch, gives me the same results.

Then I noticed what was happening with new projects: I would click-import the command-hander classes to remove the squiggles, all good. Then when I saved the files, the cleaner/formatting system would remove the imports for my command handling classes, yet the red squiggles are gone.

If I comment out the command handling parts, the plugin loads fine, i can even add other code and event handlers. Uncomment the command registration code, plugin craps out with the errors above, with no import to my classes used.

package com.prennet.boomod.demo;

import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.state.PostInitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.scheduler.SynchronousScheduler;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.args.GenericArguments;
import org.spongepowered.api.util.command.spec.CommandSpec;

@Plugin(id = "Demo", name = "Demo", version = "1.0.0")
public class Demo {

    @Inject Logger logger;
    public static Game game;
    public SynchronousScheduler scheduler;

    @Subscribe
    public void preInit(PostInitializationEvent event) {
        game = event.getGame();
        scheduler = game.getSyncScheduler();

        game.getCommandDispatcher().register(this, CommandSpec.builder()
                .setDescription(Texts.of("Display a list of warps"))
                .setExecutor(new CmdWarps())
                .build()
                , "warps");

        game.getCommandDispatcher().register(this, CommandSpec.builder()
                .setDescription(Texts.of("Warp to a destination name"))
                .setExecutor(new CmdWarp(this))
                .setArguments(GenericArguments.onlyOne(GenericArguments.string(Texts.of("warpname"))))
                .build(), "warp");
    }
}

I’ve tried to disable the "Removed unused imports " and “oganize imports” part of the clean-up /formatter, it still wipes out even when I manually add the import. I have closed and opened exclipse many times, no change, opened or closed projects when shutting down, no matter.

======
I am at a total loss of what to do, or even if I am barking up the right tree on this - I dont doubt that there may be some other missing thing that I am overlooking in my project setup or such that is really responsible, and this other stuff is not relevant. I’ve also spent ages trying to clear a “add } to complete class” or whatever such error, when no } was requried, which eventually cleared by exporting the jar file with errors, then the error cleared from the file.

Eclipse Juno, Sponge profile for cleanup/formatting routines (with or without toggles mentioned above). Forge forge-1.8-11.14.3.1446-universal Sponge sponge-1.8-1446-2.1DEV-482
Compiling with 1.7 compatibility, running server with 1.7 java

There’s your problem.

That’s not useful. Eclipse is a supported environment for sponge plugin development.

3 Likes

You assume his nonhelpful answer was focused fully on “Eclipse” … he may have meant the problem was teh combination of my username “The Boomer” and using Eclipse :wink:

Just a joke. :stuck_out_tongue:

What does your pom.xml look like?

Like this:

http://pastebin.com/RM9tgYFe

The set prefix was removed.
The method is now description(Text)
you need to refresh the dependencies. Which in gradle is easy
gradlew eclipse --refresh-dependencies

Edit
Hmm OK, you use maven (simon816 invites you to join the gradlemasterrace)
Make sure you’ve followed https://docs.spongepowered.org/en/plugin/basics/workspace/dependencies.html
The SpongeAPI dependency should be version 2.1-SNAPSHOT

Ah, so it was a matter of various command handler methods being missing after all…
Attempting to make the required changes

Well, that seems to have helped a bit - updated a few things with the CommandSpec builder …
Now to figure out how to make the scheduler / taskbuilder work

Still, my import list doesn’t include my classes CmdWarps, CmdWarp yet they are not error-highlighted from missing…

Well they’re probably in the same package then, or not?

1 Like

Like @simon816 is saying, if your CmdWarps class is in the same package, eclipse won’t import it (nor does it need to).

Oh god, I feel dumb about that now. Side effect of rewritig it differently and having everything else suddenly behave weirdly :smile:
Yeah, they’re in the same package :smiley: