can't get getDrops working..

Discussion in 'Plugin Development' started by q8minecraft, Nov 20, 2014.

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

    q8minecraft

    I'm working on a LuckyBlock plugin, But this code can't seem to be working as I expected.. Can you guys help me with it, Please?
    Code:java
    1. package me.q8minecraft.lucky;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockBreakEvent;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class LuckyBlock extends JavaPlugin implements Listener{
    13.  
    14. public void onEnable() {
    15. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    16. }
    17.  
    18. @EventHandler
    19. public void onBlockBreak(BlockBreakEvent e) {
    20. Block b = e.getBlock();
    21. if(b instanceof Block);
    22. if (b.getType() == Material.SPONGE) {
    23. ((Block) b.getLocation()).getDrops().add(new ItemStack(Material.DIAMOND_SWORD, 1));
    24. ((Block) b.getLocation()).getDrops().add(new ItemStack(Material.BOW, 1));
    25. ((Block) b.getLocation()).getDrops().add(new ItemStack(Material.ARROW, 32));
    26. }
    27. }
    28.  
    29.  
    30. }
    31.  
     
  2. Offline

    ColonelHedgehog

    Try using the World#dropItem() method instead.
     
  3. q8minecraft
    Code:
    ((Block) b.getLocation())
    Afaik, Block is not a Location.
     
  4. Offline

    q8minecraft

    ColonelHedgehog Worked! Thanks! One more thing, How do I add enchantments and renaming the dropped item ?
     
  5. Offline

    ColonelHedgehog

    You need to first get the ItemMeta:

    ItemMeta meta = item.getItemMeta();

    Then set the display name and add enchantments:

    meta.setDisplayName("My Display Name")
    meta.addEnchantment(enchant <Enchantment>, <int> power, safe <boolean>)

    Then apply the metadata to the itemstack:

    item.setItemMeta(meta);

    Hope this helped. :)
     
  6. Offline

    q8minecraft

    ColonelHedgehog when I added ItemMeta meta = item.getItemMeta(); I get an error on item.getItemMeta(); any help ? and what do you mean by int and boolean in the addEnchantment method ?
     
  7. Offline

    ColonelHedgehog

    What is your error?

    How well do you know Java, out of curiosity?
     
  8. Offline

    q8minecraft

    Already fixed it, And I don't know much about Java.. Another question if you don't mind, when I try to add a lore, I get an error.. [​IMG]
     
  9. Offline

    ColonelHedgehog

    Two things. First of all, you're attempting to set a string to the lore when in fact you need a list, and anyway, I said to use the display name method.

    Secondly, you really need to know the basics of Java to be able to make plugins. :-/
     
  10. Offline

    BetaNyan

    Arrays.asList()
     
Thread Status:
Not open for further replies.

Share This Page