fonito12

generate a plugin that adds a command that when executed gives a visual effect of snow in both players like /test (user) and gives the target a milk bucket if the one executing the command has one in it with a name like this "cubo de (user)" that when you eat it you get nausea for 5 seconds and speed 2 for 10s and a config file where i can change the command like instead of /test to /test2 etc also make look the floor in the target has particles of snow flakes

Kodari AI
KodariSep 24 at 8:27 pm 1
SnowGiftCommand
SnowGiftCommand is a Minecraft plugin that adds a customizable command (default /test) allowing a player to gift snow effects to another player. When executed, the target receives a visual snowfall particle effect around them and on the floor, while the executor must have a milk bucket named "cubo de (target)" in their inventory, which is consumed. Consuming the milk bucket grants the target Nausea for 5 seconds and Speed II for 10 seconds. The command name, particle effects, durations, and item name are all configurable via a YAML config file, allowing server admins to fully customize the experience without code changes.
  • Add the configurable command and plugin metadata.

  • Implement the snow effect and transfer a specially named milk bucket when the sender has one.

  • Apply the bucket’s nausea and Speed II effects when consumed.

Created the SnowMilk plugin. /test <player> is configurable in config.yml; it creates a five-second snow effect around both players and across the target’s floor. If the sender has a milk bucket, it’s transferred as cubo de <sender>; drinking it gives nausea for 5 seconds and Speed II for 10 seconds.

fonito12

it grants this effect when the milk bucket is eaten and it has to be executed close to the target

Kodari AI
KodariSep 24 at 8:28 pm 1
  1. Require the sender to be near the target before /test succeeds.

  2. Apply nausea and Speed II when the gifted bucket is consumed.

/test <player> now only works when both players are in the same world and within 5 blocks. Change max-distance in config.yml to adjust the range. The gifted bucket still applies nausea for 5 seconds and Speed II for 10 seconds when consumed.

fonito12

quiero que en config file pueda cambiar todo y al cambiar el nombre del comando quiero que siga sirviendo el / y no lo muestre en rojo tambien que pueda cambiar todos los mensajes que mande el plugin al igual quiero que al usar el comando suene el sonido de la vaca (el de ordeñar) y un numero que yo quiera de veces el sonido de caminar en bloques de slime igualmente quiero que pueda hacer /comando reload lo cual hara que se vuelva a leer el comando sin necesidad de reiniciar el server (osea q se vuelva a leer el config file)

Kodari AI
KodariSep 24 at 8:51 pm 1
  1. Hacer configurable el comando y registrar su alias al recargar para que / funcione sin reiniciar.

  2. Mover a config.yml todos los valores y mensajes del plugin.

  3. Añadir sonidos configurables: ordeño y pasos sobre slime con cantidad ajustable.

Actualicé el plugin: ahora puedes cambiar el comando en config.yml (con o sin /) y usar /<comando> reload para aplicar los cambios sin reiniciar. El comando nuevo queda registrado para que el cliente lo reconozca.

También puedes configurar los mensajes, la distancia, las partículas, el nombre y los efectos del cubo, y los sonidos de ordeño y de pasos sobre slime, incluida su cantidad e intervalo.

fonito12

explicame el funcionamiento

Kodari AI
KodariSep 24 at 9:04 pm 1

El plugin funciona así:

  • Comando principal: ejecutas /<comando> <jugador>. Por ejemplo, si en la configuración el comando es test, usas /test Alex.

  • Distancia: quien ejecuta el comando debe estar cerca del objetivo y ambos deben estar en el mismo mundo. La distancia máxima se puede cambiar en config.yml.

  • Efecto de nieve: al usar el comando, se muestra nieve alrededor de ambos jugadores y partículas de copos sobre el suelo del objetivo.

  • Cubo: si quien ejecuta el comando tiene un cubo de leche, se lo entrega al objetivo con un nombre como cubo de <nombre del remitente>. Al beberlo, el jugador recibe náuseas durante 5 segundos y Velocidad II durante 10 segundos.

  • Sonidos: se reproduce el sonido de ordeñar una vaca y una cantidad configurable de sonidos de pasos sobre slime.

  • Configuración y mensajes: puedes ajustar el nombre del comando, mensajes, distancia, efectos, partículas y sonidos desde config.yml.

  • Recargar sin reiniciar: usa /<comando> reload; por ejemplo, /test reload. El plugin vuelve a leer la configuración y registra el comando configurado.

Al cambiar el nombre del comando, escríbelo en la configuración sin la /; luego ejecuta el comando que estaba activo seguido de reload para aplicar el cambio.

fonito12

puedo cambiar que el sfx suene para los que esten cerca de el que ejecuta el comando asi no esten involucrados? sin actualizar solo usando el config

Kodari AI
KodariSep 24 at 9:08 pm 1

No, con la configuración actual no puedes cambiar quién oye los sonidos: puedes ajustar el sonido y cuántas veces se reproduce, pero no el público. Para que también lo escuchen los jugadores cercanos habría que modificar el plugin; después sí se podría añadir una opción configurable para el radio de escucha.

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

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.lang.reflect.Field;
import java.util.Locale;
import java.util.concurrent.ThreadLocalRandom;

public final class SnowMilkPlugin extends JavaPlugin implements Listener {
    private NamespacedKey specialMilkKey;
    private XParticle snowParticle;
    private Command registeredCommand;
    private String commandName;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        specialMilkKey = new NamespacedKey(this, "special_milk_bucket");
        loadSettings();
        getServer().getPluginManager().registerEvents(this, this);
        if (!registerConfiguredCommand()) {
            getLogger().severe("No se pudo registrar el comando configurado.");
        }
    }

    @Override
    public void onDisable() {
        if (registeredCommand != null) {
            registeredCommand.unregister(getCommandMap());
        }
        syncCommands();
    }

    private boolean registerConfiguredCommand() {
        String configuredName = getConfig().getString("command", "test");
        if (configuredName == null) {
            return false;
        }
        configuredName = configuredName.trim();
        while (configuredName.startsWith("/")) {
            configuredName = configuredName.substring(1);
        }
        if (!configuredName.matches("[a-zA-Z0-9_-]+")) {
            return false;
        }

        String newCommandName = configuredName.toLowerCase(Locale.ROOT);
        CommandMap commandMap;
        try {
            commandMap = getCommandMap();
        } catch (IllegalStateException exception) {
            getLogger().severe("No se pudo acceder al registro de comandos: " + exception.getMessage());
            return false;
        }

        Command newCommand = new Command(newCommandName) {
            @Override
            public boolean execute(CommandSender sender, String label, String[] args) {
                return executeConfiguredCommand(sender, label, args);
            }
        };
        newCommand.setDescription("Comando de efectos de nieve y leche especial.");
        newCommand.setUsage("/" + newCommandName + " <jugador> | /" + newCommandName + " reload");

        if (registeredCommand != null) {
            registeredCommand.unregister(commandMap);
        }
        if (!commandMap.register(getName().toLowerCase(Locale.ROOT), newCommand)) {
            newCommand.unregister(commandMap);
            registeredCommand = null;
            return false;
        }

        registeredCommand = newCommand;
        commandName = newCommandName;
        syncCommands();
        return true;
    }

    private boolean executeConfiguredCommand(CommandSender commandSender, String label, String[] args) {
        if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
            reloadConfig();
            loadSettings();
            if (registerConfiguredCommand()) {
                commandSender.sendMessage(message("messages.reload-success", "%command%", commandName));
            } else {
                commandSender.sendMessage(message("messages.reload-failed"));
            }
            return true;
        }

        if (!(commandSender instanceof Player sender)) {
            commandSender.sendMessage(message("messages.players-only"));
            return true;
        }
        if (args.length < 1) {
            sender.sendMessage(message("messages.usage", "%command%", label));
            return true;
        }

        Player target = Bukkit.getPlayerExact(args[0]);
        if (target == null) {
            sender.sendMessage(message("messages.player-not-found", "%player%", args[0]));
            return true;
        }

        double maxDistance = getConfig().getDouble("max-distance", 5.0);
        if (sender.getWorld() != target.getWorld()
                || sender.getLocation().distanceSquared(target.getLocation()) > maxDistance * maxDistance) {
            sender.sendMessage(message("messages.too-far", "%distance%", String.valueOf(maxDistance)));
            return true;
        }

        playCommandSounds(target);
        startSnowEffect(sender, target);
        if (giveSpecialMilk(sender, target)) {
            sender.sendMessage(message("messages.milk-given", "%target%", target.getName()));
        } else {
            sender.sendMessage(message("messages.snow-only", "%target%", target.getName()));
        }
        return true;
    }

    private String message(String path, String... replacements) {
        String text = getConfig().getString(path, "");
        for (int i = 0; i + 1 < replacements.length; i += 2) {
            text = text.replace(replacements[i], replacements[i + 1]);
        }
        return ChatColor.translateAlternateColorCodes('&', text);
    }

    private void loadSettings() {
        snowParticle = XParticle.of(getConfig().getString("snow.particle", "SNOWFLAKE"))
                .or(() -> XParticle.of("SNOW_SHOVEL"))
                .or(() -> XParticle.of("CLOUD"))
                .orElse(null);
    }

    private CommandMap getCommandMap() {
        try {
            Field field = getServer().getClass().getDeclaredField("commandMap");
            field.setAccessible(true);
            return (CommandMap) field.get(getServer());
        } catch (ReflectiveOperationException exception) {
            throw new IllegalStateException(exception);
        }
    }

    private void syncCommands() {
        try {
            getServer().getClass().getMethod("syncCommands").invoke(getServer());
        } catch (ReflectiveOperationException ignored) {
        }
    }

    private void playCommandSounds(Player target) {
        XSound.matchXSound(getConfig().getString("sounds.milk", "ENTITY_COW_MILK"))
                .ifPresent(sound -> sound.play(target));

        int soundCount = Math.max(0, getConfig().getInt("sounds.slime-step-count", 3));
        long interval = Math.max(1L, getConfig().getLong("sounds.slime-step-interval-ticks", 5L));
        if (soundCount == 0) {
            return;
        }

        new BukkitRunnable() {
            private int played;

            @Override
            public void run() {
                if (played >= soundCount || !target.isOnline()) {
                    cancel();
                    return;
                }
                XSound.matchXSound(getConfig().getString("sounds.slime-step", "BLOCK_SLIME_BLOCK_STEP"))
                        .ifPresent(sound -> sound.play(target));
                played++;
            }
        }.runTaskTimer(this, 0L, interval);
    }