NOT VOLVEX
๐Ÿ“Ž 1 file 1,268 chars
๐Ÿ“„
pasted-code-1788969662806.txt
txt 33 lines
โ–ถ
Task: Write a complete, production-ready, highly optimized Spigot/Paper/Leaf Minecraft Java Plugin that blocks player arm swing / hand-spamming sound packets in specific worlds.

Core Requirements:

Target Software & Versions: Must work across Spigot, Paper, Leaf, and Purpur (1.16 to latest 1.20+ versions).

Packet Interception (ProtocolLib): Use ProtocolLib API (PacketType.Play.Client.ARM_ANIMATION) to cancel the arm animation packet at the network layer. This ensures that fast-clicking/hand-spamming sounds are 100% blocked on both client and server sides without affecting actual block interaction logic.

Per-World Configuration:

Create a fully customizable config.yml containing a list of disabled worlds (e.g., spawn, arena).

If a player is inside a world listed in config.yml, cancel their swing packet.

If a player is in any other world, allow swing packets normally.

Commands & Permissions:

/sbreload command to reload config.yml instantly without restarting the server.

Permission node: soundblocker.admin

Deliverables Required:

Full Java Source Code for SoundBlocker.java

plugin.yml

config.yml

pom.xml (Maven setup with ProtocolLib and Paper API dependencies)

Ensure there are no deprecation warnings, memory leaks, or thread-safety issues.
Kodari AI
KodariSep 9 at 4:03 pm 1
SoundBlocker
A Spigot/Paper/Leaf/Purpur plugin that blocks player arm swing animation packets in specific worlds via ProtocolLib. Features per-world configuration through config.yml, a /sbreload command for instant config reloads, and the soundblocker.admin permission node. Intercepts ARM_ANIMATION packets at the network layer to prevent hand-spamming sounds without affecting block interaction. Supports Minecraft 1.16 through 1.20+ versions with optimized, thread-safe, memory-efficient code.
Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
4 180
src/main/java/com/example/soundblocker/SoundBlocker.java
package com.example.soundblocker;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

public final class SoundBlocker extends JavaPlugin {

    private volatile Set<String> disabledWorlds = Collections.emptySet();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        reloadDisabledWorlds();

        if (getCommand("sbreload") == null) {
            throw new IllegalStateException("The sbreload command is missing from plugin.yml");
        }

        getCommand("sbreload").setExecutor(this);

        ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
        protocolManager.addPacketListener(new PacketAdapter(
                this,
                ListenerPriority.NORMAL,
                PacketType.Play.Client.ARM_ANIMATION
        ) {
            @Override
            public void onPacketReceiving(PacketEvent event) {
                Player player = event.getPlayer();

                if (isWorldDisabled(player.getWorld().getName())) {
                    event.setCancelled(true);
                }
            }
        });

        getLogger().info("SoundBlocker enabled for " + disabledWorlds.size() + " configured world(s).");
    }

    @Override
    public void onDisable() {
        ProtocolLibrary.getProtocolManager().removePacketListeners(this);
        disabledWorlds = Collections.emptySet();
    }

    @Override
    public boolean onCommand(
            CommandSender sender,
            Command command,
            String label,
            String[] args
    ) {
        if (!sender.hasPermission("soundblocker.admin")) {
            sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
            return true;
        }

        reloadConfig();
        reloadDisabledWorlds();

        sender.sendMessage(ChatColor.GREEN + "SoundBlocker configuration reloaded.");
        sender.sendMessage(ChatColor.GRAY + "Blocked worlds: " + disabledWorlds.size());
        return true;
    }

    private void reloadDisabledWorlds() {
        Set<String> worlds = new HashSet<>();

        for (String worldName : getConfig().getStringList("disabled-worlds")) {
            if (worldName == null) {
                continue;
            }

            String normalizedName = worldName.trim().toLowerCase(Locale.ROOT);

            if (!normalizedName.isEmpty()) {
                worlds.add(normalizedName);
            }
        }

        disabledWorlds = Collections.unmodifiableSet(worlds);
    }

    private boolean isWorldDisabled(String worldName) {
        return disabledWorlds.contains(worldName.toLowerCase(Locale.ROOT));
    }
}