summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/chat/AbstractChatHandler.java
blob: ac2a76d69777ec52a47c930a0988050daa6293b5 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package io.dico.dicore.command.chat;

import io.dico.dicore.Formatting;
import io.dico.dicore.command.EMessageType;
import io.dico.dicore.command.ExecutionContext;
import io.dico.dicore.command.ICommandAddress;
import io.dico.dicore.command.chat.help.HelpPages;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class AbstractChatHandler implements IChatHandler {
    private @NotNull HelpPages helpPages;

    public AbstractChatHandler(@NotNull HelpPages helpPages) {
        this.helpPages = helpPages;
    }

    public AbstractChatHandler() {
        this(HelpPages.newDefaultHelpPages());
    }

    @NotNull
    public HelpPages getHelpPages() {
        return helpPages;
    }

    public void setHelpPages(@NotNull HelpPages helpPages) {
        this.helpPages = helpPages;
    }

    @Override
    public Formatting getChatFormatForType(EMessageType type) {
        switch (type) {
            case EXCEPTION:
            case BAD_NEWS:
                return Formatting.RED;
            case INSTRUCTION:
            case NEUTRAL:
                return Formatting.GRAY;
            case CUSTOM:
                return Formatting.WHITE;
            case INFORMATIVE:
                return Formatting.AQUA;
            case RESULT:
            default:
            case GOOD_NEWS:
                return Formatting.GREEN;
            case WARNING:
                return Formatting.YELLOW;

            case DESCRIPTION:
                return Formatting.GREEN;
            case SYNTAX:
                return Formatting.AQUA;
            case HIGHLIGHT:
                return Formatting.RED;
            case SUBCOMMAND:
                return Formatting.GRAY;
            case NUMBER:
                return Formatting.YELLOW;
        }
    }

    @Override
    public String getMessagePrefixForType(EMessageType type) {
        return "";
    }

    protected String createMessage(EMessageType type, String message) {
        if (message == null || message.isEmpty()) return null;
        return getMessagePrefixForType(type) + getChatFormatForType(type) + message;
    }

    @Override
    public String createMessage(ExecutionContext context, EMessageType type, String message) {
        return createMessage(type, message);
    }

    @Override
    public String createMessage(CommandSender sender, EMessageType type, String message) {
        return createMessage(type, message);
    }

    @Override
    public String createHelpMessage(CommandSender sender, ExecutionContext context, ICommandAddress address, int page) {
        return helpPages.getHelpPage(sender, context, address, page);
    }

    @Override
    public String createSyntaxMessage(CommandSender sender, ExecutionContext context, ICommandAddress address) {
        return helpPages.getSyntax(sender, context, address);
    }

}