FAIL.

Discussion in 'Plugin Development' started by TheGamesHawk2001, Nov 15, 2014.

Thread Status:
Not open for further replies.
  1. Guys, I just dived straight in with this auto inv this, it didnt work...

    here's my code :)

    Code:java
    1. @EventHandler()
    2. public void onBlockBreak (BlockBreakEvent e) {
    3. Player p = e.getPlayer();
    4. ItemStack drops = null;
    5. e.getBlock().getDrops(drops);
    6. e.setCancelled(true);
    7. p.getInventory().addItem(drops);
    8.  
    9. }
    10. }
     
  2. Offline

    mine-care

    ItemStack drops =null;
    e.getBlock().getDrops(drops);
    drops = null so its like saying when its broken by nothing then get the drops and do nothing with them.
    The concept is to add the drops of the broken block to players inventory so cancel the event and then add them :)
     
  3. Offline

    Gamecube762

    "didnt work..." tells us absolutely nothing. Are you getting errors? Are you getting red squiggles under your text? Is your plugin not compiling? Is your plugin not loading?

    More information will help us help you.
     
  4. Gamecube762 I wan't to make a blocks 2 inv plugin. The blocks aren't going to my inv.
     
  5. Offline

    Dealyise

    You are actually trying the following:

    Code:java
    1. @EventHandler()
    2. public void onBlockBreak (BlockBreakEvent e) {
    3. Player p = e.getPlayer();
    4. ItemStack drops = null;
    5. e.getBlock().getDrops(drops);
    6. e.setCancelled(true);
    7. p.getInventory().addItem(drops);
    8.  
    9. }


    1st. step:
    Code:java
    1. ItemStack drops = null;

    You are declaring drops as nothing, as null.

    2nd. step:
    Code:java
    1. e.getBlock().getDrops(drops);

    Remember what I've said above? You are technically getting nothing.

    3rd. step:
    Code:java
    1. e.setCancelled(true);

    You are cancelling the event. Why don't you just change the drops?

    4th. step:
    Code:java
    1. p.getInventory().addItem(drops);

    What are you adding here? Exactly, nothing!

    So, you actually tried to remove nothing, cancelling the event (which worked) and after that, adding nothing again.

    You could do the following:
    Create a new ItemStack with your choosen items, like this:
    Code:java
    1. Itemstack myItem = new Itemstack(<BLOCK/ITEM ID HERE>, (OPTIONAL! ADDING BYTES HERE, E.G: COLORED WOOL).

    After declaring your Itemstack, go ahead and change the drops with .setDrops(yourItemstackYouHaveDeclaredBefore).
    And that's it, it should give you items when breaking blocks. But: You have to declare the blocks which will drop this, otherwise it could drop the items instantly or even worse, throw errors.
     
  6. mine-care I don't understand what to replace null with.. Is this correct?

    @EventHandler()
    public void onBlockBreak (BlockBreakEvent e) {
    Player p = e.getPlayer();
    ItemStack drops = null;
    e.getBlock().getDrops(drops);
    p.getInventory().addItem(drops);
    e.setCancelled(true);

    }
    }
     
  7. Offline

    Dealyise


    TheGamesHawk2001 Just look at my answer above your post :)
     
  8. Dealyise Ah, I did what you said and I have a problem, If I add e.setCancelled(true); to it. it doesnt break the block but gives me the item stack and if I dont do setCancelled(true); it breaks the block at drops the item as normal and sets the item to my inv also.
     
  9. Offline

    JordyPwner

    Cancel the drop
     
  10. Offline

    Dealyise

    TheGamesHawk2001 Then set the drops from the block (.getDrops(null)) as null and give your itemstack through .addItem .

    This should work for you.
     
  11. Dealyise I was thinking about introducing a ItemDropEvent and cancelling that? I'll try that and yours too :D

    EDIT 1: My soloution doesnt work, I'll try yours now
     
  12. Offline

    eyamaz

    I've cleaned up this thread, I expect it kept that way or you will all be sent to your rooms without dinner.
     
  13. Offline

    Developerjohn

    timtower
     
  14. Online

    timtower Administrator Administrator Moderator

    And you tag me because?
     
    xTrollxDudex likes this.
  15. Offline

    JordyPwner

    eyamaz said:
    I've cleaned up this thread, I expect it kept that way or you will all be sent to your rooms without dinner.​
    @timtower because of that
     
  16. Offline

    Jadedcat


    I do not understand what your concern is. Please explain?
     
  17. Offline

    JordyPwner

    Timtower asked why developerjohn tagged him. And i didnt see a answer so i answered it for him

    {OFFTOPIC} Why does my messages need approval?
     
  18. Online

    timtower Administrator Administrator Moderator

    Then it would still make no sense at all that I got tagged.
     
  19. Offline

    JordyPwner

    He tagged you cause eymaz said: I've cleaned up this thread, I expect it kept that way or you will all be sent to your rooms without dinner.

     
  20. Offline

    Rocoty

    Right, that was interesting. Getting back on topic, though...

    TheGamesHawk2001 Maybe you should try reading documentation about the methods you are calling. It should save you a lot of trouble.
     
    eyamaz likes this.
  21. Rocoty Thanks. I will take a look there :D
     
  22. Offline

    Developerjohn

    timtower
    You did post on eyamaz profile page stating you thought it was funny when he posts a funny message when locking a thread. He didn't lock it, but I still thought it was funny.
     
  23. Online

    timtower Administrator Administrator Moderator

    Developerjohn No need to do that again, I will just see it when I see it.
     
    Developerjohn likes this.
Thread Status:
Not open for further replies.

Share This Page