phrvm

Develop a custom stick item called "Nesher" that, when used to hit a player, changes their voice icon to a unique design indicating they are permanently muted. Implement a visibility feature so that all players can see this icon, along with a command for admins to toggle the mute status or reset it. Ensure compatibility with existing voice chat plugins and provide a configuration file for customization. Fabric 1.21.11 and OP players can use /unmute {user} to make their simple voicechat normal.

1 image attached
Kodari AI
KodariOct 16 at 9:42 am 13
NesherVoiceMute
Adds a custom "Nesher" stick that permanently mutes a player's Simple Voice Chat icon when used to hit them. The muted player's voice icon displays a unique design visible to all players. Includes admin commands to toggle mute status or reset it, plus a configuration file for customization. Compatible with existing Simple Voice Chat mods on Fabric 1.21.11.
  1. Build the server-side Nesher item, persistent mute state, admin commands, and config.

  2. Add a client-side status icon visible to players with the mod, and integrate the mute state with Simple Voice Chat where its API allows.

Implemented the Fabric 1.21.11 Nesher mod.

  • The custom Nesher stick mutes a player when an OP hits them. Mutes persist across restarts and block their microphone packets when Simple Voice Chat is installed.

  • OPs can use /mute <user> to toggle mute, /mute reset to clear all mutes, and /unmute <user> to restore a player’s voice chat. Commands currently require the target to be online.

  • Players with the mod installed see a configurable marker above muted players. Edit config/nesher.properties after first startup to change its icon or color.

  • The item is available in the Nesher creative tab or via /give @s nesher:nesher; it has no survival recipe because it’s an admin tool. The marker requires the client mod; Simple Voice Chat integration is optional.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
16 564
src/main/java/com/kodari/nesher/NesherMod.java
package com.kodari.nesher;

import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.permission.Permission;
import net.minecraft.command.permission.PermissionLevel;
import net.minecraft.command.permission.PermissionPredicate;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class NesherMod implements ModInitializer {
    public static final String MOD_ID = "nesher";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
    private static final Permission ADMIN_PERMISSION = new Permission.Level(PermissionLevel.GAMEMASTERS);
    private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("nesher.properties");
    private static final Set<UUID> MUTED_PLAYERS = ConcurrentHashMap.newKeySet();

    public static Item NESHER;
    public static volatile String icon = "⊘";
    public static volatile int iconColor = 0xFFFF9900;

    @Override
    public void onInitialize() {
        loadConfiguration();
        RegistryKey<Item> itemKey = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, "nesher"));
        NESHER = Registry.register(Registries.ITEM, itemKey,
                new NesherItem(new Item.Settings().registryKey(itemKey).maxCount(1)));
        ItemGroup group = FabricItemGroup.builder()
                .icon(() -> new ItemStack(NESHER))
                .displayName(Text.literal("Nesher"))
                .entries((displayContext, entries) -> entries.add(NESHER))
                .build();
        Registry.register(Registries.ITEM_GROUP, Identifier.of(MOD_ID, "nesher"), group);

        NesherNetworking.initialize();
        registerCommands();
    }

    public static boolean hasAdminPermission(PermissionPredicate permissions) {
        return permissions.hasPermission(ADMIN_PERMISSION);
    }

    public static boolean isAdmin(ServerCommandSource source) {
        return hasAdminPermission(source.getPermissions());
    }

    public static boolean isMuted(UUID playerId) {
        return MUTED_PLAYERS.contains(playerId);
    }

    public static synchronized boolean toggleMuted(MinecraftServer server, UUID playerId) {
        boolean muted;
        if (MUTED_PLAYERS.remove(playerId)) {
            muted = false;
        } else {
            MUTED_PLAYERS.add(playerId);
            muted = true;
        }
        saveConfiguration();
        NesherNetworking.broadcast(server, playerId);
        return muted;
    }

    public static synchronized boolean setMuted(MinecraftServer server, UUID playerId, boolean muted) {
        boolean changed = muted ? MUTED_PLAYERS.add(playerId) : MUTED_PLAYERS.remove(playerId);
        if (changed) {
            saveConfiguration();
            NesherNetworking.broadcast(server, playerId);
        }
        return changed;
    }

    private static synchronized int resetMuted(MinecraftServer server) {
        int count = MUTED_PLAYERS.size();
        MUTED_PLAYERS.clear();
        saveConfiguration();
        for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
            NesherNetworking.broadcast(server, player.getUuid());
        }
        return count;
    }

    private static void registerCommands() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
            dispatcher.register(CommandManager.literal("mute")
                    .requires(NesherMod::isAdmin)
                    .then(CommandManager.literal("reset")
                            .executes(context -> {
                                int count = resetMuted(context.getSource().getServer());
                                context.getSource().sendMessage(Text.literal("Reset permanent mute status for " + count + " player(s)."));
                                return 1;
                            }))
                    .then(CommandManager.argument("user", StringArgumentType.word())
                            .executes(context -> {
                                String name = StringArgumentType.getString(context, "user");
                                ServerCommandSource source = context.getSource();
                                ServerPlayerEntity target = source.getServer().getPlayerManager().getPlayer(name);
                                if (target == null) {
                                    source.sendMessage(Text.literal("Player is not online: " + name));
                                    return 0;
                                }
                                boolean muted = toggleMuted(source.getServer(), target.getUuid());
                                source.sendMessage(Text.literal(name + (muted ? " is now permanently muted." : " is now unmuted.")));
                                return 1;
                            })));

            dispatcher.register(CommandManager.literal("unmute")
                    .requires(NesherMod::isAdmin)
                    .then(CommandManager.argument("user", StringArgumentType.word())
                            .executes(context -> {
                                String name = StringArgumentType.getString(context, "user");
                                ServerCommandSource source = context.getSource();
                                ServerPlayerEntity target = source.getServer().getPlayerManager().getPlayer(name);
                                if (target == null) {
                                    source.sendMessage(Text.literal("Player is not online: " + name));
                                    return 0;
                                }
                                setMuted(source.getServer(), target.getUuid(), false);
                                source.sendMessage(Text.literal(name + " is now unmuted."));
                                return 1;
                            })));
        });
    }

    private static void loadConfiguration() {
        Properties properties = new Properties();
        try {
            if (Files.exists(CONFIG_PATH)) {
                try (Reader reader = Files.newBufferedReader(CONFIG_PATH, StandardCharsets.UTF_8)) {
                    properties.load(reader);
                }
            } else {
                try (InputStream input = NesherMod.class.getResourceAsStream("/nesher.properties")) {
                    if (input != null) {
                        try (Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8)) {
                            properties.load(reader);
                        }
                    }
                }
            }
        } catch (IOException exception) {
            LOGGER.error("Could not read Nesher configuration", exception);
        }

        icon = properties.getProperty("icon", "⊘").trim();
        if (icon.isEmpty()) {
            icon = "⊘";
        }
        iconColor = parseColor(properties.getProperty("icon_color", "FF9900"));
        MUTED_PLAYERS.clear();
        Arrays.stream(properties.getProperty("muted_uuids", "").split(","))
                .map(String::trim)
                .filter(value -> !value.isEmpty())
                .forEach(value -> {
                    try {
                        MUTED_PLAYERS.add(UUID.fromString(value));
                    } catch (IllegalArgumentException exception) {
                        LOGGER.warn("Ignoring invalid UUID in muted_uuids: {}", value);
                    }
                });
        if (!Files.exists(CONFIG_PATH)) {
            saveConfiguration();
        }
    }

    private static int parseColor(String value) {
        String hex = value.trim().replace("#", "");
        try {