# Allows a player to set an npc's skin with a url using /npc skin [-u/--url] (slim) # Just drop this file into the Denizen/scripts folder and you're done! skin_url_handler: type: world debug: false events: on npc command: - if != skin: - queue clear - if !]>: - queue clear - determine passively fulfilled - define url - define model - if : - define npc - else: - define npc - if == null: - narrate "<&a>You must have an NPC selected to execute that command." - queue clear - if != PLAYER: - narrate "<&a>You must have a player-type NPC selected." - queue clear - if == null: - narrate "<&a>You must specify a valid skin URL." - queue clear - if != empty && != slim: - narrate "<&e><&a> is not a valid skin model. Must be <&e>slim<&a> or empty." - queue clear - narrate "<&a>Retrieving the requested skin..." - define key # Our own custom ~5s timeout since the builtin hangs - run skin_url_task def:|| id: instantly - while ]>: - if > 20: - queue q@ clear - narrate "<&a>The request timed out. Is the url valid?" - queue clear - wait 5t # Quick sanity check - ideally this should never be true - if !]>: - queue clear - if ]> == null: - narrate "<&a>Failed to retrieve the skin from the provided link. Is the url valid?" - flag server :! - queue clear - yaml loadtext:]> id:response - if !: - narrate "<&a>An unexpected error occurred while retrieving the skin data. Please try again." - else: - narrate "<&e><&a>'s skin set to <&e><&a>." - adjust skin_blob:; - flag server :! - yaml unload id:response skin_url_task: type: task debug: false definitions: key|url|model script: - define req "https://api.mineskin.org/generate/url" - if == slim: - define req "?model=slim" - ~webget "post:url=" timeout:5s save:res - flag server :