My custom command in Forge 1.12.1 is not working

1.5k Views Asked by At

So I made a class that implements ICommand and registered it in my ServerStarting event. When I try to execute the command in Minecraft, I get a no permission error. Here's my ICommand implemented class:

List aliases;

public CMinecraftStoryMod() {
    aliases = new ArrayList();
    aliases.add("msm");
}

@Override
public String getName() {
    return "minecraftstorymod";
}

@Override
public String getUsage(ICommandSender sender) {
    if (sender.getEntityWorld().isRemote) {
        return "/minecraftstorymod";
    } else {
        return "/minecraftstorymod";
    }
}

@Override
public List<String> getAliases() {
    return aliases;
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (!MinecraftStoryMod.gameInProgress) {
        MinecraftStoryMod.gameInProgress = true;

        if (sender.getEntityWorld().isRemote) {
            sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Attempting to start game in a multiplayer world..."));
            sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Checking out the number of players in this world..."));
            if (server.getPlayerList().getCurrentPlayerCount() > 0) {
                sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] There are " + server.getPlayerList().getCurrentPlayerCount() + " players in the server! Generating fun..."));
                MinecraftStoryMod.gameHandler.startGame(server.getPlayerList());
            } else {
                sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] The server has 0 players!"));
                MinecraftStoryMod.gameInProgress = false;
                return;
            }
        } else {
            sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Singleplayer mode for this mod is still under construction. We're sowwy :)"));
            return;
        }
    } else {
        sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Another game is in progress! Wait for it ._."));
    }
}

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
    return false;
}

@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
    return null;
}

@Override
public boolean isUsernameIndex(String[] args, int index) {
    return false;
}

@Override
public int compareTo(ICommand o) {
    return 0;
}

I know I registered my command properly because I can type /minecraftstorymod in game. I'm using Forge 1.12.1 14.22.0.2469

1

There are 1 best solutions below

2
On BEST ANSWER

You're always returning false from the checkPermission method, meaning that nobody has permission to execute the command. You can always return true if you want anybody to be able to execute the command or return a different value depending on the sender.