Janek Kozłowski

1.21.11

📎 1 file 3,670 chars
📄
pasted-code-1793392921457.txt
txt 68 lines
▶
Create a fully functional Client-Side Helper Mod for Minecraft (Fabric 1.21.1) tailored for the Ultrahub.pl server.
Visual Theme: Modern, clean, dark-mode GUI with Neon Purple & Black accents (Hex #A020F0 / #111116).

=== CORE CONFIGURATION ===
- Target Server: Ultrahub.pl
- Admin User Nickname: Vr00x
- Editable Admin Rank: "Test Helper" (Must be easily configurable in a config file or settings menu).

=== MAIN GUI & HOTKEY ===
- Opening Key: RIGHT_SHIFT opens the main Moderator Dashboard GUI.
- Main Dashboard Features:
  1. Target Player Info: Player Head / Avatar render, Player Name, Real-time Inspection Timer (starts at 3:00 and counts down).
  2. Live Target Chat Box: Displays filtered, dedicated chat messages sent ONLY by the target player being inspected.
  3. Today's Statistics Panel: Displays inspections count, total bans, total mutes, and total inspect time for today.
  4. Quick Action Buttons:
     - [ Przyznanie się ] -> Sends `/ban %player% 30d Przyznanie sie do czitow`
     - [ Brak współpracy ] -> Sends `/ban %player% 30d Brak wspólpracy podczas sprawdzania`
     - [ Czysty ] -> Clears inspect state, stops timer, sends chat notification.
     - [ Wykryto Cheaty ] -> Opens the Cheat Category Selection Sub-Menu.

=== CHEAT CATEGORIES SUB-MENU ===
When clicking "Wykryto Cheaty", open a secondary modal with 3 selectable categories:
1. Inject:
   - Veltragossa
   - Grim
   - Ventura
   - Inne
2. Zwykle:
   - Meteor
   - Wurst
   - Huzuni
   - Bleach
   - Thunder hack
   - Inne
3. ? (Inne / Inny typ cheatów)

Upon selecting a cheat (e.g. Meteor), automatically send: `/ban %player% 30d Cheaty - Meteor` and submit the ban event to Webhooks.

=== COMMAND & MUTE TRACKING ===
- Command `/sprawdz `: Starts inspection, resets timer to 3:00, sets target player.
- Mute Tracking: Intercept sent chat commands `/tempmute  
Kodari AI
KodariOct 30 at 8:54 pm 2
UltraHubAdminHelper
A client-side Fabric mod for Minecraft 1.21.1 providing a dark-mode GUI with neon purple accents for Ultrahub.pl moderators. Opens via RIGHT_SHIFT, featuring a target player inspection dashboard with live chat filtering, 3-minute countdown timer, and daily statistics panel. Includes quick-ban actions, cheat category selection sub-menu, mute command tracking, and automatic Discord webhook integration for live bans/mutes plus daily, weekly, and monthly summaries. Stores all statistics locally in JSON for persistent tracking.
  1. Create the Fabric 1.21.11 client mod, keybind, dashboard and cheat-selection screen.

  2. Add inspection/chat/mute tracking, local JSON statistics and configurable rank/webhook endpoint.

  3. Wire user-triggered moderation actions and summary events without embedding the exposed Discord webhook secrets.

Created the Fabric 1.21.11 client mod (following the project version, not the pasted spec’s 1.21.1). Right Shift opens the owo-ui dashboard; /sprawdz, target chat filtering, mute tracking, ban actions, cheat selection, and local daily statistics are wired up. Config and stats files are created under config/ on first launch.

The Discord API endpoint is intentionally left blank in config/ultrahub_admin_config.json: the supplied webhook credentials were exposed in the prompt, so rotate them before reuse. Deploy a Discord bot project on Kodari to route the mod’s moderation and summary events to your webhooks, then set its API URL as apiEndpoint.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
7 700
src/client/java/com/kodari/ultrahub/UltrahubHelperClient.java
package com.kodari.ultrahub;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.component.TextBoxComponent;
import io.wispforest.owo.ui.component.UIComponents;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.UIContainers;
import io.wispforest.owo.ui.core.Color;
import io.wispforest.owo.ui.core.HorizontalAlignment;
import io.wispforest.owo.ui.core.Insets;
import io.wispforest.owo.ui.core.OwoUIAdapter;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.core.Surface;
import io.wispforest.owo.ui.core.VerticalAlignment;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.WeekFields;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;

public final class UltrahubHelperClient implements ClientModInitializer {
    private static final int ACCENT = 0xA020F0;
    private static final int INSPECTION_SECONDS = 180;
    private static final int MAX_CHAT_LINES = 6;
    private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
    private static final HttpClient HTTP = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(8)).build();
    private static final Path CONFIG_PATH = Path.of("config", "ultrahub_admin_config.json");
    private static final Path STATS_PATH = Path.of("config", "ultrahub_admin_stats.json");
    private static final Deque<String> TARGET_CHAT = new ArrayDeque<>();
    private static final KeyBinding DASHBOARD_KEY = KeyBindingHelper.registerKeyBinding(
            new KeyBinding("key.ultrahub_helper.dashboard", InputUtil.Type.KEYSYM,
                    InputUtil.GLFW_KEY_RIGHT_SHIFT, KeyBinding.Category.MISC));

    private static AdminConfig config;
    private static StatsData stats;
    private static String targetPlayer;
    private static Instant inspectionStartedAt;
    private static int lastInspectionSeconds;
    private static int tickCounter;

    @Override
    public void onInitializeClient() {
        config = load(CONFIG_PATH, AdminConfig.class, new AdminConfig());
        stats = load(STATS_PATH, StatsData.class, new StatsData());
        if (stats.events == null) stats.events = new ArrayList<>();
        save(CONFIG_PATH, config);
        save(STATS_PATH, stats);

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (DASHBOARD_KEY.wasPressed()) client.setScreen(new DashboardScreen());
            if (++tickCounter % 20 == 0) {
                updateInspectionTimer();
                checkSummaryPeriods();
            }
        });

        ClientSendMessageEvents.COMMAND.register(UltrahubHelperClient::observeCommand);
        ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> {
            if (sender != null && targetPlayer != null && targetPlayer.equalsIgnoreCase(sender.name())) {
                TARGET_CHAT.addLast(sender.name() + ": " + message.getString());
                while (TARGET_CHAT.size() > MAX_CHAT_LINES) TARGET_CHAT.removeFirst();
            }
        });
    }

    private static <T> T load(Path path, Class<T> type, T fallback) {
        try {
            if (Files.exists(path)) {
                T loaded = GSON.fromJson(Files.readString(path), type);
                if (loaded != null) return loaded;
            }
        } catch (IOException | RuntimeException exception) {
            System.err.println("Could not read " + path + ": " + exception.getMessage());
        }
        return fallback;
    }

    private static void save(Path path, Object value) {
        try {
            Files.createDirectories(path.getParent());
            Files.writeString(path, GSON.toJson(value));
        } catch (IOException exception) {
            System.err.println("Could not write " + path + ": " + exception.getMessage());
        }
    }

    private static void observeCommand(String command) {
        String[] parts = command.trim().split("\\s+");
        if (parts.length < 2 || parts[0].isEmpty()) return;

        if (parts[0].equalsIgnoreCase("sprawdz")) {
            startInspection(parts[1]);
            return;
        }

        if (!parts[0].equalsIgnoreCase("tempmute")) return;
        int playerIndex = parts.length > 1 && parts[1].equalsIgnoreCase("IP") ? 2 : 1;
        int timeIndex = playerIndex + 1;
        int reasonIndex = playerIndex + 2;
        if (parts.length <= timeIndex) return;

        String player = parts[playerIndex];
        String duration = parts[timeIndex];
        String reason = parts.length > reasonIndex
                ? String.join(" ", java.util.Arrays.copyOfRange(parts, reasonIndex, parts.length))
                : "";
        recordEvent("MUTE", player, reason, duration, inspectionDurationSeconds());
        submitModeration("MUTE", player, reason, duration, formatDuration(inspectionDurationSeconds()));
    }

    private static void startInspection(String player) {
        if (inspectionStartedAt != null) finishInspection(false);
        targetPlayer = player;
        TARGET_CHAT.clear();
        inspectionStartedAt = Instant.now();
        lastInspectionSeconds = 0;
        recordEvent("INSPECTION_START", player, "", "", 0);
    }

    private static void updateInspectionTimer() {
        if (inspectionStartedAt != null && inspectionDurationSeconds() >= INSPECTION_SECONDS) {
            finishInspection(false);
        }
    }

    private static int inspectionDurationSeconds() {
        if (inspectionStartedAt == null) return lastInspectionSeconds;
        return (int) Math.max(0, Duration.between(inspectionStartedAt, Instant.now()).toSeconds());
    }

    private static int remainingInspectionSeconds() {
        if (inspectionStartedAt == null) return targetPlayer == null ? INSPECTION_SECONDS : 0;
        return Math.max(0, INSPECTION_SECONDS - inspectionDurationSeconds());
    }

    private static void finishInspection(boolean clearTarget) {
        if (inspectionStartedAt != null) {
            lastInspectionSeconds = inspectionDurationSeconds();
            recordEvent("INSPECTION_END", targetPlayer == null ? "" : targetPlayer, "", "", lastInspectionSeconds);
            inspectionStartedAt = null;
        }
        if (clearTarget) {
            targetPlayer = null;
            TARGET_CHAT.clear();
        }
    }

    private static void banTarget(String reason) {
        if (targetPlayer == null || targetPlayer.isBlank()) return;
        String player = targetPlayer;
        String inspectionDuration = formatDuration(inspectionDurationSeconds());
        ClientPlayNetworkHandler network = MinecraftClient.getInstance().getNetworkHandler();
        if (network == null) return;

        network.sendChatCommand("ban " + player + " 30d " + reason);
        recordEvent("BAN", player, reason, "30d", inspectionDurationSeconds());
        submitModeration("BAN", player, reason, "30d", inspectionDuration);
        finishInspection(true);
    }

    private static void clearAsClean() {
        if (targetPlayer == null) return;
        String player = targetPlayer;
        finishInspection(true);
        ClientPlayNetworkHandler network = MinecraftClient.getInstance().getNetworkHandler();
        if (network != null) {
            network.sendChatMessage(config.moderatorName + " (" + config.adminRank + "): " + player + " jest czysty po sprawdzeniu.");
        }