feat: made timestamp optional thru config
This commit is contained in:
parent
6eef1d1fab
commit
fabf10cfaa
|
@ -8,9 +8,13 @@ public class Config {
|
|||
public static int portNumber = 8069;
|
||||
public static String ipAddress = "127.0.0.1";
|
||||
public static String authToken = "";
|
||||
public static boolean addTimestamp = false;
|
||||
public static Configuration configuration;
|
||||
|
||||
public static void synchronizeConfiguration() {
|
||||
addTimestamp = configuration
|
||||
.getBoolean("Add timestamp", Configuration.CATEGORY_GENERAL, addTimestamp, "Add timestamp to messages");
|
||||
|
||||
configuration.addCustomCategoryComment(CATEGORY_WEBSOCKET, "Configuration for the websocket");
|
||||
portNumber = configuration
|
||||
.getInt("Port", CATEGORY_WEBSOCKET, portNumber, 1024, 65535, "The Port that the websocket will listen on");
|
||||
|
|
|
@ -9,12 +9,14 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import moe.yuyui.mcstreamerbot.Config;
|
||||
import moe.yuyui.mcstreamerbot.common.beans.MessageBean;
|
||||
import moe.yuyui.mcstreamerbot.common.beans.UserBean;
|
||||
|
||||
public final class OnChatMessage {
|
||||
|
||||
private static final String _messageFormat = "<%s> %s%s[%s]%s: %s";
|
||||
private static final String _messageFormat = "%s%s[%s]%s: %s";
|
||||
private static final String _timestampedMessageFormat = "<%s>";
|
||||
|
||||
private static String buildMessage(List<MessageBean> messageParts) {
|
||||
StringBuilder finalMessage = new StringBuilder();
|
||||
|
@ -58,19 +60,26 @@ public final class OnChatMessage {
|
|||
return;
|
||||
}
|
||||
final String message = buildMessage(messageParts);
|
||||
final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("hh:mm:ss a");
|
||||
final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("hh:mm a");
|
||||
final String formattedTime = Instant.ofEpochSecond(timestamp)
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.format(dateFormatter);
|
||||
ChatComponentText chatComponentText = new ChatComponentText(
|
||||
StringBuilder chatMessage = new StringBuilder();
|
||||
|
||||
if (Config.addTimestamp) {
|
||||
chatMessage.append(String.format(_timestampedMessageFormat, formattedTime));
|
||||
}
|
||||
|
||||
chatMessage.append(
|
||||
String.format(
|
||||
_messageFormat,
|
||||
formattedTime,
|
||||
getUserColor(user),
|
||||
getUserBadge(user),
|
||||
user.getName(),
|
||||
EnumChatFormatting.RESET.toString(),
|
||||
message.replace('§', ' ')));
|
||||
|
||||
ChatComponentText chatComponentText = new ChatComponentText(chatMessage.toString());
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI()
|
||||
.printChatMessage(chatComponentText);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package moe.yuyui.mcstreamerbot.gui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
import moe.yuyui.mcstreamerbot.Config;
|
||||
import moe.yuyui.mcstreamerbot.MCStreamerBot;
|
||||
|
||||
|
@ -13,12 +18,11 @@ public class MCStreamerBotGuiConfig extends GuiConfig {
|
|||
public MCStreamerBotGuiConfig(GuiScreen parent) {
|
||||
super(
|
||||
parent,
|
||||
new ConfigElement<>(Config.configuration.getCategory(Config.CATEGORY_WEBSOCKET)).getChildElements(),
|
||||
getConfigElements(),
|
||||
MCStreamerBot.MODID,
|
||||
true,
|
||||
false,
|
||||
"Configure the Websocket.");
|
||||
titleLine2 = "Make sure you know what you're doing ;)";
|
||||
false,
|
||||
"Configure the Streamer.bot integration.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,4 +39,12 @@ public class MCStreamerBotGuiConfig extends GuiConfig {
|
|||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
private static List<IConfigElement> getConfigElements() {
|
||||
Configuration config = Config.configuration;
|
||||
return config.getCategoryNames()
|
||||
.stream()
|
||||
.map(name -> new ConfigElement<>(config.getCategory(name)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user