String to Material

Discussion in 'Programming' started by T-low, May 17, 2016.

  1. Hi I am trying to pull a string out of the config file and conwert it to that "Material.DIAMOND" material below.
    Code (Text):
    if (player.getInventory().contains(Material.DIAMOND, getConfig().getInt("village1")))
    The config.yml has these commands:
    material1: Material.DIAMOND
    village1: 10

    I tryed different methods but I didn't manage to get it right :(

    Thanks in advance for any help :D
     
    • Like Like x 1
  2. Use Material.valueOf(/* material1 */) and change your config to:
    Code (Text):

    material1: DIAMOND
    village1: 10
     
     
    • Like Like x 1
  3. Thank you helped me alot!! :D
     
    • Friendly Friendly x 2
  4. Material.getMaterial(String) would be more appropriate, if you want null istead of an exception if a material is not found.
     
    • Like Like x 1