Solved Block IDs

Discussion in 'Plugin Development' started by AyWuzzUp, Jan 27, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    AyWuzzUp

    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
    
     
  2. Offline

    Machine Maker

    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.
     
  3. Offline

    AyWuzzUp

    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));
      }
    }
    
     
  4. Offline

    Machine Maker

    Yeah seems right. Test it out by giving the player the itemstack at the end and see if its the correct item type.
     
  5. Offline

    AyWuzzUp

    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
    
     
  6. Offline

    Zombie_Striker

    @AyWuzzUp
    In the else statement, your matching the material for the floor, and not the block. Replace 'floor' with block.
     
  7. Offline

    AyWuzzUp

    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
     
Thread Status:
Not open for further replies.

Share This Page