fearkxqor

create a chatpacking wordlist that instant copies and each having 3 - 4 paragrpahs

Kodari AI
KodariOct 19 at 9:50 pm 1
ChatPackerWordlist
ChatPackerWordlist is a Minecraft plugin that introduces a dynamic word-pack system for chat customization. Players can obtain word packs containing curated wordlists, each with three to four paragraph-length lore segments describing unique themes, abilities, or backstories. The plugin instantly copies these pre-written paragraphs into chat when a player activates a pack, allowing for rapid, immersive storytelling. It features a GUI for browsing and selecting packs, a command system for granting and managing packs, and configurable cooldowns to prevent spam. Administrators can create custom word packs directly from config files, making the plugin highly extensible and tailored to server-specific narratives.
  1. Create a Paper plugin with a /chatpack command and clickable copy-to-clipboard choices.

  2. Include a configurable wordlist with three packs, each containing three paragraphs.

Created ChatPacks, a Paper plugin with /chatpack to show clickable packs and /chatpack <name> to copy one. The included wordlist has three packs, each with three paragraphs; you can add or edit packs in wordlist.yml.

Minecraft requires a player click to copy text to their clipboard, so each pack is click-to-copy rather than copying automatically when the command runs.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 179
src/main/java/com/kodari/chatpacks/ChatPacksPlugin.java
package com.kodari.chatpacks;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public final class ChatPacksPlugin extends JavaPlugin implements CommandExecutor, TabCompleter {
    private final Map<String, WordPack> packs = new LinkedHashMap<>();

    @Override
    public void onEnable() {
        saveResource("wordlist.yml", false);
        loadPacks();

        PluginCommand command = getCommand("chatpack");
        if (command == null) {
            getLogger().severe("The chatpack command is missing from plugin.yml.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        command.setExecutor(this);
        command.setTabCompleter(this);
    }

    private void loadPacks() {
        packs.clear();
        File file = new File(getDataFolder(), "wordlist.yml");
        YamlConfiguration wordlist = YamlConfiguration.loadConfiguration(file);
        ConfigurationSection entries = wordlist.getConfigurationSection("entries");
        if (entries == null) {
            getLogger().warning("wordlist.yml does not contain an entries section.");
            return;
        }

        for (String id : entries.getKeys(false)) {
            String name = entries.getString(id + ".name", id);
            List<String> paragraphs = entries.getStringList(id + ".paragraphs");
            if (paragraphs.size() < 3 || paragraphs.size() > 4 || paragraphs.stream().anyMatch(String::isBlank)) {
                getLogger().warning("Skipping word pack '" + id + "': it must have 3 or 4 non-empty paragraphs.");
                continue;
            }

            packs.put(id.toLowerCase(Locale.ROOT), new WordPack(name, String.join("\n\n", paragraphs)));
        }

        if (packs.isEmpty()) {
            getLogger().warning("No valid word packs were loaded from wordlist.yml.");
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can copy chat packs.");
            return true;
        }

        if (args.length > 1) {
            player.sendMessage(Component.text("Usage: /chatpack [name]"));
            return true;
        }

        if (args.length == 1) {
            WordPack pack = packs.get(args[0].toLowerCase(Locale.ROOT));
            if (pack == null) {
                player.sendMessage(Component.text("Unknown pack. Use /chatpack to see the available packs."));
                return true;
            }

            sendCopyButton(player, pack);
            return true;
        }

        if (packs.isEmpty()) {
            player.sendMessage(Component.text("There are no word packs available."));
            return true;
        }

        player.sendMessage(Component.text("Click a pack to copy all its paragraphs to your clipboard:"));
        for (Map.Entry<String, WordPack> entry : packs.entrySet()) {
            WordPack pack = entry.getValue();
            player.sendMessage(Component.text("• " + pack.name() + " [copy]")
                    .clickEvent(ClickEvent.copyToClipboard(pack.text())));
        }
        return true;
    }

    private void sendCopyButton(Player player, WordPack pack) {
        player.sendMessage(Component.text("Click to copy “" + pack.name() + "” to your clipboard:")
                .clickEvent(ClickEvent.copyToClipboard(pack.text())));
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        if (args.length != 1) {
            return List.of();
        }

        String prefix = args[0].toLowerCase(Locale.ROOT);
        List<String> matches = new ArrayList<>();
        for (String id : packs.keySet()) {
            if (id.startsWith(prefix)) {
                matches.add(id);
            }
        }
        return matches;
    }

    private record WordPack(String name, String text) {
    }
}