Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 548
src/main/java/com/kodari/moderator/ModeratorClient.java
package com.kodari.moderator;
import com.mojang.authlib.GameProfile;
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.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.List;
public class ModeratorClient implements ClientModInitializer {
private static final String KEY_CATEGORY = "key.categories.moderatorpanel";
private static final List<String> CHAT_LINES = new ArrayList<>();
static String targetName = "";
static String notice = "Готово";
static boolean hudEnabled = true;
static boolean autoVanish;
static boolean autoSpecOff;
static boolean autoExtraTime;
static boolean autoDiscordRpc;
private static KeyBinding menuKey;
private static KeyBinding playerChatKey;
private static KeyBinding startReviseKey;
@Override
public void onInitializeClient() {
menuKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.moderatorpanel.menu", InputUtil.Type.KEYSYM, InputUtil.GLFW_KEY_LEFT_SHIFT, KEY_CATEGORY));
playerChatKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.moderatorpanel.player_chat", InputUtil.Type.KEYSYM, InputUtil.GLFW_KEY_G, KEY_CATEGORY));
startReviseKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.moderatorpanel.start_revise", InputUtil.Type.KEYSYM, InputUtil.GLFW_KEY_M, KEY_CATEGORY));
ClientTickEvents.END_CLIENT_TICK.register(client -> handleKeys(client));
ClientSendMessageEvents.ALLOW_COMMAND.register(command -> {
rememberSpecTarget(command);
return true;
});
ClientReceiveMessageEvents.ALLOW_CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> {
MinecraftClient client = MinecraftClient.getInstance();
if (!(client.currentScreen instanceof TargetChatScreen chatScreen)) {
return true;
}
String senderName = sender == null ? "" : sender.getName();
String localName = client.player == null ? "" : client.player.networkHandler.getProfile().getName();
boolean isTarget = !targetName.isBlank() && senderName.equalsIgnoreCase(targetName);
boolean isModerator = !localName.isBlank() && senderName.equalsIgnoreCase(localName);
if (isTarget || isModerator) {
chatScreen.receive(senderName, message.getString());
return true;
}
return false;
});
ClientReceiveMessageEvents.ALLOW_GAME.register((message, overlay) ->
!(MinecraftClient.getInstance().currentScreen instanceof TargetChatScreen));
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
targetName = "";
CHAT_LINES.clear();
if (autoVanish) {
handler.sendChatCommand("vanish");
}
if (autoSpecOff) {
handler.sendChatCommand("spec off");
}
if (autoExtraTime) {
handler.sendChatCommand("revise addtime 2m");
}
if (autoDiscordRpc) {
notice = "Discord RPC отмечен; внешняя интеграция не подключена";
}
});
HudRenderCallback.EVENT.register((context, tickCounter) -> renderHud(context));
}
private static void handleKeys(MinecraftClient client) {
if (menuKey.wasPressed() && client.currentScreen == null) {
client.setScreen(new MainMenuScreen());
}
if (playerChatKey.wasPressed() && client.currentScreen == null) {
openTargetChat(client);
}
if (startReviseKey.wasPressed() && client.currentScreen == null) {
startRevise(client);
}
}
private static void rememberSpecTarget(String command) {
String normalized = command.startsWith("/") ? command.substring(1) : command;
String[] parts = normalized.trim().split("\\s+");
if (parts.length < 2 || !parts[0].equalsIgnoreCase("spec")) {
return;
}
if (parts[1].equalsIgnoreCase("off")) {
targetName = "";
notice = "Цель проверки очищена";
} else {
targetName = parts[1];
notice = "Цель проверки: " + targetName;
}
}
static void sendCommand(MinecraftClient client, String command) {
if (client.player == null) {
notice = "Нет подключения к серверу";
return;
}
client.player.networkHandler.sendChatCommand(command);
notice = "Отправлено: /" + command;
}
static boolean requireTarget() {
if (!targetName.isBlank()) {
return true;
}
notice = "Сначала используй /spec <ник>";
return false;
}
private static void openTargetChat(MinecraftClient client) {
if (requireTarget()) {
client.setScreen(new TargetChatScreen());
}
}
private static void startRevise(MinecraftClient client) {
if (requireTarget()) {
sendCommand(client, "revise start " + targetName);
}
}
private static void renderHud(DrawContext context) {
MinecraftClient client = MinecraftClient.getInstance();
if (!hudEnabled || client.player == null || targetName.isBlank() || client.currentScreen != null) {
return;
}
context.fill(8, 8, 190, 34, 0xD91B2029);
context.drawText(client.textRenderer, Text.literal("Проверка: " + targetName), 16, 17, 0xFFE6EAF0, false);
}
private static void addChatLine(String sender, String message) {
CHAT_LINES.add(sender + ": " + message);
while (CHAT_LINES.size() > 80) {
CHAT_LINES.remove(0);
}
}
private record BanRule(String rule, String title, String duration) {
String command() {
String reason = rule + " | " + title;
return "tempbanip " + targetName + " " + duration + " \"" + reason + "\"";
}
String label() {
return rule + " — " + title + " — " + duration.replace("d", " дней");
}
}
private static final class MainMenuScreen extends Screen {
private static final int PANEL_WIDTH = 560;
private static final int PANEL_HEIGHT = 420;
private static final String[] TABS = {"Бан", "Проверка", "HUD", "Авто-команды", "Утилиты", "Чат", "Настройки"};
private static final BanRule[] BAN_RULES = {
new BanRule("4.3", "Нарушение правил", "30d"),
new BanRule("4.3", "Признание", "24d"),
new BanRule("4.3", "Выход с проверки", "30d"),
new BanRule("4.3", "Уклон от проверки", "30d"),
new BanRule("4.3", "Отказ от проверки", "30d"),
new BanRule("4.3", "3/3 предупреждений", "30d"),
new BanRule("4.3.1", "Запрещённые моды", "14d"),
new BanRule("4.3.2", "Очистка корзины", "30d"),
new BanRule("4.3.3", "Рек проверки", "30d")
};
private final List<MenuButton> buttons = new ArrayList<>();
private int activeTab;
private MainMenuScreen() {
super(Text.literal("Moderator Panel"));
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
int panelX = (width - PANEL_WIDTH) / 2;