Advertisement
Guest User

Untitled

a guest
Sep 8th, 2013
12,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package me.JPG.HostileAttributes.Inventory;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Material;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.event.EventHandler;
  7. import org.bukkit.event.inventory.InventoryClickEvent;
  8. import org.bukkit.inventory.Inventory;
  9. import org.bukkit.inventory.ItemStack;
  10.  
  11. public class myCustomInventory {
  12. public static Inventory myInventory = Bukkit.createInventory(null, 9, "My custom Inventory!");
  13. // The first parameter, is the inventory owner. I make it null to let everyone use it.
  14. //The second parameter, is the slots in a inventory. Must be a multiple of 9. Can be up to 54.
  15. //The third parameter, is the inventory name. This will accept chat colors
  16. static {
  17. myInventory.setItem(0, new ItemStack(Material.DIRT, 1);
  18. myInventory.setItem(8, new ItemStack(Material.GOLD_BLOCK, 1);
  19. }
  20. @EventHandler
  21. public void onInventoryClick(InventoryClickEvent event) {
  22. Player player = (Player) event.getWhoClicked(); // The player that clicked the item
  23. ItemStack clicked = event.getCurrentItem(); // The item that was clicked
  24. Inventory inventory = event.getInventory(); // The inventory that was clicked in
  25. if (inventory.getName().equals(myInventory.getName())) { // The inventory is our custom Inventory
  26. if (clicked.getType() == Material.DIRT) { // The item that the player clicked it dirt
  27. event.setCancelled(true); // Make it so the dirt is back in its original spot
  28. player.closeInventory(); // Closes there inventory
  29. player.getInventory().addItem(new ItemStack(Material.DIRT, 1)); // Adds dirt
  30. }
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement