Hi, I am trying to create a method where a player can input block names and also be able to use data-values due to blocks that are in need of them such as wool. Basically what this will do is just grab the blocks they have imputed and put them into the config, the configuration part is not an issue I know how to do that but how could I go about making it so a player could do the following: Code: /MyCommand add MyFloor wood dirt grass wool:5
well, for each argument, you could check if the String contained a ":" (colon) and if so split the string on the ":". Then create an itemstack with the first part of the string as the Material and the second as the data value.
So something like this should work? Code: private void addBlocks(Player player, String floor, String block) { if (config.contains("Floors." + floor)) { if (block.contains(":")) { String[] blockAndData = block.split(":"); String blockName = blockAndData[0]; int data = Integer.parseInt(blockAndData[1]); ItemStack blocks = new ItemStack(Material.matchMaterial(blockName), 1, (short) data); } else { ItemStack blocks = new ItemStack(Material.matchMaterial(floor)); } }
Yeah seems right. Test it out by giving the player the itemstack at the end and see if its the correct item type.
The code only works for the following - Code: /MyCommand add MyFloor wood dirt:1 wool:5 But If I was to do this it doesn't work and throws of an NPE - Code: /MyCommand add MyFloor wood dirt:1 wool:5 grass
@AyWuzzUp In the else statement, your matching the material for the floor, and not the block. Replace 'floor' with block.
Oh wow I didn't even notice! Thank you I honestly would have sat here for another 10 minutes trying to figure this out xP