> For the complete documentation index, see [llms.txt](https://openjs.wiki.gd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openjs.wiki.gd/example-scripts/skull-grabber-dialog-ui.md).

# Skull grabber Dialog-UI

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHqXqB9FayGrV9U31bfmT%2Fuploads%2FvCucwDjfSMWMpYMn4Lud%2FMinecraft%202026.04.01%20-%2000.04.10.02.mp4?alt=media&token=7e492356-7302-4470-8b31-3aa724a91723>" %}

{% code title="SkullMenu.js" %}

```js
const Dialog = Services.get("DialogApi")
const InventoryApi = Services.get("InventoryApi")

const PlayerEntity =  importClass("org.bukkit.entity.Player");
const Bukkit = importClass("org.bukkit.Bukkit");

const URL = importClass("java.net.URL");
const Scanner = importClass("java.util.Scanner");
const UUID = importClass("java.util.UUID");
const Base64 = importClass("java.util.Base64");

const PlaceholderSkull = InventoryApi.createItem(
    {
        id: "minecraft:player_head",
        name: "§7Loading...",
        lore: ["§8No data yet"]
    })

function gradientText(text, fromRGB, toRGB) {
    function parseRGB(hex) {
        hex = hex.replace('#', '');
        return {
            r: parseInt(hex.substring(0, 2), 16),
            g: parseInt(hex.substring(2, 4), 16),
            b: parseInt(hex.substring(4, 6), 16)
        };
    }

    function toHex(n) {
        return ('0' + Math.round(n).toString(16).toUpperCase()).slice(-2);
    }

    var from = parseRGB(fromRGB);
    var to   = parseRGB(toRGB);
    var chars = text.split('');
    var len = chars.length;
    var result = '';

    for (var i = 0; i < len; i++) {
        var t = len <= 1 ? 0 : i / (len - 1);
        var r = from.r + (to.r - from.r) * t;
        var g = from.g + (to.g - from.g) * t;
        var b = from.b + (to.b - from.b) * t;
        result += '&#' + toHex(r) + toHex(g) + toHex(b) + chars[i];
    }

    return result;
}

// https://htmlcolorcodes.com/
const TitleText = gradientText("Skull grabber", "A8E1FF", "C9B0FF")
const EmptyUsernameText = gradientText("The username can't be empty!", "FF0050", "FF4C00")
const UpdateText = gradientText("Update skull", "77FF00", "00FFA6")
const GrabSkullText = gradientText("Get skull", "E642FF", "EA00FF")

function getJSON(url) {
    const stream = new URL(url).openStream();
    const scanner = new Scanner(stream).useDelimiter("\\A");
    const result = scanner.hasNext() ? scanner.next() : "";
    scanner.close();
    return JSON.parse(result);
}

function getSkull(username) {
    try {
        const uuidData = getJSON("https://api.mojang.com/users/profiles/minecraft/" + username); if (!uuidData || !uuidData.id) return null;
        const uuid = uuidData.id;
        const profileData = getJSON("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
        const property = profileData.properties[0];
        const skinHash = property.value

        const headItem = InventoryApi.createItem({
            id: "minecraft:player_head",
            name: "§e" + username + "'s Head",
            lore: ["§7Owner: §f" + username]
        });
        const meta = headItem.getItemMeta();

        const decoded = new java.lang.String(Base64.getDecoder().decode(skinHash));
        const json = JSON.parse(decoded);
        const skinUrl = json.textures.SKIN.url;
        const profile = Bukkit.createProfile(UUID.randomUUID());
        const textures = profile.getTextures();

        textures.setSkin(new URL(skinUrl));
        profile.setTextures(textures);
        meta.setOwnerProfile(profile);
        headItem.setItemMeta(meta);

        return headItem;
    } catch (e) {
        return null;
    }
}

function hasContent(str) {
    return typeof str === "string" && str.trim().length > 0;
}

addCommand("skullMenu", {
    onCommand: function(player) {
        if (!(player instanceof org.bukkit.entity.Player)) {
            sender.sendMessage("§cThis command can only be used by players.");
            return true;
        }

        let lastMessageTask = null
        let processingSkull = null
        let visible = true
        const dialog = Dialog.create(player)
            .title(TitleText)
            .bodyMessage("info", "View the skull of an player")
            .item("skullview", PlaceholderSkull, "Username: None")
            .textInput("usernameInput", "Input the username:")
            .columns(1)
            .baseButton("update", UpdateText)
            .baseButton("getskull", GrabSkullText).width(60)
            .exitButton(gradientText("Close Menu", "FF8742", "FF4242"))
        
        dialog.onEvent(function(event) {
            if (event.type === 'button') {
                if (event.id == "exit") {
                    dialog.close()
                } else {
                    if (processingSkull) {
                        return
                    }

                    processingSkull = true
                    task.thread(function() { // spawn thread so that the http request does not halt the server
                        const userName = event.get("usernameInput")
                        const isEmpty = !(hasContent(userName))
                        let skullItem = null

                        if (!isEmpty) {
                           skullItem = getSkull(userName)
                        }

                        processingSkull = false

                        if (!skullItem) {
                            if (isEmpty) {
                                dialog.setBodyMessage("info", EmptyUsernameText)
                            } else {
                                dialog.setBodyMessage("info", "The player " + userName + " does not exist!")
                            }
                            dialog.show()
                            lastMessageTask = task.delay(1.2, function() {
                                if (visible) {
                                    dialog.setBodyMessage("info", "View the skull of an player")
                                    dialog.show()
                                }
                                lastMessageTask = null
                            })
                            return
                        }

                        if (event.id == "getskull") {
                            player.getInventory().addItem(skullItem)
                            dialog.close()
                        } else {
                            dialog.setItem("skullview", skullItem, "Username: "+ gradientText(userName, "42FFFF", "42FFA7"))
                            dialog.show()
                        }
                    })
                }
            }

             if (event.type === "closed") {
                dialog.destroy()
                visible = false
            }
        })
        dialog.show()
    }
})
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://openjs.wiki.gd/example-scripts/skull-grabber-dialog-ui.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
