Disabling taking items from chests.

Discussion in 'Plugin Development' started by Jamesterjim, Dec 30, 2012.

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

    Jamesterjim

    How can I make it so when a Player takes a item from a chest it puts the item back, so they can't take the items in a chest, but still view the chest.
     
  2. Offline

    Tirelessly

    Inventory click event, event.getInventory().getHolder(), and event.setCancelled()
     
  3. Offline

    Jamesterjim

    Can anyone write something for me, I really am stuck.
     
  4. Offline

    gomeow

    I am writing a huge plugin called Deposit Chest. I will gie you some basic source in a bit.
     
  5. Offline

    Jamesterjim

    If you could send me some or post it here that would be so awesome.
    Thankyou ;)
     
  6. Offline

    gomeow

    My actual event is over 100 lines, so I am going to give you a short version. Tell me if you need more help.

    Code:java
    1.  
    2. @EventHandler
    3. public void onInventoryClick(InventoryClickEvent event) {
    4. if(!(event.getWhoClicked() instanceof Player)) return; //Make sure it was a player.
    5. if(event.getSlotType() != SlotType.CONTAINER) return; //Make sure it is the chest's inventory.
    6. if(event.getInventory().getType() != InventoryType.CHEST) return; //Make sure it was a chest.
    7. Player p = (Player) event.getWhoClicked(); //Get the player who clicked on the block.
    8. if(event.getInventory().getItem(event.getSlot()) != null) { //Check if it was a withdrawal.
    9. //Withdrawal
    10. InventoryHolder ih = event.getInventory().getHolder();
    11. if(ih instanceof Chest) {
    12. Chest eventChest = (Chest) ih;
    13. Location chestLoc = eventChest.getLocation();
    14.  
    15. }
    16. else if(ih instanceof DoubleChest) {
    17. DoubleChest eventChest = (DoubleChest) ih;
    18. Location chestLoc = eventChest.getLocation();
    19. }
    20. }
    21. else {
    22. //Deposited...
    23. }
    24. }
     
Thread Status:
Not open for further replies.

Share This Page