我在Forge 1.12.1中的自定义命令不起作用

时间:2017-09-09 10:56:44

标签: java minecraft minecraft-forge

所以我创建了一个实现ICommand的类,并在我的ServerStarting事件中注册了它。当我尝试在Minecraft中执行命令时,我得到一个无权限错误。这是我的ICommand实现的类:

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;
}

我知道我正确地注册了我的命令,因为我可以在游戏中键入/ minecraftstorymod。我使用的是Forge 1.12.1 14.22.0.2469

1 个答案:

答案 0 :(得分:1)

您总是从false方法返回checkPermission,这意味着没有人有权执行该命令。如果您希望任何人能够执行命令或根据发件人返回不同的值,您始终可以返回true