Kacper

For the server donutsmp in minecraft run by popular youtuber and streamer drdonut can you create me a mod for his server that tracks when soembody pays me and when i pay somebody and tracks if ive paid out more money or gained more money on a screen in the top right while also using that data to display a graph and does the math to tell me how much im up or down

Kodari AI
KodariNov 6 at 3:42 am 2
DonutPayTracker
Client-side Fabric mod for Minecraft 1.21.1 that tracks all player-to-player payments on the DonutSMP server. Displays a persistent HUD overlay in the top-right corner showing total received, total paid, and net profit/loss. Includes an interactive graph visualizing payment history over time, with automatic calculations of net gain or loss. Updates in real-time as transactions occur, storing data locally for session persistence.
  1. Track outgoing payments and incoming payments from server chat/commands.

  2. Persist the ledger locally and calculate net profit or loss.

  3. Add a top-right HUD panel with totals and a transaction graph.

Added the Fabric 1.21.11 client mod. It records incoming payments and confirmed outgoing /pay <player> <amount> payments, saves the ledger locally, and shows totals, net gain/loss, and a graph of the last 24 transactions in the top-right HUD.

It recognizes common payment confirmation and notification messages. If DonutSMP uses a different message format, those transactions may not be recorded until the parser supports it.

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

import com.kodari.donutmoneytracker.TransactionLedger.Transaction;
import io.wispforest.owo.ui.component.LabelComponent;
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.Insets;
import io.wispforest.owo.ui.core.Positioning;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.core.Surface;
import io.wispforest.owo.ui.hud.Hud;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
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.text.Text;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class DonutMoneyTrackerClient implements ClientModInitializer {
    private static final Identifier HUD_ID = Identifier.of("donutmoneytracker", "money_panel");
    private static final Pattern PAY_COMMAND = Pattern.compile("(?i)^pay\\s+([A-Za-z0-9_]{1,16})\\s+([0-9][0-9,]*(?:\\.[0-9]{1,2})?)$");
    private static final Pattern PLAYER_PAID_YOU = Pattern.compile("(?i)\\b([A-Za-z0-9_]{1,16})\\s+(?:has\\s+)?(?:paid|sent|gave)\\s+you\\s+\\$?\\s*([0-9][0-9,]*(?:\\.[0-9]{1,2})?)\\b");
    private static final Pattern YOU_RECEIVED = Pattern.compile("(?i)\\byou\\s+(?:have\\s+)?(?:received|got)\\s+\\$?\\s*([0-9][0-9,]*(?:\\.[0-9]{1,2})?)\\s+(?:from|by)\\s+([A-Za-z0-9_]{1,16})\\b");
    private static final Pattern YOU_PAID_PLAYER = Pattern.compile("(?i)\\byou\\s+(?:have\\s+)?(?:paid|sent|gave)\\s+([A-Za-z0-9_]{1,16})\\s+\\$?\\s*([0-9][0-9,]*(?:\\.[0-9]{1,2})?)\\b");
    private static final Pattern YOU_PAID_AMOUNT = Pattern.compile("(?i)\\byou\\s+(?:have\\s+)?(?:paid|sent|gave)\\s+\\$?\\s*([0-9][0-9,]*(?:\\.[0-9]{1,2})?)\\s+to\\s+([A-Za-z0-9_]{1,16})\\b");
    private static final Pattern PAID_AMOUNT = Pattern.compile("(?i)\\b(?:payment\\s+)?(?:paid|sent)\\s+\\$?\\s*([0-9][0-9,]*(?:\\.[0-9]{1,2})?)\\s+to\\s+([A-Za-z0-9_]{1,16})\\b");
    private static final Pattern AMOUNT = Pattern.compile("\\$?\\s*([0-9][0-9,]*(?:\\.[0-9]{1,2})?)");
    private static final long PENDING_TIMEOUT_MS = 20_000;

    private final List<PendingPayment> pendingPayments = new ArrayList<>();
    private TransactionLedger ledger;
    private LabelComponent incomingLabel;
    private LabelComponent outgoingLabel;
    private LabelComponent netLabel;

    @Override
    public void onInitializeClient() {
        this.ledger = new TransactionLedger(MinecraftClient.getInstance().runDirectory.toPath()
                .resolve("donut-money-tracker.tsv"));
        this.ledger.load();

        ClientSendMessageEvents.COMMAND.register(this::onCommandSent);
        ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) ->
                this.onServerMessage(message.getString()));
        ClientReceiveMessageEvents.GAME.register((message, overlay) -> this.onServerMessage(message.getString()));
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            this.expirePendingPayments();
            this.refreshHud();
        });

        Hud.add(HUD_ID, this::createHud);
    }

    private void onCommandSent(String command) {
        Matcher matcher = PAY_COMMAND.matcher(command.trim());
        if (!matcher.matches()) {
            return;
        }

        double amount = parseAmount(matcher.group(2));
        if (amount > 0) {
            this.pendingPayments.add(new PendingPayment(matcher.group(1), amount, System.currentTimeMillis()));
        }
    }

    private void onServerMessage(String rawMessage) {
        String message = rawMessage.replaceAll("§[0-9A-FK-ORa-fk-or]", "").trim();
        Matcher matcher = PLAYER_PAID_YOU.matcher(message);
        if (matcher.find()) {
            this.ledger.add(true, matcher.group(1), parseAmount(matcher.group(2)));
            return;
        }

        matcher = YOU_RECEIVED.matcher(message);
        if (matcher.find()) {
            this.ledger.add(true, matcher.group(2), parseAmount(matcher.group(1)));
            return;
        }

        matcher = YOU_PAID_PLAYER.matcher(message);
        if (matcher.find()) {
            this.confirmOutgoing(matcher.group(1), parseAmount(matcher.group(2)));
            return;
        }

        matcher = YOU_PAID_AMOUNT.matcher(message);
        if (matcher.find()) {
            this.confirmOutgoing(matcher.group(2), parseAmount(matcher.group(1)));
            return;
        }

        matcher = PAID_AMOUNT.matcher(message);
        if (matcher.find() && (message.toLowerCase(Locale.ROOT).contains("you")
                || message.toLowerCase(Locale.ROOT).contains("success"))) {
            this.confirmOutgoing(matcher.group(2), parseAmount(matcher.group(1)));
            return;
        }

        this.confirmGenericOutgoing(message);
    }

    private void confirmOutgoing(String player, double amount) {
        this.removePending(player, amount);
        this.ledger.add(false, player, amount);
    }

    private void confirmGenericOutgoing(String message) {
        String normalized = message.toLowerCase(Locale.ROOT);
        if (!(normalized.contains("success") || normalized.contains("paid") || normalized.contains("sent")
                || normalized.contains("payment") || normalized.contains("transfer"))) {
            return;
        }

        Matcher amounts = AMOUNT.matcher(message);
        while (amounts.find()) {
            double amount = parseAmount(amounts.group(1));
            for (int i = 0; i < this.pendingPayments.size(); i++) {
                PendingPayment pending = this.pendingPayments.get(i);
                if (pending.player().equalsIgnoreCase(findMentionedPlayer(message, pending.player()))
                        && Math.abs(pending.amount() - amount) < 0.005) {
                    this.pendingPayments.remove(i);
                    this.ledger.add(false, pending.player(), pending.amount());
                    return;
                }
            }
        }
    }

    private static String findMentionedPlayer(String message, String player) {
        return Pattern.compile("(?i)\\b" + Pattern.quote(player) + "\\b").matcher(message).find() ? player : "";
    }

    private void removePending(String player, double amount) {
        for (int i = this.pendingPayments.size() - 1; i >= 0; i--) {
            PendingPayment pending = this.pendingPayments.get(i);
            if (pending.player().equalsIgnoreCase(player) && Math.abs(pending.amount() - amount) < 0.005) {
                this.pendingPayments.remove(i);
                return;
            }
        }
    }

    private void expirePendingPayments() {
        long now = System.currentTimeMillis();
        this.pendingPayments.removeIf(payment -> now - payment.timestamp() > PENDING_TIMEOUT_MS);
    }

    private FlowLayout createHud() {
        LabelComponent title = UIComponents.label(Text.literal("DONUT MONEY"));
        title.color(Color.ofRgb(0xF3C969));
        title.shadow(true);

        this.incomingLabel = UIComponents.label(Text.literal("IN   +$0.00"));
        this.incomingLabel.color(Color.ofRgb(0x65E572));
        this.outgoingLabel = UIComponents.label(Text.literal("OUT  -$0.00"));
        this.outgoingLabel.color(Color.ofRgb(0xFF6969));
        this.netLabel = UIComponents.label(Text.literal("NET  +$0.00"));
        this.netLabel.color(Color.ofRgb(0x65E572));

        FlowLayout graph = UIContainers.verticalFlow(Sizing.fixed(178), Sizing.fixed(46));
        graph.surface((graphics, component) -> this.drawGraph(graphics, component.x(), component.y(), component.width(), component.height()));

        FlowLayout panel = UIContainers.verticalFlow(Sizing.fixed(190), Sizing.content());
        panel.child(title);
        panel.child(this.incomingLabel);
        panel.child(this.outgoingLabel);
        panel.child(this.netLabel);
        panel.child(graph);
        panel.gap(3);
        panel.padding(Insets.of(7));
        panel.surface(Surface.flat(0xD9101722).and(Surface.outline(0xFF596A7A)));
        panel.margins(Insets.of(6));
        panel.positioning(Positioning.relative(100, 0));

        this.refreshHud();
        return panel;
    }

    private void drawGraph(io.wispforest.owo.ui.core.OwoUIGraphics graphics, int x, int y, int width, int height) {
        int left = x + 3;
        int graphWidth = width - 6;
        int baseline = y + height / 2;
        graphics.fill(left, baseline, left + graphWidth, baseline + 1, 0xFF7D8996);

        List<Transaction> recent = this.ledger.lastTransactions(24);
        if (recent.isEmpty()) {
            return;
        }

        double max = recent.stream().mapToDouble(Transaction::amount).max().orElse(1);