Date: 2020/05/16 03:36:33 UTC-07:00
Type: Denizen Script
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# +--------------------
# |
# | 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]>]><>><>><>> <&end_click><&e>-----"
- stop
- if <[page]> > 1 && <[page]> < <[totalPages]>:
- narrate "<&e>-----<&a><&click[/andelpage <[target]> <[page]>]> <<><<><<><&end_click> <&6><[page]>/<[totalPages]> <&a><&click[/anaddpage <[target]> <[page]>]><>><>><>> <&end_click><&e>-----"
- stop
- if <[page]> == <[totalPages]>:
- narrate "<&e>-----<&a><&click[/andelpage <[target]> <[page]>]> <<><<><<><&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]>