Paste #4197: Untitled Paste

Date: 2014/05/08 11:58:04 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


################################################################################
#
# Configurations
#
# These are the default configurations. They will be used to build the user
# level config files on first run. Each parent node defines the file type and
# the child nodes that follow are the configurations for that config file type.
#
#

'WGRegionMarketConfigurations':
  type: task
  debug: false

# Where you save this script file
  scriptPath: 'scripts/Network/Utilities/WGRegionInfo.yml'


# ------ The main config file ------ #

  config:
    # Version Number DONT TOUCH
    version: 0.1

    # Price per block when claiming a region
    BlockPrice: 0.5

    # Percent of BlockPrice to refund when removing a region
    Refund: 80

    # Remove region from market list when occupied
    RemoveFromList:
      - sell
      - lease
      - rent

    # Can players extend rent region
    CanExtend: true

    # Number of times a rental can be extended. -1 for infinite
    MaxRentExtend: -1

    # Amount of time the player can extend their rent in advance.
    MaxRentExtendDuration: 30d

    # Tell Player his lease renewed
    ShowLeaseRenewMessage: true

    # Time before rent expires to remind player
    ShowRentExpireWarning: 20

    # Rollback region on lease or rent termination
    RollbackOnExpire:
      - let
      - rent

# ------


# ------ The limits config file ------ #

  limits:
    global:
      rent: -1
      lease: -1
      buy: -1
      sell: -1
    worlds:
      world:
        rent: -1
        lease: -1
        buy: -1
        sell: -1
    groups:
      default:
        global:
          rent: -1
          lease: -1
          buy: -1
          sell: -1
        worlds:
          world:
            rent: -1
            lease: -1
            buy: -1
            sell: -1

# ------


################################################################################
#
# WorldGuard Region Market Config Helper
#
#
# This script tells the s@ConfigFileGenerator which files to generate based on
# the configs above.
# 
"WGRegionMarketConfigHelper":
#
  type: task
  debug: true
  script:

    - ^define scriptPath '<s@WGRegionMarketConfigurations.constant[scriptPath]>'
    - ^define readID 'WGRegionMarket'
    - ^yaml 'load:<def[scriptPath]>' 'id:%readID%'

    - ^define keylist '<yaml[%readID%].list_keys[WGRegionMarketConfigurations].exclude[type|debug|scriptPath]>'

    - foreach <def[keylist]> {
      - define node <def[value]>

      - if !<server.has_file[Plots/%node%.yml]> {
        - narrate "<&a>Generating default %node%.yml file..."
        - define path 'WGRegionMarketConfigurations.%node%'
        - define writeID 'WGRegionMarket_%node%'
        - yaml create 'id:%writeID%'
        - inject s@ConfigFileGenerator p:loop
        - narrate "<&b>Done!"
        - yaml savefile:Plots/%node%.yml 'id:%writeID%'
        - yaml unload 'id:%writeID%'
        }
        else narrate "<&a>%node%.yml already exists!"
      }
    - yaml unload 'id:%readID%'


################################################################################
#
# Configuration File Generator
#
#
# This script generates default config files based on the definitions.
#   - run s@ConfigFileGenerator def:%readID%|%writeID%|%path%
# 
'ConfigFileGenerator':
  type: task
  debug: true

  script:
    - ^define readID '<def[1]>'
    - ^define writeID '<def[2]>'
    - ^define path '<def[3]>'
    - ^inject s@ConfigFileGenerator p:loop

  loop:
    - ^define keylist '<yaml[%readID%].list_keys[%path%]>'
    - if <def[dryrun]> {
      - narrate "<&a>keylist<&co> <&b>%keylist%"
      }
    - ^if <def[keylist].is[==].to[null]> {
      - define entry '<yaml[%readID%].read[%path%].as_list>'
      - if <def[dryrun]> {
        - narrate "<&a>entry<&co> <&b>%entry%"
        }
      - if !<def[entry].is_empty> {
        - foreach <def[entry]> {
          - if <def[dryrun]> {
            - narrate "<&a>%path%.%entry%<&co> <&b>%value%"
            }
            else yaml set '%path%.%entry%':->:<def[value]> 'id:%writeID%'
          }
        }
        else {
        - define entry '<yaml[%readID%].read[%path%]>'
        - if <def[dryrun]> {
          - narrate "<&a>%path%.%entry%<&co> <&c>EMPTY"
          }
          else yaml 'write:%path%.%entry%' 'id:%writeID%'
        }
      }
      else {
      - foreach <def[keylist]> {
        - define key '<def[value]>'
        - define path '%path%.%key%'
        - inject s@ConfigFileGenerator p:loop
        }
      }

#
################################################################################





"WGRegionMarketCommandHandler":
  type: world
  debug: false
  events:

    on wgrminit command:
    - define dryrun true
    - inject s@WGRegionMarketConfigHelper
    - inject s@FinishCommand