Paste #21701: Untitled Paste

Date: 2015/10/27 05:17:04 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


Load Prices:
  type: world
  debug: false
  events:
    on server start:
    - if <server.has_file[/prices.yml]> {
      - yaml load:/prices.yml id:prices
      - announce to_console "<&a>Loaded existing price list!"
    }
    else {
      - yaml create id:prices
      - foreach <server.list_materials.exclude[air|standing_banner|wall_banner]> {
        - if <def[Value].as_item||null> == null {
          - foreach next
        }
        - yaml set "<def[Value]>.current:1" id:prices
        - yaml set "<def[Value]>.min:0" id:prices
        - yaml set "<def[Value]>.max:2" id:prices
      }
      - yaml savefile:/prices.yml id:prices
      - announce to_console "<&a>Generated new Price list!"
    }

SetPrice_Command:
  type: command
  debug: false
  name: setprice
  usage: /setprice (item)
  description: Set the price of the item specified, or item in hand.
  permission: prices.sets
  tab complete:
  - if <yaml.list.contains[prices].not> queue clear
  - choose <context.args.size>:
    - case 0:
      - determine <yaml[prices].list_keys[]>
    - case 1:
      - determine <yaml[prices].list_keys[].filter[starts_with[<context.args.last]>]>
  script:
  - if <yaml.list.contains[prices].not> {
    - narrate "<&c>Prices are not loaded!"
    - queue clear
  }
  - if <context.args.size> == 1 {
    - define Item <player.item_in_hand.material.name>
    - if <def[Item]> == air {
      - narrate "<&c>Cannot set a price on air!"
      - queue clear
    }
    - define Cost <context.args.get[1].as_decimal||null>
    - if <def[Cost]> == null {
      - narrate "<&c>Cost must be a number!"
      - queue clear
    }
    - yaml set <def[Item]>:<def[Cost]> id:prices
    - yaml savefile:/prices.yml id:prices
  }
  else if <context.args.size> == 2 {
    - define Item <context.args.get[1].as_item||null>
    - if <def[Item]> == null {
      - narrate "<&c>That's not a real item!"
      - queue clear
    }
    - define Item <def[Item].material.name>
    - if <def[Item]> == air {
      - narrate "<&c>Cannot set a price on air!"
      - queue clear
    }
    - define Cost <context.args.get[2].as_decimal||null>
    - if <def[Cost]> == null {
      - narrate "<&c>Cost must be a number!"
      - queue clear
    }
    - yaml set <def[Item].material.name>:<def[Cost]> id:prices
    - yaml savefile:/prices.yml id:prices
  }
  else {
    - narrate "<&6>Proper Syntax is:"
    - narrate "<&6>/setprice cost (e.g. /setprice 5) to set price of item in hand."
    - narrate "<&6>/setprice item cost (e.g. /setprice stone 5) to set the price of the item specified."
  }

GetPrice Command:
  type: command
  name: getprice
  usage: /getprice
  description: Get the price of the item specified, or item in hand.
  permission: prices.get
  tab complete:
  - if <yaml.list.contains[prices].not> queue clear
  - choose <context.args.size>:
    - case 0:
      - determine <yaml[prices].list_keys[]>
    - case 1:
      - determine <yaml[prices].list_keys[].filter[starts_with[<context.args.last]>]>
  script:
  - if <yaml.list.contains[prices].not> {
    - narrate "<&c>Prices are not loaded!"
    - queue clear
  }
  - if <context.args.size> == 0 {
    - define Item <player.item_in_hand.material.name>
    - if <def[Item]> == air {
      - narrate "<&c>Air does not have a price!"
      - queue clear
    }
    - narrate "<&6>The price of <&f><def[Item].to_titlecase> <&6>is <&f><yaml[prices].read[<def[Item]>.current]><&6>."
  }
  else if <context.args.size> == 1 {
    - define Item <context.args.get[1].as_item||null>
    - if <def[Item]> == null {
      - narrate "<&c>That's not a real item!"
      - queue clear
    }
    - define Item <def[Item].material.name>
    - if <def[Item]> == air {
      - narrate "<&c>Air does not have a price!"
      - queue clear
    }
    - narrate "<&6>The price of <&f><def[Item].to_titlecase> <&6>is <&f><yaml[prices].read[<def[Item]>.current]><&6>."
  }