Skip to content

Commit 422c1c7

Browse files
committed
command permissions checking simplification
1 parent 01db94a commit 422c1c7

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

scripts/dmodels_command.dsc

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ dmodels_command:
2323
data:
2424
load_example: <&[error]>'path' should be a valid file name, for example if you have <&[emphasis]>data/dmodels/example.bbmodel<&[error]>, you should do: <&[warning]>/dmodels load example
2525
script:
26-
- choose <context.args.first||help>:
26+
- define arg1 <context.args.first||help>
27+
- if !<[arg1].matches_character_set[<script[dmodels_cmd_data].data_key[valid_chars]>]>:
28+
- define arg1 help
29+
- if !<player.has_permission[dmodels.<[arg1]>]>:
30+
- narrate "<&[error]>You do not have permission for that."
31+
- stop
32+
- choose <[arg1]>:
2733
- case load:
28-
- if !<player.has_permission[dmodels.load]>:
29-
- narrate "<&[error]>You do not have permission for that."
30-
- stop
3134
- if !<context.args.get[2].exists>:
3235
- narrate "<&[warning]>/dmodels load [path] <&[error]>- loads a model from file based on filename"
3336
- narrate <script.parsed_key[load_example]>
@@ -52,19 +55,13 @@ dmodels_command:
5255
- else:
5356
- narrate "<&[error]>Unable to load that model."
5457
- case loadall:
55-
- if !<player.has_permission[dmodels.loadall]>:
56-
- narrate "<&[error]>You do not have permission for that."
57-
- stop
5858
- ~run dmodels_gather_folder def.folder:data/dmodels save:list
5959
- define files <entry[list].created_queue.determination.first>
6060
- narrate "<&[base]>Loading <[files].size.custom_color[emphasis]> files..."
6161
- debug log "[DModels] <&[emphasis]><player.name||server> <&[base]>is loading <[files].size.custom_color[emphasis]> model files: <[files].formatted.custom_color[emphasis]>"
6262
- ~run dmodels_multi_load def.list:<[files]>
6363
- narrate <&[base]>Done!
6464
- case unload:
65-
- if !<player.has_permission[dmodels.unload]>:
66-
- narrate "<&[error]>You do not have permission for that."
67-
- stop
6865
- if !<context.args.get[2].exists>:
6966
- narrate "<&[warning]>/dmodels unload [model] <&[error]>- unloads a model's data from memory."
7067
- stop
@@ -79,15 +76,9 @@ dmodels_command:
7976
- flag server dmodels_data.animations_<[model]>:!
8077
- narrate "<&[base]>Removed model <[model].custom_color[emphasis]> from memory."
8178
- case unloadall:
82-
- if !<player.has_permission[dmodels.unloadall]>:
83-
- narrate "<&[error]>You do not have permission for that."
84-
- stop
8579
- flag server dmodels_data:!
8680
- narrate "<&[base]>Removed all DModels data from meory."
8781
- case spawn:
88-
- if !<player.has_permission[dmodels.spawn]>:
89-
- narrate "<&[error]>You do not have permission for that."
90-
- stop
9182
- if !<context.args.get[2].exists>:
9283
- narrate "<&[warning]>/dmodels spawn [model] <&[error]>- spawns a model at your position (must be loaded)"
9384
- stop
@@ -106,17 +97,11 @@ dmodels_command:
10697
- flag player spawned_dmodel_<[model]>:<[spawned]>
10798
- narrate "<&[base]>Spawned model <[model].custom_color[emphasis]> with root entity <[spawned].uuid.custom_color[emphasis]>, stored to player flag '<&[emphasis]>spawned_dmodel_<[model]><&[base]>'"
10899
- case remove:
109-
- if !<player.has_permission[dmodels.remove]>:
110-
- narrate "<&[error]>You do not have permission for that."
111-
- stop
112100
- inject dmodels_get_target
113101
- define model <[target].flag[dmodel_model_id]>
114102
- run dmodels_delete def.root_entity:<[target]>
115103
- narrate "<&[base]>Removed a spawned copy of model <[model].custom_color[emphasis]>."
116104
- case animate:
117-
- if !<player.has_permission[dmodels.animate]>:
118-
- narrate "<&[error]>You do not have permission for that."
119-
- stop
120105
- if !<context.args.get[2].exists>:
121106
- narrate "<&[warning]>/dmodels animate [animation] <&[error]>- causes the closest real-spawned model to start playing the given animation"
122107
- stop
@@ -130,19 +115,13 @@ dmodels_command:
130115
- run dmodels_animate def.root_entity:<[target]> def.animation:<[animation]>
131116
- narrate "<&[base]>Model <[target].flag[dmodel_model_id].custom_color[emphasis]> is now playing animation <[animation].custom_color[emphasis]>"
132117
- case stopanimate:
133-
- if !<player.has_permission[dmodels.stopanimate]>:
134-
- narrate "<&[error]>You do not have permission for that."
135-
- stop
136118
- inject dmodels_get_target
137119
- if !<[target].has_flag[dmodels_animation_id]>:
138120
- narrate "<&[base]>Your nearest model is not animating currently."
139121
- stop
140122
- run dmodels_end_animation def.root_entity:<[target]>
141123
- narrate "<&[base]>Animation stopped."
142124
- case npcmodel:
143-
- if !<player.has_permission[dmodels.npcmodel]>:
144-
- narrate "<&[error]>You do not have permission for that."
145-
- stop
146125
- if !<player.selected_npc.exists>:
147126
- narrate "<&[error]>You do not have any NPC selected."
148127
- stop
@@ -217,7 +196,9 @@ dmodels_tab_2:
217196
debug: false
218197
definitions: args
219198
script:
220-
- if <[args].first> == load && <player.has_permission[dmodels.load]||true>:
199+
- if !<[args].first.matches_character_set[<script[dmodels_cmd_data].data_key[valid_chars]>]> || !<player.has_permission[dmodels.<[args].first>]||true>:
200+
- determine <list>
201+
- if <[args].first> == load:
221202
- define path <[args].get[2]||>
222203
- if !<[path].to_lowercase.matches_character_set[<script[dmodels_cmd_data].data_key[valid_chars]>]>:
223204
- determine <list>
@@ -226,11 +207,13 @@ dmodels_tab_2:
226207
- else:
227208
- define path <empty>
228209
- determine <util.list_files[data/dmodels/<[path]>].parse[before_last[.bbmodel]]||<list>>
229-
- else if <[args].first> == spawn && <player.has_permission[dmodels.spawn]||true>:
210+
- if !<server.has_flag[dmodels_data]>:
211+
- determine <list>
212+
- if <[args].first> in spawn|unload:
230213
- determine <server.flag[dmodels_data].keys.filter[starts_with[model_]].parse[after[model_]]>
231-
- else if <[args].first> == npcmodel && <player.has_permission[dmodels.npcmodel]||true>:
214+
- else if <[args].first> == npcmodel:
232215
- determine <server.flag[dmodels_data].keys.filter[starts_with[model_]].parse[after[model_]].include[none]>
233-
- else if <[args].first> == animate && <player.has_permission[dmodels.animate]||true>:
216+
- else if <[args].first> == animate:
234217
- define target <player.location.find_entities[dmodel_part_stand].within[10].filter[has_flag[dmodel_model_id]].first||null>
235218
- if !<[target].is_truthy>:
236219
- determine <list>

0 commit comments

Comments
 (0)