Paste #7922: Untitled Paste

Date: 2014/08/05 23:25:13 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# ---------------------------------------------------------------------------- #
#                                                                              |
#                                                                              |
#                     S u b s c r i p t i o n   S y s t e m                    |
#                                                                              |
#             A system for giving players timed access to your server          |
#                                                                              |
#                                                                              |
#   Author: |Anthony|                                                          |
#   Version: 0.1                                                               |
#   dScript Version: 0.9.5-b150X                                               |
#                                                                              |
# ---------------------------------------------------------------------------- #
# 
# 
# ABOUT:
# 
# 
# 
# 
# USAGE:
# 
# 
# 
# 
# TODO - Future Feature Fluff:
#    
# 
# 
#______________________________________________________________________________#


'SubscriptionSystem':
  type: world
  debug: true

  events:

    on server start:
    - run locally start instantly delay:2s

    on player joins:
    - run locally join instantly


  load:
    # Loads the yaml files and generates default files if they don't exist.
    - announce "<&b>Loading Subscription System config files..." to_console
#
# This is the way i /should/ be doing it but the ConfigFileGenerator needs
# to be updated to support creating a single file from a script container.
# 
#    - define files '<yaml[Subscriptions_config].read[config.categories].as_list>'
#    - foreach files {
#      - if !<server.has_file[Subscriptions/%value%.yml]> {
#        - if <player> != null {
#          - flag <player> ConfigFileGeneratorNotify:true
#          - run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations|false|true|false instantly
#          - flag <player> ConfigFileGeneratorNotify:!
#          }
#          else run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations|%value% instantly
#        }
#
#   The ConfigFileGenerator will attempt to build every file if it's missing one of the files.
#
    - if !<server.has_file[SubscriptionSystem/config.yml]>
      || !<server.has_file[SubscriptionSystem/trial.yml]>
      || !<server.has_file[SubscriptionSystem/member.yml]>
      || !<server.has_file[SubscriptionSystem/expired.yml]> {
      - if <player> != null {
        - flag <player> ConfigFileGeneratorNotify:true
        - run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations|false|true|false instantly
        - flag <player> ConfigFileGeneratorNotify:!
        }
        else run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations instantly
      }
    - if <yaml.list.contains[Subscriptions_config]> yaml unload 'id:Subscriptions_config'
    - yaml 'load:SubscriptionSystem/config.yml' 'id:Subscriptions_config'
    - define categories '<yaml[Subscriptions_config].read[config.categories].as_list>'
    - foreach %categories% {
      - if <yaml.list.contains[Subscriptions_%value%]> yaml unload 'id:Subscriptions_%value%'
      - yaml 'load:SubscriptionSystem/%value%.yml' 'id:Subscriptions_%value%'
      }
    - announce "<&b>Subscriptions System config files Loaded!" to_console

  start:
    - inject locally load instantly
    - define categories '<yaml[Subscriptions_config].read[config.categories].as_list>'
    - foreach %categories% {
      - if <queue.exists[Subscriptions_%value%_timer]> {
        - queue queue:Subscriptions_%value%_timer stop
        }
      - run locally checkExpiredLoop 'def:%value%' delay:2s 'id:Subscriptions_%value%_timer'
      }

  checkExpiredLoop:
    - ^define wait '<yaml[Subscriptions_%1%].read[%1%.config.checkInterval].as_duration>'
    - ^wait %wait%
    - ^run locally checkAllExpired def:%1%
    - ^inject locally checkExpiredLoop

  checkAllExpired:
    - define players '<yaml[Subscriptions_%1%].list_keys[%1%.players]>'
    - define now '<server.current_time_millis>'
    - foreach %players% {
      - define expireDate '<yaml[Subscriptions_%category%].read[%category%.players.%value%]>'
      - if <def[expireDate].is[OR_LESS].than[%now%]> {
        - run locally setExpired as:<def[value].as_player>
        }
      }

  checkExpired:
    - define now '<server.current_time_millis>'
    - define player '<player.uuid>'
    - define categories '<yaml[Subscriptions_config].read[config.categories].as_list>'
    - foreach %categories% {
      - define category %value%
      - if <yaml[Subscriptions_%category%].list_keys[%category%.players].contains[%player%]> {
        - define expireDate '<yaml[Subscriptions_%category%].read[%category%.players.%player%]>'
        - if <def[expireDate].is[OR_LESS].than[%now%]> {
          - run locally setExpired def:%category% as:<player>
          }
        }
      }

  setExpired:
    - define player <player.name>
    - define expireAction '<yaml[Subscriptions_config].read[config.expireAction]>'
    - define externalCommands '<yaml[Subscriptions_config].read[config.expireCommandsExt].as_list>'
    - define internalCommands '<yaml[Subscriptions_config].read[config.expireCommandsInt].as_list>'
    - foreach %externalCommands% {
      - execute as_server '%value%'
      }
    - foreach %internalCommands% {
      - %value%
      }
    - if <def[expireAction].is[==].to[kick]> {
      - adjust <player> 'kick:<yaml[Subscriptions_config].read[config.kickMsg].parsed>'
      }
      else if <def[expireAction].is[==].to[ban]> {
      - execute as_server '<yaml[Subscriptions_config].read[config.banCmd].parsed>'
      }
      else if <def[expireAction].is[==].to[tp]> {
      - teleport <player> '<yaml[Subscriptions_config].read[config.tpLocation].as_location>'
      }
      else {
      - adjust <player> 'kick:<yaml[Subscriptions_config].read[config.kickMsg].parsed>'
      }

  join:
    - if <player.has_played_before> {
      - inject locally checkExpired
      }
      else {
      - inject locally firstJoin
      }

  firstJoin:
    - yaml 'write:<player.uuid>' 'value:<server.current_time_millis>' id:Subscriptions_trial




################################################################################
#                                                                              #
# Configuration Files                                                          #
#                                                                              #
#   These are the default config files. They will be used to build the default #
# config file and data storage files.                                          #
#                                                                              #
#______________________________________________________________________________#
#                                                                              #
#______________________________DO_NOT_EDIT_THIS_DATA___________________________#
#______________________________________________________________________________#

'SubscriptionSystem_Configurations':
  type: task
  debug: false

  # Where you save this script file
  scriptPath: 'scripts/SubscriptionSystem.yml'

  config:
    categories:
      - trial
      - members
    expireAction: kick
    kickMsg: 'Your subscription has expired'
    banCmd: ''
    tpLocation: ''
    expireCommandsExt:
      - 'perm player %player% setgroup expired'
    expireCommandsInt:
      - 'narrate "%player% your time has expired"'
    firstJoinCommandsExt:
      - 'perm player %player% setgroup trial'
    firstJoinCommandsInt:
      - 'narrate "%player% your time has expired"'


  trial:
    config:
      checkInterval: 1h
      duration: 14d
    players:
      af5efd2a-f19b-47ef-a4bb-9c585108b3d4: 1500000000000

  members:
    config:
      checkInterval: 24h
      duration: 30d
      gracePeriod: 1d
    players:
      af5efd2a-f19b-47ef-a4bb-9c585108b3d4: 1500000000000

  expired:
    config:
      checkInterval: 1h
    players:
      af5efd2a-f19b-47ef-a4bb-9c585108b3d4: 1500000000000