My Command dont work in game!

Hi! I am new to the forum and to the Sponge API and I try to make a plugin, but when I open the server the plugin commands don’t work.
I tried similar case solutions in the forum but none worked for me.
Here some photos of my plugin:

build.gradle

Main
package AppForm;

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.GameStartedServerEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;

import com.google.inject.Inject;

@Plugin(id = “sulybanlogin”, name =“LoginBan”, authors = “SulyBan”)
public class Main {

public static Main instance;

@Inject
Logger logger;

@Listener
public void onServerStart(GameStartedServerEvent event) {
	logger.info("Succesly running LoginPlugin!!");
	
	CommandSpec command = CommandSpec.builder()
			.permission("sulyban.command.base")	
			.description(Text.of("This commmand is for login o register new players!"))
			.executor(new LogIn())
			.build();
	
	Sponge.getCommandManager().register(instance, command, "Login","login");
	System.out.println("Funciona, repito esto funciona coronel!");
}

}

Command
package AppForm;

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.source.CommandBlockSource;
import org.spongepowered.api.command.source.ConsoleSource;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.serializer.TextSerializers;

public class LogIn implements CommandExecutor {

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	
	if(src instanceof Player) {
		Player player  = (Player) src;
		Text mensaje = TextSerializers.FORMATTING_CODE.deserialize("§2§k¡Hola §3§l"+player.getName()+"§2§kBienveido a §c§lSurvivalMods!");
		
		player.sendMessage(mensaje);
	}
	
	if (src instanceof ConsoleSource) {
		src.sendMessage(Text.of(TextColors.DARK_RED,"¡El server no tiene permiso para ejecutar este comando!"));
	}
	
	if(src instanceof CommandBlockSource) {
		src.sendMessage(Text.of(TextColors.DARK_RED,"¡El Bloque de comandos no tiene permiso para ejecutar este comando!"));
	}
	
	return CommandResult.success();
}

}

Thx for read and sorry for my english!

So a few things wrong with your code. First of all, commands can not register the same labels as another command within the same plugin. In your case your command is registering two labels, both of which are the same.

Sponge.getCommandManager().register(instance, command, "Login","login");

Not only that but sponge does not allow for commands to have upper case letters, therefore if you remove your first label, that should sort that issue.

Next issue is that your executor is registering a instance of “LogIn” while the class you gave us as your executor is “login”. As in there is a capital “I” in the setExecutor which is not present, therefore you arnt registering the same class as the executor. Change the executor to match your actual executor then it will work.

The last issue I can see is your registering your command with the plugin instance of “instance” however this field does not get a value applied to it, therefore your essentially registering your plugin as “Null” so give “instance” a value of “this” within the first Listener fired.

Need anymore help then a log would be nice. And posted on a site such as pastebin.com so it doesnt destroy formatting. Same goes with code (you can also put 4 spaces with code to put that line in a code box)

1 Like

OMG! Thanks, i changed everything you told me and now it works, thanks a lot again.

1 Like