Creative Inventory help

Discussion in 'Plugin Development' started by LordManegane, Apr 21, 2014.

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

    LordManegane

    How i can detect when a player take an item from a Creative Inventory Tab?
    I try with something like

    Code:
    if(inventory.getType() == InventoryType.CREATIVE){
    //do something
    }
    But doesnt detect the creative tabs
     
  2. Offline

    beeselmane

    idk if you can do this directly, but you could try to do something like this:

    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryPickupItem event)
    3. {
    4. if (event.getInventory().getType() == InventoryType.CREATIVE)
    5. {
    6. Item clicked = event.getItem();
    7.  
    8. // see what item equals here?
    9. }
    10. }


    and then you could get the item, and try to see which tab it would go in from there?
     
  3. Offline

    CraftedShack

    You could check if player is in creative mode.

    Code:java
    1. if (player.getGameMode() == GameMode.CREATIVE) {
    2. //Creative inventory
    3. }
     
  4. Offline

    LordManegane

    beeselmane I do that, but doesnt work also, with that event, i cant identify a player.
    CraftedShack I also tried that, doesnt work too.
     
  5. Offline

    beeselmane

    Sure you can:
    Code:java
    1. Player player = (Player)event.getInventory().getViewingPlayers().get(0);

    They're they only person viewing their own inventory :p
     
  6. Offline

    LordManegane

    beeselmane
    BTW, i do this
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryPickupItemEvent event){
    3. System.out.println("TEST");
    4. }

    And doesnt do anything
     
  7. Offline

    xTigerRebornx

    LordManegane Because you aren't using the correct event. InventoryPickupItemEvent is fired when a hopper/hopper-minecart picks up an item
     
  8. Offline

    LordManegane

  9. Offline

    beeselmane

    xTigerRebornx is right.. haha

    correct event: InventoryClickEvent
    example:
    Code:java
    1. public void onInventoryClick(InventoryClickEvent event)
    2. {
    3. if (event.getInventory().getType() == InventoryType.CREATIVE)
    4. {
    5. if (event.getAction() == InventoryAction.PICKUP_ALL || event.getAction() == InventoryAction.PICKUP_ALL || event.getAction() == InventoryAction.PICKUP_ALL || event.getAction() == InventoryAction.PICKUP_ALL || event.getAction() == InventoryAction.PICKUP_ALL )
    6. {
    7. Item clicked = event.getCurrentItem().getType();
    8.  
    9. // Check for a specific item
    10. }
    11. }
    12. }
     
  10. Offline

    Loogeh

  11. Offline

    LordManegane

    Loogeh It works, but doesnt seem to do anything when the item its on the creative tab.
     
Thread Status:
Not open for further replies.

Share This Page