Paste #50778: Add a --url flag to /npc skin

Date: 2018/11/24 17:17:22 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# Allows a player to set an npc's skin with a url using /npc skin [-u/--url] <url>
skin_handler:
    type: world
    debug: false
    events:
        on npc command:
            - if <c.args.get[1]||null> != skin:
                - queue clear
            - if !<li@-u|--url.contains[<c.args.get[2]||null>]>:
                - queue clear
            - determine passively fulfilled

            - define url <c.args.get[3]||null>
            - if <c.server>:
                - define npc <server.selected_npc||null>
            - else:
                - define npc <player.selected_npc||null>

            - if <def[npc]> == null:
                - narrate "<&a>You must have an NPC selected to execute that command."
                - queue clear
            - if <def[url]> == null:
                - narrate "<&a>You must specify a valid skin URL."
                - queue clear

            - define file "temp-<server.current_time_millis>.yml"
            - ~webget "https://api.mineskin.org/generate/url" "post:url=<def[url]>" save:res

            - if <entry[res].failed>:
                - narrate "<&a>Failed to retrieve the skin from the provided link. Is the url valid?"
                - queue clear

            # TODO: This assumes the response is valid
            - log <entry[res].result> type:clear file:<def[file]>
            - narrate <entry[res].result>
            - yaml load:../../<def[file]> id:response
            - adjust <def[npc]> skin_blob:<yaml[response].read[data.texture.value]>;<yaml[response].read[data.texture.signature]>
            - yaml unload id:response
            - adjust server delete_file:../../<def[file]>