Must override a superclass method? Please help!

No matter how I use this code, I always get an error:

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

This is copied directly from the sponge docs and I am trying to implement it into my command executor.

However, I get an error that it must override a superclass method. Any ideas?

the class you paste this in isn’t implementing CommandExcecutor, of which that method is a part.

if you change your class definition to public class MyClassName implements CommandExecutor, it’ll work

No, I have already done that.

Show you class code pls…

Here:

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.Text;

public class DPCommand implements CommandExecutor { 

	@Override
    public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    	if (args.getOne("itemid").isPresent() && (args.getOne("quantity").isPresent()) && (args.getOne("message").isPresent())) {
    		Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "give @a "+"itemid"+" "+"quantity");
            Sponge.getServer()
            .getBroadcastChannel()
            .send(Text.of("message"));
            return CommandResult.success();

} } }

Could you tell us which version of the API you’re using?

I’m using 4.1.0

Sponge Build:
4.1.0

Forge Build:
1.10.2

Java Version:
8

[spoiler “Forge Logs”]
[/spoiler] - ?

[spoiler “Minecraft Logs”]
[/spoiler] - ?

Plugin Source:

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.Text;

public class DPCommand implements CommandExecutor {

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (args.getOne("itemid").isPresent() && (args.getOne("quantity").isPresent()) && (args.getOne("message").isPresent())) {
		Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "give @a "+"itemid"+" "+"quantity");
        Sponge.getServer()
        .getBroadcastChannel()
        .send(Text.of("message"));
        return CommandResult.success();

} } }

Uh, just so you know, MC 1.10.2 is API 5.

At a guess, is your code and imports have errors all over it like this?

If so, your error isn’t that it can’t override from the super class, but it can’t find the superclass, so it isn’t aware that it’s supposed to be overriding a method from the super class.

With errors in programming if you have multiple errors, the compiler and IDE can get confused very very quickly, generally fix the first error you see first, until you get skilled enough to recognize what the real errors are.

To fix this you need to fix your project setup, you said that you are trying to target minecraft 1.10.2? For that you will need to compile against SpongeAPI 5.0.0-SNAPSHOT

The easiest way to set this up in my opinion, is to use the MinecraftDev intellij plugin.

this will allow you to have a set up project very very quickly.

1 Like