InventoryMoveItemEvent Help!

Discussion in 'Plugin Development' started by Kassestral, Jul 5, 2014.

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

    Kassestral

    When the hopper moves the cobblestone to the chest is it meant to get rid of the cobblestone and deposit gravel in its place, but instead it deposits both cobblestone and gravel, any help guys?
    Code:java
    1. @EventHandler
    2. public void onHopperMove(InventoryMoveItemEvent e){
    3. if(e.getInitiator().getType() == InventoryType.HOPPER && (e.getDestination().getType() == InventoryType.CHEST)){
    4. if(e.getItem().getType().equals(Material.COBBLESTONE)){
    5.  
    6. //Cancels the item being moved
    7. e.setItem(new ItemStack(Material.AIR));
    8. //Cancels the item being moved
    9.  
    10. e.getDestination().addItem(new ItemStack(Material.GRAVEL));
    11. e.getInitiator().remove(new ItemStack(Material.COBBLESTONE, 1));
    12. }
    13. }
    14. }


    timtower Garris0n

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    Garris0n

    Have you considered cancelling the event...?
     
    dsouzamatt likes this.
  3. Offline

    Kassestral

    Garris0n
    Yeah and it still doesn't work, it just keeps adding gravel to the chest without taking cobblestone
     
  4. Offline

    Garris0n

    Well, is there a stack of cobblestone with an amount of one and no extra metadata in the hopper?
     
  5. Offline

    Kassestral

    Garris0n
    Yeah
     
  6. Offline

    Garris0n

    Well, that's weird, although you should consider a remove method that doesn't require there to be an amount of exactly 1.
     
  7. Offline

    Kassestral

    Garris0n
    I did that, and it just removes ALL the cobblestone from the hopper, and deposits 1 cobblestone, 1 gravel into the chest
     
  8. Offline

    Garris0n

    Make your own method that removes one from a stack.
     
  9. Offline

    Kassestral

    Garris0n
    I would have no idea where to being :/
     
  10. Offline

    Garris0n

    1. Find an ItemStack of the type you want.
    2. Lower the amount of the itemstack.*
    3. ???
    4. Profit.

    *Note that setting the amount to zero doesn't delete an item. If the item's amount is 1, you have to actually set it to null in the inventory.
     
  11. Offline

    Kassestral

    Garris0n Tried something like what you mentioned above but it doesn't seem to be working :/ think you could test some stuff for me? been stuck wit this for over 24 hours xD
     
  12. Offline

    Necrodoom

    Kassestral paste current code and explain why it doesn't work.
     
    Garris0n likes this.
  13. Offline

    Kassestral

    Necrodoom Garris0n I didn't save what i had before since my laptop died while I was sleeping but this is the last thing that was saved.
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onHopperMove(InventoryMoveItemEvent e){
    3. if(e.getInitiator().getType() == InventoryType .HOPPER && (e.getDestination().getType() == InventoryType.CHEST)){
    4. if(e.getItem().getType().equals(Material.COBBLESTONE)){
    5. e.getDestination().remove(Material.COBBLESTONE);
    6. }
    7. }
    8. }
     
  14. Offline

    Garris0n

    Well obviously that will remove all of the cobblestone. That's what the method does.
     
  15. Offline

    Kassestral

    Garris0n
    But it doesn't, it deposits it, then removes it next time the event is called, meaning their is always a single cobblestone in the chests inventory, however players can take the cobblestone out of the chest therefor getting ALL of their cobblestone back, before the plugin removes it :/
     
  16. Offline

    Garris0n

    Well that's because you remove the cobblestone before the next one is put into the chest.

    Which I would've pointed out, except...
     
  17. Offline

    Kassestral

    Garris0n
    Could I ask you show me the code needed to fix my problem? and annotate what has been done?
     
  18. Offline

    Garris0n

    something something section for help with code not giving code something
     
  19. Offline

    Kassestral

    Garris0n
    Okay, so then can you help me by telling me how to take the item from the initiator's inventory? it seems that if I cancel the event then it doesn't transfer the material, and also wont allow me to take any materials from the initators inventory slots :/
     
  20. Offline

    Garris0n

  21. Offline

    Kassestral

Thread Status:
Not open for further replies.

Share This Page