Inventory Swapping

Discussion in 'Plugin Development' started by Onlineids, Mar 23, 2014.

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

    Onlineids

    Im creating an advanced banking plugin and want to get when a player puts an gold nugget from his inven to his echest how would i do this get the amount of that item and set it to null?

    Anyone know?

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

    mikamika83

    If you want to simply delete that item - set the material to Material.AIR
     
  3. Offline

    Onlineids

    That solves that part but how to get when they put the item in there echest?
     
  4. Offline

    Minnymin3

    InventoryClickEvent. Check the click type to see if they placed an item, check the inventory and then check the item.
     
  5. Offline

    Onlineids

    But they could then place an item anywhere and it would work the same
     
  6. Offline

    Minnymin3

    Check the inventory like I said. See if its this magical chest that eats your gold.
     
  7. Offline

    Onlineids

    This is my code but it doesnt work for several reasons:
    1: It only allows one gold to be put in at once
    2. If you go from enderchest to inventory it still will register which i dont want
    3. Doesnt get rid of the gold
    Code:java
    1. @EventHandler
    2. public void onBank(InventoryClickEvent event)
    3. {
    4. if (event.getWhoClicked() instanceof Player)
    5. {
    6. Player player = (Player) event.getWhoClicked();
    7. InventoryType topType = event.getView().getTopInventory().getType();
    8. InventoryType botType = event.getView().getBottomInventory().getType();
    9. ItemStack nugget = event.getCurrentItem(); //the item that is part of the event
    10. player.sendMessage("test");
    11. if (topType.equals(InventoryType.ENDER_CHEST))
    12. {
    13. player.sendMessage("Test 1");
    14. if (invAction(event.getAction()) && event.getCurrentItem().equals(item) && event.getSlot() == 0) //checks to see if it is the special item with the lore, if it is, it cancels the event
    15. {
    16. player.sendMessage("Test 2 item");
    17. event.setCancelled(true);
    18. }
    19. if (invActionPlace(event.getAction()) && !event.getInventory().getType().equals(botType)) //checks to see if the item is being placed or swapped
    20. {
    21. player.sendMessage("test 3");
    22. if (item.getType().equals(Material.GOLD_NUGGET)) //checks to see if the item is a gold nugget
    23. {
    24. player.sendMessage("Test 3 final");
    25. player.getInventory().remove(nugget); //removes the item
    26. int amt = item.getAmount(); //Gets the amount of the item
    27. String a = amt + "";
    28. double bala = econ.getBalance(player.getName());
    29. double bal = bala + amt;
    30. String balance = String.valueOf(bal);
    31. String mess = ChatColor.GOLD + a + ChatColor.GOLD + " Gold" + ChatColor.GREEN + " Added!" + ChatColor.GREEN + " New Balance: " + ChatColor.GOLD + balance + ChatColor.GOLD + " Gold";
    32. player.sendMessage(mess);
    33. econ.depositPlayer(player.getName(), amt);
    34.  
    35. }
    36. }
    37. }
    38. }
    39. }
    40. }
    41.  
     
  8. Offline

    Minnymin3

    Give the inventory some special metadata, cancel the event and remove the curser item of the player and im not sure why its only letting you put in one at a time. Show me the invAction and invActionPlace methods
     
Thread Status:
Not open for further replies.

Share This Page