Advertisement
maxthelinkfan

Untitled

Sep 22nd, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. package me.maxtheorange.Signs;
  2.  
  3.  
  4. import org.bukkit.event.block.Action;
  5. import org.bukkit.event.inventory.InventoryCloseEvent;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Material;
  8. import org.bukkit.Server;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.player.PlayerInteractEvent;
  13. import org.bukkit.inventory.ItemStack;
  14. import org.bukkit.inventory.PlayerInventory;
  15. import org.bukkit.inventory.meta.BookMeta;
  16. import org.bukkit.scheduler.BukkitRunnable;
  17. import org.bukkit.block.Sign;
  18. import org.bukkit.command.CommandSender;
  19.  
  20. public class Books implements Listener{
  21.  
  22.        
  23.         public Books(Main instance){            
  24.                 Main plugin = instance; //Unused Here
  25.         }
  26.         @EventHandler
  27.         public void onPlayerInteract(PlayerInteractEvent e){
  28.         final Player p = e.getPlayer();
  29.         if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
  30.             if(e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST){
  31.             Sign sign = (Sign) e.getClickedBlock().getState();
  32.             if(sign.getLine(0).equals("[Book]")){
  33.             PlayerInventory inventory = p.getInventory();
  34.             ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
  35.             BookMeta bm = (BookMeta) book.getItemMeta();
  36.             bm.addPage("Hello THIS IS MY BOOK! GO AWAY I LIKE BOOKS!", "THIS IS STILL MY BOOK");
  37.             bm.setAuthor("SonicPvP");
  38.             bm.setTitle("The Awesome Book");
  39.             book.setItemMeta(bm);
  40.             inventory.addItem(book);
  41.            
  42.           //player receives book
  43.             new BukkitRunnable() {
  44.             @SuppressWarnings("deprecated") //Unused here
  45.             public void run() {
  46.             for(ItemStack is : p.getInventory().getContents()) {
  47.             if(is.getType() == Material.BOOK) {
  48.             //check meta if you want
  49.             is.setType(Material.AIR);
  50.             p.updateInventory(); // Unused Here
  51.                       }
  52.                   }
  53.               }
  54.             }.runTaskLater(plugin, 600L); // Plugin cannot be resolved to a variable
  55.             }
  56.             }
  57.         }
  58.         }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement