Spigot question (.matchMaterial)

Discussion in 'Programming' started by Fyriboo, Jun 5, 2016.

  1. I am trying to make a mine plugin, where the mine resets within the given coordinates and with given blocks that are in the config.
    Now I have the Problem that Blocks with :Number don't work. For example when I save the Block IDs to the config I can save Blocks with only 1 parameter, so 1,2,3,4,... (stone,grass,...).
    The Blocks are then handled like this:

    Material item = Material.matchMaterial(getConfig().getConfigurationSection("mines").getConfigurationSection(name).getString("blocks").split(",")[rnd]

    and then the Block in the world is placed like this:


    Is there a "function" to also add the Item :... so for example .matchMaterial(1 <--for Stone, 1 <--for Granite)?
  2. No, you would have to use the string IDs. Trust me, the size of the file may be larger, but it's inconsequential considering the amount of space SSDs and HDDs have. Also, don't use the config to store things like this. Use a separate YML or JSON file, or even a SQLite or mySQL database.
  3. String IDs are the same, so for wood they all are minecraft:log. But you seem to be quite good in coding bukkit. How did you learn it so I could become better or if you have some free time I would love to ask you some questions (Skype: xxxzentrerxxx)
  4. Would it be possible to do this with
    Bukkit.getWorld(world).getBlockAt(loc).setMetadata(WHAT ARE THE NEEDED VALUES HERE?);
  5. I got it working with Meta Data now:
    Code (Text):
    if (item.contains(":")) {
                                            Bukkit.getWorld(world).getBlockAt(loc).setType(Material.getMaterial((int) Double.parseDouble(item.split(":")[0])));
                                            Bukkit.getWorld(world).getBlockAt(loc).setData((byte) Byte.parseByte(item.split(":")[1]), true);
                                        } else {
                                            Bukkit.getWorld(world).getBlockAt(loc).setType(Material.getMaterial((int) Double.parseDouble(item)));

    I used .setData to set the Meta Data and split the block with .split(":")