Paste #112507: ChunkLoad Command

Date: 2023/07/19 08:47:06 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


ChunkLoad_Data:
    type: data
    debug: false
    # Specify the worlds to disable flight in here.
    Disabled_Worlds:
    - Spawn
    - SpawnBuilds
    - Events

ChunkLoad_Command:
    type: command
    debug: true
    name: chunkload
    description: Keeps a single chunk loaded
    usage: /chunkload [remove]
    tab completions:
      1: remove
    permission: servername.user.chunkload
    script:
    - if <context.args.get[1].if_null[null]> == remove:
        - if <player.has_flag[LoadedChunk].not>:
            - narrate "<server.flag[ServerName]> <&7>» <&c>You do not have a loaded chunk"
            - stop
        - else:
            - define chunk <player.flag[LoadedChunk]>
            - chunkload remove <[chunk]>
            - flag server LoadedChunks:<-:<[chunk]>
            - flag <player> LoadedChunk:!
            - narrate "<server.flag[ServerName]> <&7>» <&6><[chunk].x>,<[chunk].z>,<[chunk].world.name> <&color[#87CEEB]>will no longer stay loaded."
            - stop
    - else:
        - define chunk <player.location.chunk>
        - if <script[ChunkLoad_Data].data_key[Disabled_Worlds].contains[<[chunk].world.name>]>:
            - narrate "<server.flag[ServerName]> <&7>» <&c>You cannot use this command in this world!"
            - stop
        - if <server.flag[LoadedChunks].if_null[<list>].contains[<[chunk]>]>:
            - narrate "<server.flag[ServerName]> <&7>» <&c>This command has already been used on this chunk!"
            - stop
        - if <player.has_flag[LoadedChunk].not>:
            - flag <player> LoadedChunk:<[chunk]>
            - flag server LoadedChunks:->:<[chunk]>
            - chunkload <[chunk]>
            - narrate "<server.flag[ServerName]> <&7>» <&6><[chunk].x>,<[chunk].z>,<[chunk].world.name> <&color[#87CEEB]>will now stay loaded while you are online"
            - stop
        - else:
            - chunkload remove <player.flag[LoadedChunk]>
            - flag server LoadedChunks:<-:<player.flag[LoadedChunk]>
            - flag <player> LoadedChunk:<[chunk]>
            - flag server LoadedChunks:->:<[chunk]>
            - chunkload <[chunk]>
            - narrate "<server.flag[ServerName]> <&7>» <&6><[chunk].x>,<[chunk].z>,<[chunk].world.name> <&color[#87CEEB]>will now stay loaded while you are online."
            - stop

ChunkLoad_Handler:
    type: world
    debug: false
    events:
        after player joins flagged:loadedchunk:
        - chunkload <player.flag[LoadedChunk]>
        after player quits flagged:loadedchunk:
        - chunkload remove <player.flag[LoadedChunk]>