diff options
Diffstat (limited to 'src/main/java/makamys/neodymium/util/ChatUtil.java')
-rw-r--r-- | src/main/java/makamys/neodymium/util/ChatUtil.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/makamys/neodymium/util/ChatUtil.java b/src/main/java/makamys/neodymium/util/ChatUtil.java new file mode 100644 index 0000000..05b31cf --- /dev/null +++ b/src/main/java/makamys/neodymium/util/ChatUtil.java @@ -0,0 +1,57 @@ +package makamys.neodymium.util; + +import static makamys.neodymium.Neodymium.LOGGER; +import static makamys.neodymium.Neodymium.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 + } + +} |