Paste #69075: Admin Notes

Date: 2020/05/16 03:36:33 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# +--------------------
# |
# | A d m i n  N o t e s
# |
# | Add, delete and read admin notes about users
# |
# +----------------------
#
# @author Spirion
# @date 2020/05/13
# @denizen-build DEV-4786
#
# Installation:
# Just put the script in your scripts folder and reload.
#
# Usage:
# You will need to assign an administrator the "admin" flag from Denizen
# To check if a user has notes, type /notes [player]
# To add a new note, type /notes add [player] [note here]. It will automatically add the administrator name and the date at the end.
# To delete some note, type /notes del [player] [index]
# When a player has notes, it will appear a message next to its login text indicating it. You can click on this notes information to read them.
#
# ---------------------------- END HEADER ----------------------------
AdminNotesCommand:
    type: command
    debug: false
    name: notes
    usage: /notes [player]
    description: Show a player's notes.
    script:
        # Permissions check
        - if !<player.has_flag[admin]>:
            - narrate "<red>You don't have permission to use this command."
            - stop
        # We check how many arguments were typed
        - define size:<context.args.size>
        - choose <[size]>:
            - case 1:
                # Check if they tried to type the command and is incomplete
                - define arg1:<context.args.get[1]>
                - if <[arg1]> == del || <[arg1]> == add:
                    - narrate "<&c>Not enough arguments. Try:"
                    - narrate "<&c>/notes add [player] [note]"
                    - narrate "<&c>/notes del [player] [index]"
                    - stop
                # Is it a player?
                - define target:<server.match_offline_player[<[arg1]>]||null>
                - if <[target]> == null:
                    - narrate "<&c>Unknown user '<&e><[arg1]><&c>'."
                    - stop
                - else:
                    - run adminNotesShow def:<[target]>
            - case >= 3:
                - define arg1:<context.args.get[1]>
                - define arg2:<context.args.get[2]>
                - define arg3:<context.args.get[3]>
                - choose <[arg1]>:
                    # If the player wants to delete a note
                    - case del:
                        - define target:<server.match_offline_player[<[arg2]>]||null>
                        - if <[target]> == null:
                            - narrate "<&c>Unknown user '<&e><[arg2]><&c>'."
                            - stop
                        - else:
                            - if !<[arg3].is_integer>:
                                - narrate "<&c>You must include a numerical index."
                                - narrate "<&c>/notes del [player] [index]"
                                - stop
                            - if <[arg3]> <= 0:
                                - narrate "<&c>Are you trying to break the script...?"
                                - stop
                            - if <[arg3]> > <[target].flag[note].size>:
                                - narrate "<&c>The index entered is not valid."
                                - stop
                            - run adminNotesDel def:<[target]>|<[arg3]>
                    # If the player wants to add a note
                    - case add:
                        - define target:<server.match_offline_player[<[arg2]>]||null>
                        - if <[target]> == null:
                            - narrate "<&c>Unknown user '<&e><[arg2]><&c>'."
                            - stop
                        - else:
                            - define totalArgs:<context.args.remove[1|2].space_separated>
                            - run adminNotesAdd def:<[target]>|<[totalArgs]>
                    # Is it a player?
                    - default:
                        - define target:<server.match_offline_player[<[arg1]>]||null>
                        - if <[target]> == null:
                            - narrate "<&c>Unknown user '<&e><[arg1]><&c>'."
                            - stop
                        - else:
                            - run adminNotesShow def:<[target]>
            - default:
                - narrate <empty>
                - narrate "<&e>---- Notes of players ----"
                - narrate "<&6>/notes [player]<&r> - Displays the notes of the indicated user."
                - narrate "<&6>/notes add [player] [note]<&r> - Add a note to the indicated user."
                - narrate "<&6>/notes del [player] [index]<&r> - Delete the note with the indicated index."
                - stop

adminNotesEvents:
    type: world
    debug: false
    events:
        on player joins bukkit_priority:highest:
            - if <player.has_flag[note]>:
                - define admin:<server.list_online_players_flagged[admin]>
                # Admins will get a personalized message
                - foreach <[admin]>:
                    - define target:<player>
                    - if <player.flag[note].size> == 1:
                        - narrate "<context.message> <&2><&o>(<player.flag[note].size> <&hover[Click to read]><&click[/anshow <[target]>]>note<&end_click><&end_hover>)" targets:<[value]>
                    - else:
                        - narrate "<context.message> <&2><&o>(<player.flag[note].size> <&hover[Click to read]><&click[/anshow <[target]>]>notes<&end_click><&end_hover>)" targets:<[value]>
                # All other users will see the default entry message, unmodified by Denizen
                - foreach <server.list_online_players.exclude[<[admin]>]>:
                    - narrate <context.message> targets:<[value]>
                - determine none

adminNotesShowCommand:
    type: command
    debug: false
    name: anshow
    description: A command to show notes on admin notes
    usage: /anshow [target]
    script:
        - if !<player.has_flag[admin]>:
            - narrate "<red>You don't have permission to use this command."
            - stop
        - define target:<context.args.get[1]>
        - run adminNotesShow def:<[target]>

adminNotesShow:
    type: task
    debug: false
    definitions: target
    script:
        - if !<[target].has_flag[note]>:
            - narrate "<&e>This user has no notes..."
            - stop
        # If the user has more than 5 notes, it will distribute them in pages
        - else if <[target].flag[note].size> > 5:
            - define page:1
            - run adminNotesShowMore def:<[target]>|<[page]>
        # If the user has 5 or less notes, all the information is displayed directly
        - else:
            - narrate <empty>
            - narrate "<&e>----- Notes from <&a><[target].name> <&e>-----"
            - foreach <[target].flag[note]>:
                - narrate "<&6><[loop_index]>. <&r><[value]>"

adminNotesDel:
    type: task
    debug: false
    definitions: target|arg3
    script:
        - flag <[target]> note:<-:<[target].flag[note].get[<[arg3]>]>
        - narrate "<&a><[target].name><&e>'s note deleted."

adminNotesAdd:
    type: task
    debug: false
    definitions: target|totalArgs
    script:
        - flag <[target]> "note:->:<[totalArgs]> <&b><&o><player.name> <&8>(<util.date.time.year>/<util.date.time.month>/<util.date.time.day>)"
        - narrate "<&a><[target].name><&e>'s note added."

adminNotesShowMore:
    type: task
    debug: false
    definitions: target|page
    script:
        - narrate <empty>
        - narrate "<&e>----- Notes from <&a><[target].name> <&e>-----"

        # To know which page to show we make a calculus.
        # Page = p. Last note (n) of the page = 5 * p. First note of the page = n - 4
        # p = from (n-4) to (5*p)
        # Each page whil show the last note (n), that will be the number of the page (p) multiplied by 5. The first note will be n - 4.
        - define totalPages:<[target].flag[note].size.div[5].round_up>
        - define toNotes:<[page].mul[5]>
        - define fromNotes:<[toNotes].sub[4]>

        - foreach <[target].flag[note].get[<[fromNotes]>].to[<[toNotes]>]>:
            - narrate "<&6><[fromNotes]>. <&r><[value]>"
            - define fromNotes:++
            - if <[loop_index]> == 5:
                - if <[page]> == 1:
                    - narrate "<&e>-----       <&6><[page]>/<[totalPages]>  <&a><&click[/anaddpage <[target]> <[page]>]><&gt><&gt><&gt>  <&end_click><&e>-----"
                    - stop
                - if <[page]> > 1 && <[page]> < <[totalPages]>:
                    - narrate "<&e>-----<&a><&click[/andelpage <[target]> <[page]>]>  <&lt><&lt><&lt><&end_click>  <&6><[page]>/<[totalPages]>  <&a><&click[/anaddpage <[target]> <[page]>]><&gt><&gt><&gt>  <&end_click><&e>-----"
                    - stop
        - if <[page]> == <[totalPages]>:
            - narrate "<&e>-----<&a><&click[/andelpage <[target]> <[page]>]>  <&lt><&lt><&lt><&end_click>  <&6><[page]>/<[totalPages]>       <&e>-----"

adminNotesDelPages:
    type: command
    debug: false
    name: andelpage
    description: A command to turn the page on admin notes
    usage: /andelpage [player] [page]
    script:
        - if !<player.has_flag[admin]>:
            - narrate "<red>You don't have permission to use this command."
            - stop
        - define page <context.args.get[2]>
        - define page:--
        - define target:<context.args.get[1]>
        - run adminNotesShowMore def:<[target]>|<[page]>

adminNotesAddPages:
    type: command
    debug: false
    name: anaddpage
    description: A command to turn the page on admin notes
    usage: /anaddpage [player] [page]
    script:
        - if !<player.has_flag[admin]>:
            - narrate "<red>You don't have permission to use this command."
            - stop
        - define page <context.args.get[2]>
        - define page:++
        - define target:<context.args.get[1]>
        - run adminNotesShowMore def:<[target]>|<[page]>