aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/util/ChatUtil.java
blob: 7c2337f5dca55fd7b348631ce7310faac839464c (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
package makamys.neodymium.util;

import static makamys.neodymium.Constants.LOGGER;
import static makamys.neodymium.Constants.MODID;

import java.util.HashSet;
import java.util.Set;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;

public class ChatUtil {
    
    private static Set<String> shownChatMessages = new HashSet<>();
    
    public static void showChatMessage(String text) {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        
        if(player != null) {
            ChatComponentText cc = new ChatComponentText(text);
            player.addChatComponentMessage(cc);
        } else {
            LOGGER.info(text);
        }
    }
    
    public static void showNeoChatMessage(String text, MessageVerbosity verbosity) {
        showNeoChatMessage(text, verbosity, false);
    }
    
    public static void showNeoChatMessage(String text, MessageVerbosity verbosity, boolean once) {
        if(shownChatMessages.contains(text)) return;
        
        String verbosityText =
                verbosity == MessageVerbosity.WARNING
                    ? EnumChatFormatting.YELLOW + "WARNING"
                : verbosity == MessageVerbosity.ERROR
                    ? EnumChatFormatting.RED + "ERROR"
                :
                    "INFO";
                
        ChatUtil.showChatMessage("" + "[" + EnumChatFormatting.LIGHT_PURPLE + MODID + EnumChatFormatting.RESET + "/" + verbosityText + EnumChatFormatting.RESET + "] " + text);
        
        shownChatMessages.add(text);
    }
    
    public static void resetShownChatMessages() {
        shownChatMessages.clear();
    }
    
    public static enum MessageVerbosity {
        INFO, WARNING, ERROR
    }
    
}