################################################################################ # # # M e s s a g e C o n s t r u c t o r # # L I B R A R Y # # # # A set of utilities to make displaying text pretty, uniform, and easy # # # # Authors: |Anthony| # # Version: 0.5 # # dScript Version: 1.0.3-DEV_b691 # # # # For bleeding-edge code, bug reports, code contributions, and feature # # requests, visit the GitHub project: # # - github.com/AnthonyAMC/Public-Denizen-Scripts/blob/master/MessageConstructors.yml # # # Has my work helped you in some way? Show your support by clicking the # # Like button. # # Feeling generous? Get me a coffee :D # # https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NPXKHCNMTGSUG # # #-------------------------------------- # # # #--- About this script # # # # # # This library will be a dependency for nearly all of my scripts. Mainly so # # I don't have to duplicate the code so much, but also because it makes # # development and maintenance easier. # # # # Other scripters are free to implement this library in their own scripts. # # Just make sure you credit the author. If you are releasing a script that # # uses this library, be sure to tell your users to install it from here. # # Do not include this library, or parts of it, directly in your public # # scripts. # # # # # ################################################################################ # # Example Usages: # # - narrate "click <&e>this|google.com/search|<&9>click]><&f> link" # # - narrate "read the <&e>help|help|<&a>click here fool!]><&f> docs" # # - narrate "hover your mouse on the <&e>secret|<&6>gold star!]><&f> message" # # - narrate "click <&e>yes|yes|Click this]><&f> to make your player say yes in chat" # # - narrate "Give the player a <&e>Command|command|Click this]><&f> hint" # # - narrate " <&e>Suggest|Maybe say this|Click this]><&f> something for your player to type" # ################################################################################ # # Message Constructor Library Version # # Handles Versioning Checks # MSG_Version: type: version author: Anthony name: MessageConstructorLibrary version: 0.5 description: A Library for Message Construction id: 90 # #--------------------------------------- # MCL_Events: type: world debug: false events: on system time hourly: # - if !: # - queue clear # - if !contains 'q@MCL_UpdateCheck': - run locally delay:1t updateCheck 'id:MCL_UpdateCheck' - if !contains 'q@MCL_SendMetrics': - run locally delay:1t sendMetrics 'id:MCL_SendMetrics' on server start: - if !contains 'q@MCL_UpdateCheck': - run locally delay:1t updateCheck 'id:MCL_UpdateCheck' on script reload: - if !contains 'q@MCL_UpdateCheck': - run locally delay:1t updateCheck 'id:MCL_UpdateCheck' updateCheck: - ^if !: # - ~webget "https://raw.githubusercontent.com/AnthonyAMC/Public-Denizen-Scripts/master/versions/MCL.txt" save:page - ~webget "https://one.denizenscript.com/denizen/repo/version/" save:page - ^define result '' - ^if !: - define result 'unknown' - ^flag server "MCL.Version.Repo:" d:1h - ^define repoVersion '' - ^define currentVersion '' - ^if '' == 'unknown': - run s@msgPrefixed instantly 'def:MCL|<&7>Unable to check for update! <&7><&o><&7> is installed!' - else if '' > '': - run s@msgPrefixed instantly 'def:MCL|<&7>Update from version <&o><&7> to <&o><&7>!' - else if '' != '': - run s@msgPrefixed instantly 'def:MCL|<&7>What happened? You are on version <&o><&7> and the repo says <&o><&7>!' sendMetrics: # - run s@msgPrefixed instantly 'def:MCL|<&3>Sending usage metrics...' - ~webget "http://stats.denizenscript.com/tracker?script=&version=&players=&denizen_version=&jenkins_build=&bukkit_version=" 'save:send' - if !: - run s@msgPrefixed instantly 'def:MCL|<&c>Metrics failed!' # #--------------------------------------- # ################################################################################ # # #-------------------------------------- # # Message Prefixer # # - Pop-Up on hover shows your script title and 'Click for Help' # - Clicking the prefix runs / help # - Long messages are automatically linewrapped # # Usage: # - run s@msgPrefixed 'def:|<&c>' # msgPrefixed: type: item debug: false definitions: title|msg material: i@human_skull display name: "<&4> [<&6>---<&4>]" lore: - <&5>Click for Help script: - ^define text '<&4>[<&6><&4>]' - ^if !: - announce to_console " " - goto 'end' - ^define icon 'i@human_skull[display_name=]>]' - ^adjust 'lore:<&sp>|<&5> Click for Help' save:item - ^define hover '{}' - ^define click '/ help' - ^define button '"text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_item","value":""}' - ^define spacer '"text":" "' - ^foreach '>|]>]>': - ^execute as_server 'tellraw {"text":"","extra":[{},{},{"text":""}]}' - mark 'end' # # END msgPrefixed #-------------------------------------- # # Boxed Message # # - Encapsulate your messages in a neat and tidy box format # Messages sent through will be linewrapped and given a header and footer # - Header displays specified script title, page title, and page number(s) # - Page numbers are clickable to ease navigation # - Footer can display clickable buttons for your script authors # - You must have a valid author item script named _Author_ # # Definitions Explained: # # - The prefix used to find your authors # - The title to display in the Header # - The subtitle to display in the Header # - The command to run when the page buttons are clicked # - The current page to display # - How many characters (roughly) to display on one line # - How many lines in the body of the message should be on one page # - The complete contents of the document your are working with. # Every entry in the list is displayed on its own line. Long # entries are automatically linewrapped to fit the box message. # # Usage: # - run s@msgBoxed 'def:|||||||' # msgBoxed: type: task debug: false definitions: script|title|subTitle|command|page|pageWidth|pageHeight script: - ^define entries '' - ^foreach 'li@script|title|subTitle|command|page|pageWidth|pageHeight': - define ']>' - ^define paragraphs '|]>' - ^if < 1: - define page '1' - ^define pageInfo '||]>' - ^define pageTotal '' - ^if > : - define page '' - ^define lines ']>' - ^define cList 'li@0/black|1/dark_blue|2/dark_green|3/dark_aqua|4/dark_red|5/dark_purple|6/gold|7/gray|8/dark_gray|9/blue|a/green|b/aqua|c/red|d/light_purple|e/yellow|f/white|k/obfuscated|l/bold|m/strikethrough|n/underline|o/italic|r/reset' - ^define i 0 - ^foreach 'li@title|subTitle': - define this '' - define thisValue ']>' - define clean 'li@' - foreach '': - define i - define word '' - if '' == '': - define clean '].include[<&sp>]>' - foreach next - if !<&ss>@<&ss><&chr[260f]>]>: - define clean '].include[]>' - foreach next - define text '<&ss>@<&ss><&chr[260f]>].split[_-_].get[2].replace[\u0026].with[&].unescaped>' - define '<&bs>u0026]>' - define clean '].include[]>' - define clean '].separated_by[<&sp>]>' - ^define hpad '' - ^define heading '].with[<&sp>]> ' - ^define pagesInfo '<&7><&o>Page <&f> <&7><&o>of <&f>' - ^define pad '].sub[].mul[1.5].round>' - ^if !: - ^announce to_console "<&5>|<&pipe.pad_left[].with[-]>" - ^announce to_console "<&5>|<&sp><&sp><&sp><&6> <&7.pad_right[].with[ ]>" - ^announce to_console "<&5>|<&f>" - ^foreach : - announce to_console "<&5>|<&f><&sp><&sp>" - ^announce to_console "<&5>|" - ^inject locally msgsFooter - ^queue clear - ^define finalHeading 'li@' - ^foreach '': - define c '' - if '' == '': - if : - define c '' - else: - define c 'white' - else: - define c ']>' - define lc '' - if ].exists>: - define split '].after[<&ss>@<&ss><&chr[260f]>].split[_-_]>' - define type '' - define text ' ' - if '' == 'URL': - define url 'http<&co>//' - define hover '' - define button '"color":"","text":"","clickEvent":{"action":"open_url","value":""},"hoverEvent":{"action":"show_text","value":""}' - else if '' == 'command': - define tcommand '/' - define hover '' - define button '"color":"","text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - else if '' == 'hint': - define hint '/' - define hover '].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"suggest_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - else if '' == 'suggest': - define suggest '' - define hover '].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"suggest_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - else if '' == 'chat': - define chat '' - define hover '' - define button '"text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - else if '' == 'hover': - define hover '' - define button '"color":"","text":"","hoverEvent":{"action":"show_text","value":""}' - define finalHeading '}]>' - else: - if '' == '': - define value '&sp' - define finalHeading '","color":""}|{"text":"<&sp>"}]>' - ^define finalHeading '' - ^inject locally msgsHeader - ^inject locally msgsBody - ^inject locally msgsFooter msgsHeader: - ^if == 1: - define buttonThis '"text":"1"' - else: - define iconThis 'i@human_skull[display_name=]' - define hoverThis '{}' - define clickThis '/ ' - define buttonThis '"text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_item","value":""}' - ^if == : - define buttonNext '"text":""' - else: - define iconNext 'i@human_skull[display_name=]' - define hoverNext '{}' - define clickNext '/ ' - define buttonNext '"text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_item","value":""}' - ^define prefix '"text":"<&5>|<&sp><&sp><&sp><&6>"' - ^define tpad '"text":"<&7.pad_right[].with[ ]>"' - ^define p '"text":"<&7><&o>Page<&sp>"' - ^define o '"text":"<&7><&o><&sp>of<&sp>"' - ^narrate "<&5>|<&pipe.pad_left[].with[-]>" - ^execute as_server 'tellraw {"text":"","extra":[{},,{},{},{},{},{}]}' - ^narrate "<&5>|" msgsBody: - ^foreach : - narrate "<&5>|<&f><&sp><&sp>" - ^repeat ].as_int>: - narrate "<&5>|" - ^if contains 's@_Version': - define repoVersion '.Version.Repo]||unknown>' - define currentVersion '_Version.yaml_key[version]>' - define vString '<&7>Version<&co> <&b>' - define vPad '].add[1].mul[1.5].round>' - narrate "<&5>|<&f.pad_right[]>" - if '' != '': - define uString '<&c><&o>Repo Version<&co> <&b>' - define uPad '].add[1].mul[1.5].round>' - define url 'http://one.denizenscript.com/denizen/repo/entry/_Version.yaml_key[id]>' - narrate "<&5>|<&f.pad_right[]><&c><&o>Repo Version<&co> ||Click to go to repo!]>" - else: - narrate "<&5>|" msgsFooter: - ^define authors '_Author_]]||li@>' - ^if : - goto 'end' - ^define list 'li@' - ^define spacer '"text":" "' - ^define prefix '"text":"<&5>| <&f>Authors<&co> "' - ^foreach : - define text '' - define url '' - define entry '"text":"<&7>","clickEvent":{"action":"open_url","value":""},"hoverEvent":{"action":"show_item","value":"{}"}' - if == : - define list '<&rc>]>' - else: - define list '<&rc>|<&lc><&rc>]>' - ^if : - execute as_server 'tellraw {"text":"","extra":[{},]}' - else: - announce to_console "<&5>| <&f>Authors: <&7><&sp><&7>]>" - ^mark 'end' - ^define scroll '<&d>S<&5>-<&d>c<&5>-<&d>r<&5>-<&d>o<&5>-<&d>l<&5>-<&d>l<&5>---<&d>U<&5>-<&d>p<&5>' - ^define pad '].div[2].round_up>' - ^narrate "<&5><&pipe.pad_right[].with[-]>-<&pipe.pad_left[].with[-]>" # # END msgBoxed #-------------------------------------- # # URL Parser # # - Allow scripters to easily have clickable text to open urls, run commands, or just show messages on hover # # Example usages at the top of this file. # msgParser: type: world debug: false events: on player receives message: - if !@<&ss><&chr[260f]>]>: - queue clear - define message '].before_last[<&rb>]>' - foreach '].before_last[<&rc>].split[<&rc>,<&lc>].escape_contents>': - define element '' - foreach ',<&dq>]>': - define node '' - define attribute ']>' - define aValue ']>' - if '' != '<&dq>text<&dq>': - foreach next - if !<&ss>@<&ss><&chr[260f]>]>: - foreach next - define split '<&ss>@<&ss><&chr[260f]>].split[_-_]>' - define type '' - define text '' - choose '': - case 'URL': - define url 'http<&co>//' - define hover '].replace[\\u0026].with[&].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"open_url","value":""},"hoverEvent":{"action":"show_text","value":""}' - case 'command': - define command '/' - define hover '].replace[\\u0026].with[&].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - case 'hint': - define command '/' - define hover '].replace[\\u0026].with[&].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"suggest_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - case 'suggest': - define command '' - define hover '].replace[\\u0026].with[&].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"suggest_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - case 'chat': - define chat '' - define hover '].replace[\\u0026].with[&].replace[\u0026].with[&].unescaped>' - define button '"text":"","clickEvent":{"action":"run_command","value":""},"hoverEvent":{"action":"show_text","value":""}' - case 'hover': - define hover '].replace[\\u0026].with[&].replace[\u0026].with[&].unescaped>' - define button '"text":"","hoverEvent":{"action":"show_text","value":""}' - define message ']>]>' - determine 'RAW_JSON:{"extra":[],"text":""}' # # END URL Parser #-------------------------------------- # # Line Wrapping utility # # - Turn a long string into a list of smaller strings # Treats the <&nl> symbol as intended # Preserves the last color used from the previous line # # Usage: # lineWrap: type: procedure definitions: string|targetLen debug: false script: - define cleanString 'li@' - foreach '': - if '' == '': - define cleanString '' - foreach next - define word '' - if !<&ss>@<&ss><&chr[260f]>]>: - define cleanString ']>' - foreach next - define text '<&ss>@<&ss><&chr[260f]>].split[_-_].get[2].replace[\u0026].with[&].unescaped>' - define '<&bs>u0026]>' - define cleanString ']>' - if : - determine 'li@ ' - define cleanString '' - define stringLen '' - if <= : - define finalString 'li@' - foreach '': - if ].exists>: - define finalString ']>]>' - else: - if '' == '': - define value '&sp' - define finalString ']>' - determine '].as_list>' - define c '<&f>' - define lines 'li@' - while '': - define low '' - define hi '].as_int||>' - define pass ',]>' - if == : - define lines ']>' - while stop - else: - define brake ']>]:]>||]>>' - define increment ']||>' - define passtrim ']:||>]>' - define lines ']||>' - define c '>' - define stringLen ']>' - if : - while stop - define i '0' - define finalLines 'li@' - foreach '': - define finalString 'li@' - foreach '': - define i '' - if ].exists>: - define finalString ']>]>' - else: - if '' == '': - define value '<&sp>' - define finalString ']>' - define finalLines ']>]>' - determine '' # # END lineWrap #-------------------------------------- # # Pagination utility # # - Return a list of entries for display on a specific page # Pagination simply takes a list of entries, and the desired page length and # returns only the entries for the desired page number. # # Usage: # pagination: type: procedure definitions: page|pageSize debug: false script: - define entries '' - foreach 'li@page|pageSize': - define ']>' - if : - define page '1' - else: - define page '' - define pages '].round_up||1>' - if ]>: - define page '' - define highNumber '].as_int>' - define lowNumber '].as_int>' - determine 'li@||].to[].separated_by[|]||li@>' # # END pagination #-------------------------------------- # # Paragraph utility # # Turns a list of entries into a list of lines limited in length. # - Useful if you want to limit total page size not just entries per page. # # Usage: # paragraph: type: procedure definitions: lineLen debug: false script: - define paragraphs '' - define lineLen '' - define lineLen ']>]:||44>' - define result 'li@' - foreach '': - define lines '|]>' - foreach '': - define result ']>' - determine '' # # Put this inside the second foreach just before it closes to automatically # insert a newline at the end of each paragraph. # - define result ']>' # # END paragraph #-------------------------------------- # # Center Justified Utility # # Returns your text center justified based on target line length # # Usage: # msgCentered: type: procedure definitions: lineLen|string debug: false script: - define pad '].sub[].div[2].as_int>' - determine '<&6.pad_right[].with[<&sp>]><&6.pad_right[].with[<&sp>]>' # # END msgCentered #-------------------------------------- # # Trimmed Message Utility # # Returns your text trimmed to fit a specified length. # Extra text is shown as an elipsis... # # Usage: # msgTrim: type: procedure definitions: lineLen|string debug: false script: - if > : - determine '].escaped>...' - determine '' # # END msgTrim #-------------------------------------- # # URL Message Formatter # # Returns your text formatted for automatic conversion to JSON. # # Usage: ||]> # msgUrl: type: procedure definitions: display|url|hover debug: false script: - determine '<&r><&ss>@<&ss><&chr[260f]>URL_-__-__-_<&r>' # # END msgUrl #-------------------------------------- # # Command Message Formatter # # Returns your text formatted for automatic conversion to JSON. # # Usage: ||]> # msgCommand: type: procedure definitions: display|command|hover debug: false script: - determine '<&r><&ss>@<&ss><&chr[260f]>command_-__-__-_<&r>' # # END msgCommand #-------------------------------------- # # Hover Message Formatter # # Returns your text formatted for automatic conversion to JSON. # # Usage: |]> # msgHover: type: procedure definitions: display|hover debug: false script: - determine '<&r><&ss>@<&ss><&chr[260f]>hover_-__-_<&r>' # # END msgHover #-------------------------------------- # # Hint Message Formatter # # Returns your text formatted for automatic conversion to JSON. # # Usage: ||]> # msgHint: type: procedure definitions: display|hint|hover debug: false script: - determine '<&r><&ss>@<&ss><&chr[260f]>hint_-__-__-_<&r>' # # END msgHint #-------------------------------------- # # Suggest Message Formatter # # Returns your text formatted for automatic conversion to JSON. # # Usage: ||]> # msgSuggest: type: procedure definitions: display|suggest|hover debug: false script: - determine '<&r><&ss>@<&ss><&chr[260f]>suggest_-__-__-_<&r>' # # END msgSuggest #-------------------------------------- # # Chat Message Formatter # # Returns your text formatted for automatic conversion to JSON. # This will make it so that a player chats the message they click. # Good for situations where an NPC is expecting chat input. # # Usage: ||]> # msgChat: type: procedure definitions: display|chat|hover debug: false script: - determine '<&r><&ss>@<&ss><&chr[260f]>chat_-__-__-_<&r>' # # END msgChat # # # ################################################################################