Drop Item naturally via config.yml

Discussion in 'Plugin Development' started by xTeCnOxShAdOwZz, Apr 11, 2014.

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

    xTeCnOxShAdOwZz

    Hello, I require a little help concerning how to drop a block entity when a block is broken. At the moment, when a block is broken, it will drop bedrock, but I want this to be configurable via the config.yml. For example, if I change the dropItem bit to sand, when the block is mined, it drops sand. Currently it is limited to just bedrock. Here is the bit of code that I am using:


    Code:java
    1. p.getWorld().dropItemNaturally(
    2. block.getLocation(),
    3. bedrock);
     
  2. Offline

    Onlineids

    Just edit the drops
     
  3. Offline

    xTeCnOxShAdOwZz

    But I want it to be configurable from the config.yml
     
  4. Offline

    Onlineids

    getConfig().getInt(PATH)
    then when editing the drops set it to an item id and the item id of the line above
     
  5. Offline

    xTeCnOxShAdOwZz

    Ok, thanks, I'll try that
     
  6. Offline

    1Rogue Retired Staff

    Code:java
    1. String s = /* your material string from the config */;
    2. Material m = Material.matchMaterial(s);
    3. ItemStack stack = new ItemStack(m, /* amount */);
    4. p.getWorld().dropItemNaturally(block.getLocation(), stack);


    You shouldn't use item id's, you should use the material enum provided.
     
    Garris0n likes this.
  7. Offline

    xTeCnOxShAdOwZz

    1Rogue Ok, I tried your suggestion, and no errors occured, and it seemed to all make sense, this is what I did:

    Code:java
    1. if (Main.this.DropBedrock) {
    2. String s = getConfig().getString("Item-Drop");
    3. Material m = Material.matchMaterial(s);
    4. ItemStack stack = new ItemStack(m, 1);
    5. p.getWorld().dropItemNaturally(
    6. block.getLocation(),
    7. stack);


    I made a String in the config.yml called "Item-Drop" and set the default to sand, then went to test it, and nothing happened :(
     
  8. Offline

    1Rogue Retired Staff


    Do:

    Code:java
    1. Material.match.Material(s.toUpperCase());


    And print some debug statements, see what the values are of the variables you are working with.
     
  9. Offline

    xTeCnOxShAdOwZz

    Ah, I see the problem, it wasn't the making it uppercase, it was the fact the string in the config file was slightly different to the one used in the code, so it couldn't locate it. In the code it was called Item-Drop, whereas in the config file it was called ItemDropped. Thanks for your help!!
     
Thread Status:
Not open for further replies.

Share This Page