Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 143
src/client/java/com/kodari/quickpunish/QuickPunishClient.java
package com.kodari.quickpunish;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
public class QuickPunishClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) ->
dispatcher.register(ClientCommandManager.literal("punish")
.then(ClientCommandManager.argument("player", StringArgumentType.word())
.executes(context -> {
showMenu(StringArgumentType.getString(context, "player"));
return 1;
}))));
}
private static void showMenu(String playerName) {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player == null) {
return;
}
MutableText menu = Text.literal("Наказание для " + playerName + " — нажмите срок:");
menu.append(Text.literal("\nБан: "));
addTimedOptions(menu, playerName, "tempban", "ban");
menu.append(Text.literal("\nМут: "));
addTimedOptions(menu, playerName, "tempmute", "mute");
menu.append(Text.literal("\nКик: "));
addButton(menu, "выполнить", "/kick " + playerName);
menu.append(Text.literal("\nПредупреждение: "));
addButton(menu, "выдать", "/warn " + playerName);
player.sendMessage(menu, false);
}
private static void addTimedOptions(MutableText menu, String playerName, String temporaryCommand, String permanentCommand) {
addButton(menu, "10м", "/" + temporaryCommand + " " + playerName + " 10m");
addButton(menu, "1ч", "/" + temporaryCommand + " " + playerName + " 1h");
addButton(menu, "1д", "/" + temporaryCommand + " " + playerName + " 1d");
addButton(menu, "7д", "/" + temporaryCommand + " " + playerName + " 7d");
addButton(menu, "навсегда", "/" + permanentCommand + " " + playerName);
}
private static void addButton(MutableText menu, String label, String command) {
menu.append(Text.literal(" [" + label + "]")
.setStyle(Style.EMPTY.withClickEvent(new ClickEvent.SuggestCommand(command))));
}
}