Paste #59352: doorcloser

Date: 2019/10/24 22:23:31 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


doorcloser:
    type: world    
    debug: true

    events:    
        on player right clicks block:
            #If player is op & in creative just let them do whatever they want with the door
            - if <player.is_op> && <player.gamemode> = creative:
                - queue clear
            #If the block is a trapdoor ignore it
            - else if <context.location.material.contains_any[trap]>:
                - queue clear   
            #If the block is a door or a gate & it is closed
            - else if <context.location.material.contains_any[door|gate]> && !<context.location.switched>:
                #Let the script remember the recent interaction
                - flag <player> <context.location> duration:200t
                #Wait long enough to let the player through the door and not smack them in the rear
                - wait 100t
                #If the door is still open
                - if <context.location.switched>:
                    #Close the door
                    - switch <context.location>
                - else:
                    #The door must have been closed already!
                    - queue clear
            #If the player right clicks a block and it has an already open door or gate
            - else if <context.location.material.contains_any[door|gate]> && <context.location.switched>:
                #If they opened the door they are closing and have not recently been thanked for doing so
                - if <player.has_flag[<context.location>]> && !<player.has_flag[door_spamshield]>:
                    # thank the player
                    - narrate "Thanks for closing the door!"
                    # make sure it doesn't get annoying to close doors
                    - flag <player> door_spamshield duration:10m
                    - queue clear
                - else:
                    #Just let the door close
                    - queue clear
            - else:
                # this block is not a trapdoor, door, or a gate so do nothing
                - queue clear