Solved Creating customizable Data/Amounts for items

Discussion in 'Spigot Plugin Development' started by Cervinakuy, Jun 3, 2016.

  1. Hey guys!

    This is kind of hard to explain, so I'll show you what I'm looking to do in my config.yml

    Code (Text):
      - EXAMPLE_ITEM:2 1
      - EXAMPLE_ITEM2:5 3

    # And so on...
    I want the :[Data Number] to be the data.. and the number after the space to be the amount it gives..

    All I have is the items... as shown below:

    Code (Text):
    for (String itemlist : plugin.getConfig().getStringList("Items")) {
                            ItemStack items = new ItemStack(Material.valueOf(itemlist));
    Does anyone know the most practical way of doing this?

    - Cervinakuy
  2. Just use String#Split

    As an example, your list would look like:
    Code (Text):
      - DIAMOND_BLOCK:1:0
      - EMERALD_BLOCK:1:0
      - WOOL:1:14
    So take your Strings and split them then parse the integers
    Code (Text):
    for (String s : yourConfigList){
        String[] split = s.split(":");
        Material mat = Material.getMaterial(split[0]);
        int amount = Integer.parseInt(split[1]);
        int data = Integer.parseInt(split[2]);
    It's much easier to do what you're trying to achieve using JSON, you should really learn it.
  3. Thank you for your reply! :)

    I'll try this and see if it works.

    I'm planning to learn that language after I've mastered Java (So in a very long time :p)

    - Cervinakuy
    • Useful Useful x 1
  4. That is very true JSON is very useful for keeping track of data and stuff like this. It is also really quick because it's not really a coding language it's a format just like YAML.

    Also please set the thread to solved