12345bartek

Generate a player head plugin that, when right-clicked, randomly selects one of five effects, applies it to the player, and then disappears from the player's inventory. The config should include space for the item name, item lore, head texture, and space for the types of possible random effects and cooldown. The plugin should have a reload command.

Kodari AI
KodariFeb 27 at 11:43 pm 10,988 (v2)

I’ll create a player head plugin with random potion effects, cooldown system, and reload command.

MysteryHead
A plugin that provides customizable player heads which grant random potion effects when used. Players right-click the head to receive one random effect from a configurable list, with the head being consumed on use. Features include per-player cooldowns, custom head textures via base64, configurable item appearance, and admin reload commands.

Plugin created successfully! Here’s what was implemented:

Core Features:

  • Right-click player head to get random potion effect

  • Head disappears after use

  • Per-player cooldown system (configurable in seconds)

  • Reload command: /mysteryhead reload

Configuration (config.yml):

  • Customizable head name and lore (supports color codes)

  • Base64 texture for custom head appearance

  • List of 5 random effects (format: EFFECT_NAME:duration:amplifier)

  • Cooldown timer in seconds

Technical Implementation:

  • Uses XSkull/Profileable for cross-version player heads

  • Uses XPotion for cross-version potion effects (1.8 to 1.21+)

  • FoliaLib for Folia-compatible scheduling

  • Cooldown manager tracks per-player usage

  • Item removed from inventory after use

  • Permission: mysteryhead.reload for reload command

12345bartek

improve the plugin to have a command to give the player a head and add a mini animation when drawing the effect.

Kodari AI
KodariFeb 27 at 11:50 pm 10,277 (v2)

I’ll improve the plugin by adding a give command and a particle animation when using the head.

Plan

  1. Create GiveCommand to give mystery heads to players

  2. Add particle animation when using the head (spiral effect)

  3. Update plugin.yml to register the give command

  4. Update config to include animation settings

  5. Update main class to register the new command

Plugin improved with give command (/giveysteryhead <player> [amount]) and particle spiral animation with sound when using the head.

12345bartek

add editable messages to the this plugin

Kodari AI
KodariFeb 27 at 11:58 pm 12,979 (v2)

I’ll add editable messages to the MysteryHead plugin. Let me first examine the existing files to identify all hardcoded messages.

Now I’ll add editable messages to the plugin by creating a MessageManager and messages.yml file.

All messages are now editable through the messages.yml file with support for color codes, placeholders, and a configurable prefix.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
11 590
src/main/java/com/mysteryhead/MysteryHead.java
package com.mysteryhead;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.profiles.builder.XSkull;
import com.cryptomorin.xseries.profiles.objects.Profileable;
import com.mysteryhead.commands.GiveCommand;
import com.mysteryhead.commands.ReloadCommand;
import com.mysteryhead.listeners.HeadUseListener;
import com.mysteryhead.managers.CooldownManager;
import com.mysteryhead.managers.MessageManager;
import com.tcoded.folialib.FoliaLib;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

@Getter
public class MysteryHead extends JavaPlugin {
    private FoliaLib foliaLib;
    private CooldownManager cooldownManager;
    private MessageManager messageManager;
    private final Random random = new Random();
    
    private ItemStack mysteryHead;
    private List<PotionEffect> possibleEffects;
    private long cooldownSeconds;
    private FileConfiguration messagesConfig;
    
    @Override
    public void onEnable() {
        this.foliaLib = new FoliaLib(this);
        this.cooldownManager = new CooldownManager();
        this.messageManager = new MessageManager(this);

        saveDefaultConfig();
        File messagesFile = new File(getDataFolder(), "messages.yml");
        if (!messagesFile.exists()) {
            saveResource("messages.yml", false);
        }
        loadMessagesConfig();
        loadConfiguration();
        
        Bukkit.getPluginManager().registerEvents(new HeadUseListener(this), this);
        
        ReloadCommand reloadCommand = new ReloadCommand(this);
        getCommand("mysteryhead").setExecutor(reloadCommand);
        
        GiveCommand giveCommand = new GiveCommand(this);
        getCommand("givemysteryhead").setExecutor(giveCommand);
        getCommand("givemysteryhead").setTabCompleter(giveCommand);
        
        getLogger().info("MysteryHead has been enabled!");
    }
    
    @Override
    public void onDisable() {
        if (foliaLib != null) {
            foliaLib.getScheduler().cancelAllTasks();
        }
        getLogger().info("MysteryHead has been disabled!");
    }
    
    public void loadMessagesConfig() {
        File messagesFile = new File(getDataFolder(), "messages.yml");
        this.messagesConfig = YamlConfiguration.loadConfiguration(messagesFile);
    }

    public FileConfiguration getMessagesConfig() {
        return messagesConfig;
    }

    public void loadConfiguration() {
        reloadConfig();
        loadMessagesConfig();
        
        String name = ChatColor.translateAlternateColorCodes('&', getConfig().getString("head.name", "&d&lMystery Head"));
        
        List<String> loreConfig = getConfig().getStringList("head.lore");
        List<String> lore = loreConfig.stream()
            .map(line -> ChatColor.translateAlternateColorCodes('&', line))
            .collect(Collectors.toList());
        
        String texture = getConfig().getString("head.texture", "");
        
        this.mysteryHead = createMysteryHead(name, lore, texture);
        this.cooldownSeconds = getConfig().getLong("cooldown", 60);
        this.possibleEffects = loadEffects();
        
        getLogger().info("Configuration loaded with " + possibleEffects.size() + " possible effects");
    }
    
    private ItemStack createMysteryHead(String name, List<String> lore, String texture) {
        ItemStack head;
        
        if (texture != null && !texture.isEmpty()) {
            head = XSkull.createItem().profile(Profileable.detect(texture)).apply();
        } else {
            head = XMaterial.PLAYER_HEAD.parseItem();
        }
        
        if (head != null) {
            ItemMeta meta = head.getItemMeta();
            if (meta != null) {
                meta.setDisplayName(name);
                meta.setLore(lore);
                head.setItemMeta(meta);
            }
        }
        
        return head;
    }
    
    private List<PotionEffect> loadEffects() {
        List<PotionEffect> effects = new ArrayList<>();
        List<String> effectStrings = getConfig().getStringList("effects");
        
        for (String effectStr : effectStrings) {
            String[] parts = effectStr.split(":");
            if (parts.length >= 3) {
                String effectName = parts[0];
                int duration = Integer.parseInt(parts[1]);
                int amplifier = Integer.parseInt(parts[2]);
                
                XPotion.matchXPotion(effectName)
                    .map(xp -> xp.buildPotionEffect(duration, amplifier))
                    .ifPresent(effects::add);
            }
        }
        
        return effects;
    }
    
    public boolean isMysteryHead(ItemStack item) {
        if (item == null || mysteryHead == null) return false;
        if (!item.hasItemMeta() || !mysteryHead.hasItemMeta()) return false;
        
        ItemMeta itemMeta = item.getItemMeta();
        ItemMeta headMeta = mysteryHead.getItemMeta();
        
        if (!itemMeta.hasDisplayName() || !headMeta.hasDisplayName()) return false;
        
        return itemMeta.getDisplayName().equals(headMeta.getDisplayName());
    }
    
    public PotionEffect getRandomEffect() {
        if (possibleEffects.isEmpty()) return null;
        return possibleEffects.get(random.nextInt(possibleEffects.size()));
    }
}