First upload

First upload working on it still having trouble with issues not showing the username but this is a start
This commit is contained in:
minster586
2026-10-26 05:14:12 -04:00
parent 514423725e
commit 90666d0ac9
25 changed files with 1999 additions and 1 deletions
@@ -0,0 +1,179 @@
package dev.streamchat;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import java.util.List;
public final class StreamChatScreen extends Screen {
private static final List<String> TWITCH_EVENTS =
List.of("ChatMessage", "Follow", "Sub", "ReSub", "GiftSub", "Cheer", "Raid");
private static final List<String> YOUTUBE_EVENTS =
List.of("Message", "SuperChat", "SuperSticker", "MemberMilestone", "NewSponsor", "GiftMembershipReceived");
private static final List<String> TIKTOK_EVENTS =
List.of("chat", "gift", "share", "follow", "like", "roomUser", "subscribe");
private final Screen parent;
private final StreamChatConfig config;
private final ConnectionManager connections;
private Platform selectedPlatform = Platform.TWITCH;
private EditBox streamerBotUrl;
private EditBox streamerBotPassword;
private EditBox tikFinityUrl;
private EditBox prefix;
private EditBox template;
public StreamChatScreen(Screen parent, StreamChatConfig config, ConnectionManager connections) {
super(Component.literal("Stream Chat Settings"));
this.parent = parent;
this.config = config;
this.connections = connections;
}
@Override
protected void init() {
int left = width / 2 - 190;
int rowWidth = 380;
int buttonWidth = 120;
addRenderableWidget(Button.builder(toggleLabel(Platform.TWITCH), button -> {
config.twitchEnabled = !config.twitchEnabled;
button.setMessage(toggleLabel(Platform.TWITCH));
}).bounds(left, 28, buttonWidth, 20).build());
addRenderableWidget(Button.builder(toggleLabel(Platform.YOUTUBE), button -> {
config.youtubeEnabled = !config.youtubeEnabled;
button.setMessage(toggleLabel(Platform.YOUTUBE));
}).bounds(left + 130, 28, buttonWidth, 20).build());
addRenderableWidget(Button.builder(toggleLabel(Platform.TIKTOK), button -> {
config.tiktokEnabled = !config.tiktokEnabled;
button.setMessage(toggleLabel(Platform.TIKTOK));
}).bounds(left + 260, 28, buttonWidth, 20).build());
streamerBotUrl = new EditBox(font, left, 75, rowWidth, 20, Component.literal("Streamer.bot WebSocket URL"));
streamerBotUrl.setValue(config.streamerBotUrl);
streamerBotUrl.setMaxLength(256);
addRenderableWidget(streamerBotUrl);
streamerBotPassword = new EditBox(font, left, 105, rowWidth, 20, Component.literal("Streamer.bot password"));
streamerBotPassword.setValue(config.streamerBotPassword);
streamerBotPassword.setMaxLength(256);
streamerBotPassword.setSuggestion("Streamer.bot password (stored in config file)");
addRenderableWidget(streamerBotPassword);
tikFinityUrl = new EditBox(font, left, 135, rowWidth, 20, Component.literal("TikFinity WebSocket URL"));
tikFinityUrl.setValue(config.tikFinityUrl);
tikFinityUrl.setMaxLength(256);
addRenderableWidget(tikFinityUrl);
addRenderableWidget(Button.builder(Component.literal("Streamer.bot: " + (config.streamerBotEnabled ? "On" : "Off")),
button -> {
config.streamerBotEnabled = !config.streamerBotEnabled;
button.setMessage(Component.literal("Streamer.bot: " + (config.streamerBotEnabled ? "On" : "Off")));
}).bounds(left, 165, 180, 20).build());
addRenderableWidget(Button.builder(Component.literal("TikFinity: " + (config.tikFinityEnabled ? "On" : "Off")),
button -> {
config.tikFinityEnabled = !config.tikFinityEnabled;
button.setMessage(Component.literal("TikFinity: " + (config.tikFinityEnabled ? "On" : "Off")));
}).bounds(left + 200, 165, 180, 20).build());
addRenderableWidget(Button.builder(Component.literal("Twitch"), button -> select(Platform.TWITCH))
.bounds(left, 200, 120, 20).build());
addRenderableWidget(Button.builder(Component.literal("YouTube"), button -> select(Platform.YOUTUBE))
.bounds(left + 130, 200, 120, 20).build());
addRenderableWidget(Button.builder(Component.literal("TikTok"), button -> select(Platform.TIKTOK))
.bounds(left + 260, 200, 120, 20).build());
prefix = new EditBox(font, left, 230, rowWidth, 20, Component.literal("Platform prefix"));
prefix.setValue(config.getPrefix(selectedPlatform));
prefix.setMaxLength(128);
addRenderableWidget(prefix);
template = new EditBox(font, left, 270, rowWidth, 20, Component.literal("Message format"));
template.setValue(config.templates.getOrDefault(selectedPlatform.name(),
"{prefix}{username} > {message}"));
template.setMaxLength(256);
addRenderableWidget(template);
addRouteButtons(left);
addRenderableWidget(Button.builder(Component.literal("Toggle connections"), button -> connections.toggleConnections())
.bounds(left, height - 32, 180, 20).build());
addRenderableWidget(Button.builder(Component.literal("Done"), button -> onClose())
.bounds(left + 200, height - 32, 180, 20).build());
}
@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
renderBackground(graphics);
graphics.drawCenteredString(font, title, width / 2, 8, 0xFFFFFF);
int left = width / 2 - 190;
graphics.drawString(font, "Streamer.bot / TikFinity WebSocket settings", left, 60, 0xA0A0A0);
graphics.drawString(font, "Connection status: " + connections.status(selectedPlatform), left, 188, 0xFFFFFF);
graphics.drawString(font, "Last event: " + connections.lastEvent(selectedPlatform), left + 180, 188, 0xA0A0A0);
graphics.drawString(font, "Prefix", left, 220, 0xA0A0A0);
graphics.drawString(font, "Format: {prefix}, {platform}, {event}, {username}, {message}", left, 256, 0xA0A0A0);
graphics.drawString(font, "Event destination (click to cycle)", left, 296, 0xA0A0A0);
super.render(graphics, mouseX, mouseY, delta);
}
@Override
public void onClose() {
config.streamerBotUrl = streamerBotUrl.getValue().trim();
config.streamerBotPassword = streamerBotPassword.getValue();
config.tikFinityUrl = tikFinityUrl.getValue().trim();
config.prefixes.put(selectedPlatform.name(), prefix.getValue());
config.templates.put(selectedPlatform.name(), template.getValue());
config.save();
connections.configurationChanged();
minecraft.setScreen(parent);
}
private void select(Platform platform) {
config.streamerBotUrl = streamerBotUrl.getValue().trim();
config.streamerBotPassword = streamerBotPassword.getValue();
config.tikFinityUrl = tikFinityUrl.getValue().trim();
config.prefixes.put(selectedPlatform.name(), prefix.getValue());
config.templates.put(selectedPlatform.name(), template.getValue());
selectedPlatform = platform;
prefix.setValue(config.getPrefix(platform));
template.setValue(config.templates.getOrDefault(platform.name(),
"{prefix}{username} > {message}"));
rebuildRoutes();
}
private void rebuildRoutes() {
clearWidgets();
init();
}
private void addRouteButtons(int left) {
List<String> events = switch (selectedPlatform) {
case TWITCH -> TWITCH_EVENTS;
case YOUTUBE -> YOUTUBE_EVENTS;
case TIKTOK -> TIKTOK_EVENTS;
};
for (int i = 0; i < events.size(); i++) {
String eventType = events.get(i);
int x = left + (i % 2) * 195;
int y = 320 + (i / 2) * 24;
addRenderableWidget(Button.builder(routeLabel(eventType), button -> {
String key = StreamChatConfig.routeKey(selectedPlatform, eventType);
DisplayTarget[] targets = DisplayTarget.values();
DisplayTarget current = config.routes.getOrDefault(key, DisplayTarget.HIDDEN);
config.routes.put(key, targets[(current.ordinal() + 1) % targets.length]);
button.setMessage(routeLabel(eventType));
}).bounds(x, y, 185, 20).build());
}
}
private Component routeLabel(String eventType) {
DisplayTarget target = config.routes.getOrDefault(
StreamChatConfig.routeKey(selectedPlatform, eventType), DisplayTarget.HIDDEN);
return Component.literal(eventType + ": " + target.name());
}
private Component toggleLabel(Platform platform) {
return Component.literal(platform.name() + ": " + (config.isEnabled(platform) ? "On" : "Off"));
}
}