Paste #13851: dRegions_WaterSpreadEvent RAW Event

Date: 2015/02/13 19:24:35 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


dRegions_WaterSpreadEvent:
  type: world
  debug: false
  events:
    on water spreads:
    - define world '<c.location.world.name.to_lowercase>'

    # Build list of dRegions for <c.location> in priority order
    - define regionPri 'li@'
    - foreach <c.location.cuboids.parse[notable_name].filter[split[_].get[1].is[==].to[dRegions]].parse[after[dregions_%world%_]].include[__global__]> {
      - define regionPri '<def[regionPri].include[<yaml[dRegions_%world%_regions].read[regions.%value%.priority]||0>/%value%]>'
      }
    - define oldLoc '<def[regionPri].alphanumeric.reverse.parse[split[/].get[2]].get[1]>'

    # Build list of dRegions for <c.destination> in priority order
    - define regionPri 'li@'
    - foreach <c.destination.cuboids.parse[notable_name].filter[split[_].get[1].is[==].to[dRegions]].parse[after[dregions_%world%_]].include[__global__]> {
      - define regionPri '<def[regionPri].include[<yaml[dRegions_%world%_regions].read[regions.%value%.priority]||0>/%value%]>'
      }
    - define orderedRegions '<def[regionPri].alphanumeric.reverse.parse[split[/].get[2]]>'

    # Block liquid from crossing region borders
    - if %oldLoc% != <def[orderedRegions].get[1]> determine cancelled

    # We want to control what blocks water is allowed to destroy when it flows
    - define target '<c.destination.material.bukkit_enum.to_lowercase>'

    # Check global and world config files
    - foreach '<el@val[%world%|global].as_list>' {
      - define settingValue '<yaml[dRegions_%value%_config].read[config.spread.water]||true>'
      - define targetList '<yaml[dRegions_%value%_config].read[config.spread.water-list]||li@>'
      - if %settingValue% {
        - if !<def[targetList].is_empty> {
          - if %targetList% !contains %target% {
            - determine CANCELLED
            }
          }
        }
      - if !%settingValue% {
        - if <def[targetList].is_empty> {
          - determine CANCELLED
          }
        - if %targetList% contains %target% {
          - determine CANCELLED
          }
        }
      }

    # Process water-spread region flag

    # Exhaustively search for a flag value
    - foreach %orderedRegions% {
      - define region %value%
      # Check the (currently) highest priority region for a flag value
      - define flagVal '<yaml[dRegions_%world%_regions].read[regions.%region%.flags.water-spread]||null>'
      # If it doesn't set the flag, exhaust its ancestry
      - if %flagVal% == null {
        - define thisRegion '%region%'
        - while <def[flagVal].is[==].to[null]||false> {
          - define thisRegion '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.parent]||null>'
          - if %thisRegion% == null {
            - while stop
            }
          - define flagVal '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.flags.water-spread]||null>'
          }
        }
      # If the flagVal is still null, check the next highest priority region for this location
      - if %flagVal% == null {
        # If there are no other regions at this location, set a default value
        - if %loop_index% == <def[orderedRegions].size> {
          - define flagVal '<def[FlagScript].yaml_key[flag_defaultValue]||allow>'
          }
          else foreach next
        }
      # Working with ONLY the current region, get a list of blocks water is/isn't allowed to destroy
      - define targetList '<yaml[dRegions_%world%_regions].read[regions.%region%.flags.water-spreadblocks]||null>'
      # If it doesn't set the flag, exhaust its ancestry
      - if %targetList% == null {
        - define thisRegion '%region%'
        - while <def[targetList].is[==].to[null]||false> {
          - define thisRegion '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.parent]||null>'
          - if %thisRegion% == null {
            - while stop
            }
          - define targetList '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.flags.water-spreadblocks]||null>'
          }
        # Set a default if we've exhausted the ancestry and still have no value for the targetList.
        - if %targetList% == null {
          - define targetList 'li@all'
          }
        }
      }

    # Now that we have a flagVal and a targetList, check for canceling

    # If the flag is set to allow, cancel the event as needed
    - if %flagVal% == allow {
      - if %targetList% != li@all {
        - if %targetList% !contains %target% {
          - determine cancelled
          }
        }
      - queue clear
      }

    # Must be a deny flag
    - if %targetList% == li@all {
      - determine cancelled
      }
    # Cancel the event if the target matches the list, otherwise it's not a denied target.
    - if %targetList% contains %target% {
      - determine cancelled
      }