Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("deprecation")
- @EventHandler
- public void CGinvClick(InventoryClickEvent event) {
- final int slot = 0; //The first slot of the chest
- Player p = (Player) event.getWhoClicked();
- p.sendMessage(event.getInventory().getName());
- if (event.getRawSlot() < event.getInventory().getSize() && //This makes sure the player clicked in the chest, and not the player's inventory.
- event.getRawSlot() == slot) // This makes sure it only gives the player the item in his hand if he clicks the item. (Could be replaced with event.getItem() == book)
- {
- event.setCancelled(true); //If you don't cancel it, it will do this odd thing you showed in your video, where it creates ghost books.
- ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
- book.setAmount(1);
- event.getInventory().clear(); //Clearing it, in case the player placed the book in the chest.
- event.getInventory().setItem(slot,book); //Because we cancelled the event, we have to manually give the player the item on his cursor.
- p.updateInventory();
- p.setItemOnCursor(book); //Can't explain, remove it to see the difference :P
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement