Paste #5124: Untitled Paste

Date: 2014/06/06 06:04:28 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


################################################################################
#                                                                              #
#                  M o b S p a w n   L i m i t   M a n a g e r                 #
#                                                                              #
#                                                                              #
# A system for setting how many mobs are able to spawn per chunk in each world #
#                                                                              #
# Features a dynamic command handler. Command arguments can be supplied in any #
# order. Syntax checking and error handeling included.                         #
#                                                                              #
################################################################################

'MobSpawnManagerTasks':
  type: task
  debug: false

  script:
    - define worlds <server.list_worlds>
    - if %world% != null {
      - if !<def[worlds].contains[<def[world].as_world>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[world]> <&b>does not exist"
        - queue stop
        }
      - define worlds <def[world].as_world>
      }
    - define types 'ambient|animal|monster|water_animal'
    - if %type% != null {
      - if !<def[types].as_list.contains[<def[type]>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[type]> <&b>is not a valid type"
        - queue stop
        }
      - define types <def[type]>
      }


  set:
    - define worlds <server.list_worlds>
    - if %world% != null {
      - if !<def[worlds].contains[<def[world].as_world>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[world]> <&b>does not exist"
        - queue stop
        }
      }
      else {
      - narrate "<&4><&l>ERROR<&co><&r> <&b>Must specify a world"
      - narrate format:CmdSynFormat "/mslimit -w \<&lt\>world\<&gt\>"
      - queue stop
      }

    - define types 'ambient|animal|monster|water_animal'
    - if %type% != null {
      - if !<def[types].as_list.contains[<def[type]>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[type]> <&b>is not a valid type"
        - queue stop
        }
      }
      else {
      - narrate "<&4><&l>ERROR<&co><&r> <&b>Must specify a type"
      - narrate format:CmdSynFormat "/mslimit -t \<&lt\>type\<&gt\>"
      - queue stop
      }

    - if %limit% != null {
      - if !<def[limit].is[matches].to[integer]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[limit]> <&b>is not a valid number"
        - queue stop
        }
      - define limit <def[limit].abs.as_int>
      }
      else {
      - narrate "<&4><&l>ERROR<&co><&r> <&b>Must specify a limit"
      - narrate format:CmdSynFormat "/mslimit -l \<&lt\>limit\<&gt\>"
      - queue stop
      }


    - adjust <def[world].as_world> %type%_spawn_limit:<def[limit]>

  list:
    - inject s@MobSpawnManagerTasks
    - foreach <def[worlds].as_list> {
      - define world %value%
      - narrate "<&6><&l><def[world].name> Spawn Limits"
      - foreach <def[types].as_list> {
        - narrate "<&sp><&sp><&sp><&b><def[value].to_titlecase><&co> <&a><def[world].<def[value]>_spawn_limit>"
        }
      - narrate ""
      }


'MobSpawnManagerCommand':
# The command handler. Accepts the command and passes the info to the task scripts
  type: world
  debug: true
  events:

    on mslimit command:
    - if !<player.has_permission[denizen.cmdtest]> queue stop
    - determine passively fulfilled
    - define list '<tern[<context.args.contains[-ls]>]:true||<tern[<context.args.contains[--list]>]:true||false>>'
    - define set '<tern[<context.args.contains[-s]>]:true||<tern[<context.args.contains[--set]>]:true||false>>'
    - define world '<tern[<c.args.find[-w].is[MORE].than[0]>]:<c.args.get[<c.args.find[-w].add[1].as_int>]> || null>'
    - define type '<tern[<c.args.find[-t].is[MORE].than[0]>]:<c.args.get[<c.args.find[-t].add[1].as_int>]> || null>'
    - define limit '<tern[<c.args.find[-l].is[MORE].than[0]>]:<c.args.get[<c.args.find[-l].add[1].as_int>]> || null>'

    - if %list% == true {
      - inject s@MobSpawnManagerTasks p:list
      - queue stop
      }

    - if %set% == true {
      - inject s@MobSpawnManagerTasks p:set
      - queue stop
      }