You are browsing as a guest.
Login | Register
~ mcmonkey's simpler pastebin ~ Inspired by Hastebin ~ home page ~ Denizen help ~
click to use the normal pastebin instead ~ Click to make your own paste ~ click to duplicate and edit this paste


Title:
Type:
Date:
By:
Raw:
Other:
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
10700

Magic Sidebar
Denizen Script
2019/03/01 07:57:18 UTC-08:00
mcmonkey
Click here to view this paste as a raw text file | Or download the script


# +-------------------------
# |
# | M a g i c   S i d e b a r
# |
# | Provides a working live-updating per-player sidebar!
#
# @author mcmonkey
# @date 2019/03/01
# @denizen-build DEV-670
# @script-version 1.0
#
# Installation:
# 1. Put the script in your scripts folder.
# 2. Edit the config script below to your liking.
# 3. Reload
#
# Usage:
# Type "/sidebar" in-game to toggle the sidebar on or off.
#
# ---------------------------- END HEADER ----------------------------

# ------------------------- Begin configuration -------------------------
magic_sidebar_config:
    type: yaml data
    # How many updates per second (acceptable values: 1, 2, 4, 5, 10)
    per_second: 5
    # Set this to your sidebar title.
    title<&b><&l>Player Info
    # Set this to the list of sidebar lines you want to display.
    # Start a line with "[scroll:#/#]" to make it automatically scroll
    # with a specified width and scroll speed (characters shifted per second).
    # Note that width must always be less than the line's actual length.
    # There should also be at least one normal line that's as wide as the width, to prevent the sidebar resizing constantly.
    lines:
    - "[scroll:20/5]<&a>Welcome to <&6>my server<&a><&b><player.name><&a>!"
    - "<&8>-----------------------"
    - "Ping: <&b><player.ping>"
    - "Location: <&b><player.location.simple.before_last[,].replace[,].with[<&f>,<&b>]>"
    - "Online Players<&b><server.list_online_players.size><&f>/<&b><server.max_players>"
# ------------------------- End of configuration -------------------------

magic_sidebar_world:
    type: world
    debug: false
    events:
        on delta time secondly:
        - define per_second <script[magic_sidebar_config].yaml_key[per_second]>
        - define wait_time <el@1.div[<def[per_second]>]>s
        - define players <server.list_online_players.filter[has_flag[sidebar_disabled].not]>
        - define title <script[magic_sidebar_config].yaml_key[title]>
        - repeat <def[per_second]>:
            - sidebar title:<parse:<def[title]>> values:<proc[magic_sidebar_lines_proc]> players:<def[players]> per_player
            - wait <def[wait_time]>

magic_sidebar_lines_proc:
    type: procedure
    debug: false
    script:
    - define list <script[magic_sidebar_config].yaml_key[lines]>
    - foreach <def[list]> as:line:
        - define list_index <def[loop_index]>
        - define line <parse:<def[line]>>
        - if <def[line].starts_with[<&lb>scroll<&co>]>:
            - define width <def[line].after[<&co>].before[/]>
            - define rate <def[line].after[/].before[<&rb>]>
            - define line <def[line].after[<&rb>]>
            - define index <server.current_time_millis.div[1000].mul[<def[rate]>].round.mod[<def[line].strip_color.length>].add[1]>
            - define end <def[index].add[<def[width]>]>
            - repeat <def[line].length> as:charpos:
                - if <def[line].char_at[<def[charpos]>]> == <&ss>:
                    - define index <def[index].add[2]>
                - if <def[index]> <= <def[charpos]>:
                    - repeat stop
            - define start_color <def[line].substring[0,<def[index]>].last_color>
            - if <def[end]> > <def[line].strip_color.length>:
                - define end <def[end].sub[<def[line].strip_color.length>]>
                - repeat <def[line].length> as:charpos:
                    - if <def[line].char_at[<def[charpos]>]> == <&ss>:
                        - define end <def[end].add[2]>
                    - if <def[end]> < <def[charpos]>:
                        - repeat stop
                - define line "<def[start_color]><def[line].substring[<def[index]>]> <&f><def[line].substring[0,<def[end]>]>"
            - else:
                - repeat <def[line].length> as:charpos:
                    - if <def[line].char_at[<def[charpos]>]> == <&ss>:
                        - define end <def[end].add[2]>
                    - if <def[end]> < <def[charpos]>:
                        - repeat stop
                - define line "<def[start_color]><def[line].substring[<def[index]>,<def[end]>]>"
        - define list <def[list].set[<def[line]>].at[<def[list_index]>]>
    - determine <def[list]>

magic_sidebar_command:
    type: command
    name: sidebar
    usage: /sidebar
    description: Toggles your sidebar on or off.
    script:
    - if <player.has_flag[sidebar_disabled]>:
        - flag player sidebar_disabled:!
        - narrate "<&b>Sidebar enabled."
    - else:
        - flag player sidebar_disabled
        - narrate "<&b>Sidebar disabled."
        - wait 1
        - sidebar remove players:<player>