Paste #5095: Untitled Paste

Date: 2014/06/05 10:40:41 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>
    - define types 'ambient|animal|monster|water_animal'


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

  list:
    - define worlds <server.list_worlds>
    - if %world% != null {
      - if !<def[worlds].contains[<def[world].as_world>]> {
        - narrate "<def[world]> 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 "<def[type]> is not a valid type"
        - queue stop
        }
      - define types <def[type]>
      }
    - foreach <def[worlds].as_list> {
      - define world %value%
      - narrate "<def[world].name> Spawn Limits"
      - foreach <def[types].as_list> {
        - narrate "<&sp><&sp><&sp><def[value].to_titlecase><&co> <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[-l]>]: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
      }

    - if <context.server> {
      - if %world% == null {
        - announce to_console "ERROR<&co> Must specify a world"
        - announce to_console "/mslimit -w <&lt>world<&gt>"
        }
      - if %type% == null {
        - announce to_console "ERROR<&co> Must specify a type"
        - announce to_console "/mslimit -t <&lt>type<&gt>"
        }
      - if %limit% == null {
        - announce to_console "ERROR<&co> Must specify a limit"
        - announce to_console "/mslimit -l <&lt>limit<&gt>"
        }
      }