summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DescriptionHelpTopic.java
blob: ae88ea2c6b150fb0ce78da5113143a58f92e900a (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
package io.dico.dicore.command.chat.help.defaults;

import io.dico.dicore.command.Command;
import io.dico.dicore.command.EMessageType;
import io.dico.dicore.command.ExecutionContext;
import io.dico.dicore.command.ICommandAddress;
import io.dico.dicore.Formatting;
import io.dico.dicore.command.chat.help.IHelpComponent;
import io.dico.dicore.command.chat.help.IHelpTopic;
import io.dico.dicore.command.chat.help.SimpleHelpComponent;
import org.bukkit.permissions.Permissible;

import java.util.ArrayList;
import java.util.List;

public class DescriptionHelpTopic implements IHelpTopic {

    @Override
    public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) {
        List<IHelpComponent> out = new ArrayList<>();
        Formatting format = context.getFormat(EMessageType.DESCRIPTION);

        if (!target.hasCommand()) {
            return out;
        }
        Command command = target.getCommand();
        String[] description = command.getDescription();
        if (description.length == 0) {
            String shortDescription = command.getShortDescription();
            if (shortDescription == null) {
                return out;
            }

            description = new String[]{shortDescription};
        }

        for (int i = 0; i < description.length; i++) {
            description[i] = format + description[i];
        }

        out.add(new SimpleHelpComponent(description));
        return out;
    }

}