Paste #36139: Edit of P#36117 dFurnitureEditor

Date: 2016/09/15 08:24:34 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479


dFurnitureEditor_Version: 
  type: version 
  author: Xenmai
  name: dFurnitureEditor 
  version: 0.5
  description: An advanced menu for editing and placing/removing furniture props 
  id: 98
#   ___   ___   ___  ___ ___  ___  ___  __  __ ____       __    ___ ____  __ ____  ______  __ 
#  //    // \\  ||\\//|| ||\\//|| // \\ ||\ || || \\     (( \  //   || \\ || || \\ | || | (( \
# ((    ((   )) || \/ || || \/ || ||=|| ||\\|| ||  ))     \\  ((    ||_// || ||_//   ||    \\ 
#  \\__  \\_//  ||    || ||    || || || || \|| ||_//     \_))  \\__ || \\ || ||      ||   \_))
#
dFurnitureEditor:
  type: command
  debug: false
  name: dfe
  description: "Main dFE command. Allows for editing and placing props."
  usage: /dfe [edit|place]
  aliases:
    - dfurnitureeditor
  allowed help: 
    - determine <player.is_op||<context.server>> 
  tab complete: 
    - if !<player.is_op||<context.server>> queue clear 
    - determine <li@edit|place.filter[starts_with[<context.args.last>]]>
  script:

    - if !<player.is_op||<context.server>> { 
      - narrate "<red>You do not have permission for that command." 
      - queue clear 
      } 
    - choose <context.args.get[1]>:

      # Opens the general dFE inventory GUI
      - case edit:
        - flag player CreateProp:!
        - flag player DeleteProp:!
        - flag player CreatePart:!
        - flag player DeletePart:!
        - flag player SetLocation:!
        - flag player SetAngle:!
        - flag player SetItem:!
        - flag player SetType:!
        - inventory open d:in@Editor_Menu

      # Places a prop at your current location.
      # For example, "/dfe place Stool" will place a created prop called Stool. 
      - case place:
        - define loc <player.location.block.center>
        - define yaw <player.location.yaw>
        #- light <def[loc].below> <def[loc].light>        
        - foreach <yaml[props].list_keys[<context.args.get[2]>]> {
          - define location l@<yaml[props].read[<context.args.get[2]>.<def[value]>.location]>
          - define angle <yaml[props].read[<context.args.get[2]>.<def[value]>.angle].split[,].as_list.parse[to_radians].separated_by[,]>
          - define small <yaml[props].read[<context.args.get[2]>.<def[value]>.small]>
          - define item <yaml[props].read[<context.args.get[2]>.<def[value]>.item]>
          - define type <yaml[props].read[<context.args.get[2]>.<def[value]>.type]>
          - spawn armor_stand[max_health=0.1;visible=false;gravity=false;is_small=<def[small]>;equipment=air|air|air|<def[item]>;armor_pose=head|<def[angle]>] <def[loc].add[<def[location].rotate_around_y[<def[yaw].to_radians.mul[-1]>]>].with_pose[0,<def[yaw]>]> save:<yaml[props].read[<context.args.get[2]>]>
          - if <def[type].is[==].to[sit]> {
            - flag <entry[<yaml[props].read[<context.args.get[2]>]>].spawned_entities.after[li@]> sit
          }
          else if <def[type].is[==].to[fire]> {
            - flag <entry[<yaml[props].read[<context.args.get[2]>]>].spawned_entities.after[li@]> fire
          }
          - define entities <def[entities]>|<entry[<yaml[props].read[<context.args.get[2]>]>].spawned_entities.after[li@]>
        }
        - define entities <def[entities].after[<&pipe>].as_list>
        - flag server <context.args.get[2]>_<def[loc]>:->:<def[entities]>
        - narrate "Placed <context.args.get[2]> at <def[loc]>!"

      # Removes a prop at your current location.
      # For example, "/dfe remove Stool" will remove a placed Stool at your location.       
      - case remove:
        - define loc <player.location.block.center>
        - remove <server.flag[<context.args.get[2]>_<def[loc]>]>
        #- light <def[loc].below> reset
        - flag server <context.args.get[2]>_<def[loc]>:!
        - narrate "Removed <context.args.get[2]> at <def[loc].simple>!"

      - default:

        - narrate "<&c>Invalid argument specified!"

# __    __   ___   ____  __    ____       __    ___ ____  __ ____  ______  __ 
# ||    ||  // \\  || \\ ||    || \\     (( \  //   || \\ || || \\ | || | (( \
# \\ /\ // ((   )) ||_// ||    ||  ))     \\  ((    ||_// || ||_//   ||    \\ 
#  \V/\V/   \\_//  || \\ ||__| ||_//     \_))  \\__ || \\ || ||      ||   \_))
#
dFE_Listener: 
  type: world
  debug: false
  events:

    # Loads the file, or creates it if it doesn't exist yet.
    on server start:

      - if <server.has_file[/dFurnitureEditor/props.yml]> {
        - yaml "load:/dFurnitureEditor/props.yml" id:props
      }
      else {
        - yaml create id:props

        - yaml id:props set props:->:Stool

        - define part li@Leg1|Leg2|Leg3|Leg4|Plank|Sitting
        - define location li@-0.1,-2.4,0.25|-0.25,-2.4,-0.1|0.1,-2.4,-0.25|0.25,-2.4,0.1|0,-1.35,0|0,-1.65,0
        - define angle li@0,0,0|0,90,0|0,180,0|0,270,0|0,0,0|0,0,0
        - define small li@false|false|false|false|false|false
        - define item li@stick|stick|stick|stick|wood_plate|air
        - define type li@normal|normal|normal|normal|normal|sit

        - repeat 6 {
          - yaml id:props set Stool.<def[part].get[<def[value]>]>.location:<def[location].get[<def[value]>]>
          - yaml id:props set Stool.<def[part].get[<def[value]>]>.angle:<def[angle].get[<def[value]>]>
          - yaml id:props set Stool.<def[part].get[<def[value]>]>.small:<def[small].get[<def[value]>]>
          - yaml id:props set Stool.<def[part].get[<def[value]>]>.item:<def[item].get[<def[value]>]>
          - yaml id:props set Stool.<def[part].get[<def[value]>]>.type:<def[type].get[<def[value]>]>
        }

        - yaml id:props set props:->:Log

        - define part li@Log1|Log2|Log3|Log4|Log5|Sitting1|Sitting2|Sitting3
        - define location li@0,-1.6,1|0,-1.6,0.375|0,-1.6,-0.25|0,-1.6,-0.875|0,-1.6,-1.5|0,-1.6,1|0,-1.6,0|0,-1.6,-1
        - define angle li@90,0,0|90,0,0|90,0,0|90,0,0|90,0,0|0,0,0|0,0,0|0,0,0
        - define small li@false|false|false|false|false|false|false|false
        - define item li@log|log|log|log|log|air|air|air
        - define type li@normal|normal|normal|normal|normal|sit|sit|sit

        - repeat 8 {
          - yaml id:props set Log.<def[part].get[<def[value]>]>.location:<def[location].get[<def[value]>]>
          - yaml id:props set Log.<def[part].get[<def[value]>]>.angle:<def[angle].get[<def[value]>]>
          - yaml id:props set Log.<def[part].get[<def[value]>]>.small:<def[small].get[<def[value]>]>
          - yaml id:props set Log.<def[part].get[<def[value]>]>.item:<def[item].get[<def[value]>]>
          - yaml id:props set Log.<def[part].get[<def[value]>]>.type:<def[type].get[<def[value]>]>
        }

        - yaml "savefile:/dFurnitureEditor/props.yml" id:props
      }

    # Saves and unloads the data.
    on shutdown:

      - yaml "savefile:/dFurnitureEditor/props.yml" id:props
      - yaml unload id:props

    # Places a created prop.
    on place command:

      - determine passively fulfilled

    # Listener for the Editor Menu. Prevents clicking items.
    on player clicks in Editor_Menu:
      - determine passively cancelled
      - choose <context.slot>:

        - case 1:
          - inventory close

        - case 3:
          - inventory close
          - narrate "Enter name for the new prop."
          - flag player CreateProp

        - case 4:
          - inventory close
          - narrate "Enter name of the prop to delete."
          - flag player DeleteProp

        - default:
          - if <context.item.material> == m@workbench {
            - inventory close
            - flag player Editing1:<context.item.display.strip_color>
            - inventory open d:in@Prop_Menu
          }

    # Prevents dragging items.
    on player drags in Editor_Menu:

      - determine cancelled

    # Listener for the Prop Menu. Prevents clicking items.
    on player clicks in Prop_Menu:

      - determine passively cancelled
      - choose <context.slot>:

        - case 1:
          - inventory close
          - inventory open d:in@Editor_Menu

        - case 3:
          - inventory close
          - narrate "Enter name for the new part."
          - flag player CreatePart

        - case 4:
          - inventory close
          - narrate "Enter name of the part to delete."
          - flag player DeletePart

        - default:
          - if <context.item.material> == m@armor_stand {
            - inventory close
            - flag player Editing2:<context.item.display.strip_color>
            - inventory open d:in@Part_Menu
          }

    # Prevents dragging items.    
    on player drags in Prop_Menu:

      - determine cancelled

    # Listener for the Part Menu. Prevents clicking items.
    on player clicks in Part_Menu:

      - determine passively cancelled
      - choose <context.slot>:

        - case 3:
          - inventory close
          - narrate "Enter location offset value as x,y,z."
          - flag player SetLocation

        - case 4:
          - inventory close
          - narrate "Enter head angle values as a,b,c."
          - flag player SetAngle 

        - case 5:
          - inventory close
          - narrate "Small state toggled."
          - if <yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.small]> == true {
            - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.small:false
          }
          else {
            - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.small:true
          }
          - yaml "savefile:/dFurnitureEditor/props.yml" id:props
          - inventory open d:in@Part_Menu

        - case 6:
          - inventory close
          - narrate "Enter name of item to equip."
          - flag player SetItem

        - case 7:
          - inventory close
          - narrate "Enter type of the element (normal, sit and fire allowed)."
          - flag player SetType

        - case 1:
          - inventory close
          - inventory open d:in@Prop_Menu

    # Prevents dragging items.
    on player drags in Part_Menu:

      - determine cancelled

    # Listens to the chat as input for names and values.
    on player chats:

      # Enter name for the new prop.
      - if <player.has_flag[CreateProp]> {
        - determine passively cancelled
        # Checks for input to be alphanumerical & _.
        - if <context.message.matches[<&lb>a-zA-Z0-9_<&rb>+].not> {
          - narrate "Prop names must be alphanumerical & _, please try again with a valid name."
          - queue clear
        }
        - if <yaml[props].read[props].contains[<context.message>]> {
          - narrate "Prop name <context.message> already in use!"
        }
        else {
          - yaml id:props set props:->:<context.message>
          - yaml "savefile:/dFurnitureEditor/props.yml" id:props
          - narrate "Prop <context.message> created!"
        }
        - flag player CreateProp:!
        - inventory open d:in@Editor_Menu
      }

      # Enter name of prop to delete.
      else if <player.has_flag[DeleteProp]> {
        - determine passively cancelled
        - if <yaml[props].read[props].contains[<context.message>]> {
          - yaml id:props set props:<-:<context.message>
          - yaml id:props set <context.message>:!
          - yaml "savefile:/dFurnitureEditor/props.yml" id:props
          - narrate "Prop <context.message> deleted!"
        }
        else {
          - narrate "Prop <context.message> doesn't exist!"
        }
        - flag player DeleteProp:!
        - inventory open d:in@Editor_Menu
      }

      # Enter name for the new part.
      else if <player.has_flag[CreatePart]> {
        - determine passively cancelled
        # Checks for input to be alphanumerical & _.
        - if <context.message.matches[<&lb>a-zA-Z0-9_<&rb>+].not> {
          - narrate "Part names must be alphanumerical & _, please try again with a valid name."
          - queue clear
        }
        - if <yaml[props].list_keys[<player.flag[Editing1]>].contains[<context.message>]> {
          - narrate "Part name already in use!"
        }
        else {
          - yaml id:props set <player.flag[Editing1]>.<context.message>.location:0,0,0
          - yaml id:props set <player.flag[Editing1]>.<context.message>.angle:0,0,0
          - yaml id:props set <player.flag[Editing1]>.<context.message>.small:false
          - yaml id:props set <player.flag[Editing1]>.<context.message>.item:stone
          - yaml id:props set <player.flag[Editing1]>.<context.message>.type:normal
          - yaml "savefile:/dFurnitureEditor/props.yml" id:props
          - narrate "Part <context.message> created!"
        }
        - flag player CreatePart:!
        - inventory open d:in@Prop_Menu
      }

      # Enter name of part to delete.
      else if <player.has_flag[DeletePart]> {
        - determine passively cancelled
        - if <yaml[props].list_keys[<player.flag[Editing1]>].contains[<context.message>]> {
          - yaml id:props set <player.flag[Editing1]>.<context.message>:!
          - yaml "savefile:/dFurnitureEditor/props.yml" id:props
          - narrate "Part <context.message> deleted!"
        }
        else {
          - narrate "Part <context.message> doesn't exist!"
        }
        - flag player DeletePart:!
        - inventory open d:in@Prop_Menu
      }

      # Enter location offset value as x,y,z.
      else if <player.has_flag[SetLocation]> {
        - determine passively cancelled
        - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.location:<context.message>
        - yaml "savefile:/dFurnitureEditor/props.yml" id:props
        - narrate "Location offset set to <context.message>!"
        - flag player SetLocation:!
        - inventory open d:in@Part_Menu
      }

      # Enter head angle values as a,b,c.
      else if <player.has_flag[SetAngle]> {
        - determine passively cancelled
        - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.angle:<context.message>
        - yaml "savefile:/dFurnitureEditor/props.yml" id:props
        - narrate "Rotation angle set to <context.message>!"
        - flag player SetAngle:!
        - inventory open d:in@Part_Menu
      }

      # Enter item name to equip.
      else if <player.has_flag[SetItem]> {
        - determine passively cancelled
        - if <li@sit|fire.contains[<yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.type]>]> {
          - narrate "You can't give an item to a this type of element! Please change the element type to normal first."
          - queue clear
        }
        - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.item:<context.message>
        - yaml "savefile:/dFurnitureEditor/props.yml" id:props
        - narrate "Item name set to <context.message>!"
        - flag player SetItem:!
        - inventory open d:in@Part_Menu
      }

      # Enter element type.
      else if <player.has_flag[SetType]> {
        - determine passively cancelled
        - if <li@normal|sit|fire.contains[<context.message>].not> {
          - narrate "Invalid element type! Valid types are normal, sit and fire."
          - queue clear
        }
        - if <li@sit|fire.contains[<context.message>]> {
          - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.item:air
          - narrate "Element item set to air!"
        }
        - yaml id:props set <player.flag[Editing1]>.<player.flag[Editing2]>.type:<context.message>
        - yaml "savefile:/dFurnitureEditor/props.yml" id:props
        - narrate "Element type set to <context.message>!"
        - flag player SetType:!
        - inventory open d:in@Part_Menu
      }

    # Listener for sitting components in placed props.
    on player right clicks at entity:
      - determine passively cancelled
      - define entity <context.entity.location.find.entities[armor_stand].within[2.0].filter[has_flag[sit]].get[1]>
      - if <def[entity]||null> == null {
        - queue clear
      }
      - if <def[entity].has_passenger> && <def[entity].passenger.is[!=].to[<player>]||false> {
        - narrate "That position is already occupied by another person!"
        - queue clear
      }
      - mount <player>|<def[entity]> <def[entity].location.with_pose[0,<player.location.yaw.add[180]>]>

    # Listener for fire components in placed props.
    on system time minutely:
      - foreach <w@world.entities.filter[has_flag[fire]]> {
        - define entity <def[value]>
        - repeat 120 {
          - if <def[entity].is_spawned.not||true> {
            - queue clear
          }
          - if <def[entity].location.find.entities[player].within[16].size.is[MORE].than[0]> {
            - playeffect <def[entity].location> effect:flame data:0.001 quantity:5 offset:0.1,0.1,0.1
          }
          - wait 10t
        }
      }

    # BC's data tracker.
    on system time hourly:
      - webget "http://stats.denizenscript.com/tracker?script=98&players=<server.list_online_players.size>"

# __ __  __ __ __  ____ __  __ ______   ___   ____  _  _     __    ___ ____  __ ____  ______  __ 
# || ||\ || || || ||    ||\ || | || |  // \\  || \\ \\//    (( \  //   || \\ || || \\ | || | (( \
# || ||\\|| \\ // ||==  ||\\||   ||   ((   )) ||_//  )/      \\  ((    ||_// || ||_//   ||    \\ 
# || || \||  \V/  ||___ || \||   ||    \\_//  || \\ //      \_))  \\__ || \\ || ||      ||   \_))
#
Editor_Menu:
  type: inventory
  debug: false
  inventory: chest
  size: 54
  title: "Editor Menu"
  slots:
    - "[i@green_wool[display_name=<&b>Exit]] [i@air] [] [] [i@air] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
  procedural items: 
  - define items "li@i@blue_wool[display_name=<&b>Create a new prop]|i@red_wool[display_name=<&b>Delete a prop]"
  - foreach <yaml[props].read[props].as_list.alphanumeric> {
    - define items "<def[items].include[i@workbench[display_name=<&b><def[value]>;lore=<&d>Parts:|<yaml[props].list_keys[<def[value]>].as_list.alphanumeric.after[li@]||None>]]>" 
  }
  - determine <def[items]>

Prop_Menu:
  type: inventory
  debug: false
  inventory: chest
  size: 54
  title: "Prop Menu"
  slots:
    - "[i@green_wool[display_name=<&b>Return]] [i@air] [] [] [i@air] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
  procedural items: 
  - define items "li@i@blue_wool[display_name=<&b>Create a new part]|i@red_wool[display_name=<&b>Delete a part]"
  - if <yaml[props].list_keys[<player.flag[Editing1]>].as_list.alphanumeric||null> != null {
    - foreach <yaml[props].list_keys[<player.flag[Editing1]>].as_list.alphanumeric> {
      - define items "<def[items].include[i@armor_stand[display_name=<&b><def[value]>;lore=<&d>Location: <&5><&o><yaml[props].read[<player.flag[Editing1]>.<def[value]>.location]>|<&d>Angle: <&5><&o><yaml[props].read[<player.flag[Editing1]>.<def[value]>.angle]>|<&d>Small: <&5><&o><yaml[props].read[<player.flag[Editing1]>.<def[value]>.small]>|<&d>Item: <&5><&o><yaml[props].read[<player.flag[Editing1]>.<def[value]>.item]>|<&d>Type: <&5><&o><yaml[props].read[<player.flag[Editing1]>.<def[value]>.type]>]]>" 
    }
  }
  - determine <def[items]>

Part_Menu:
  type: inventory
  debug: false
  inventory: chest
  size: 9
  title: "Part Menu"
  slots:
    - "[i@green_wool[display_name=<&b>Return]] [i@air] [] [] [] [] [] [] []"
  procedural items: 
  - define items "li@i@paper[display_name=<&b>Location;lore=li@<yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.location]>]|i@paper[display_name=<&b>Angle;lore=li@<yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.angle]>]|i@paper[display_name=<&b>Small;lore=li@<yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.small]>]|i@paper[display_name=<&b>Item;lore=li@<yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.item]>]|i@paper[display_name=<&b>Type;lore=li@<yaml[props].read[<player.flag[Editing1]>.<player.flag[Editing2]>.type]>]"
  - determine <def[items]>