aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/numerouscommands/ModInfo.java
blob: 15f4522ae51b8a84a2b5ae0756f1c031cc9fcf06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package de.cowtipper.cowlection.numerouscommands;

import de.cowtipper.cowlection.command.NumerousCommandsCommand;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.ModMetadata;

import java.util.*;

public class ModInfo {
    private final String name;
    private final ModMetadata metadata;
    private final Set<String> ownedPackages;
    private final Map<String, CommandInfo> commands;
    private final boolean hasUpdate;

    public ModInfo(ModContainer mod) {
        name = mod.getName();
        metadata = mod.getMetadata();
        ownedPackages = new HashSet<>(mod.getOwnedPackages());
        commands = new TreeMap<>();
        hasUpdate = ForgeVersion.getResult(mod).status == ForgeVersion.Status.OUTDATED;
    }

    public ModInfo() {
        name = "Unknown mod";
        metadata = new ModMetadata();
        metadata.modId = "unknownmodwithoutanid";
        metadata.name = name;
        metadata.authorList = Collections.singletonList(EnumChatFormatting.ITALIC + "Unknown");
        ownedPackages = new HashSet<>();
        commands = new TreeMap<>();
        hasUpdate = false;
    }

    public void addCommand(ICommand cmd, ICommandSender sender) {
        CommandInfo commandInfo = new CommandInfo(cmd, sender);
        if (cmd instanceof NumerousCommandsCommand) {
            commandInfo.setIsListCommandsCommand();
        }
        commands.put(cmd.getClass().getSimpleName() + cmd.getCommandName(), commandInfo);
    }

    public String getName() {
        return name;
    }

    public ModMetadata getModMetadata() {
        return metadata;
    }

    public Collection<CommandInfo> getCommands() {
        return commands.values();
    }

    public int getCommandsCount() {
        return commands.size();
    }

    public boolean hasUpdate() {
        return hasUpdate;
    }

    public boolean isOwnedPackage(String packAge) {
        return ownedPackages.contains(packAge);
    }
}