Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1.  
  2. import org.bukkit.Material;
  3. import org.bukkit.command.Command;
  4. import org.bukkit.command.CommandSender;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.event.EventHandler;
  7. import org.bukkit.event.Listener;
  8. import org.bukkit.event.block.Action;
  9. import org.bukkit.event.inventory.InventoryClickEvent;
  10. import org.bukkit.event.player.PlayerInteractEvent;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. public class Repair extends JavaPlugin implements Listener{
  14.  
  15. public void onEnable(){
  16. getServer().getPluginManager().registerEvents(this, this);
  17. }
  18. public void onDisable(){
  19.  
  20. }
  21. @Override
  22. public boolean onCommand(CommandSender sender,Command cmd,String label,String args[]){
  23. Player player = (Player)sender;
  24. if(label.equalsIgnoreCase("repair")){
  25. if(sender.hasPermission("repair.use")){
  26. player.openInventory(player.getInventory());
  27. }else{
  28. sender.sendMessage("§cYou do not have permission to perform this command!");
  29. return true;
  30. }
  31. }
  32. return true;
  33. }
  34.  
  35. @EventHandler
  36. public void InventoryClick(InventoryClickEvent e) {
  37. Player p = (Player) e.getWhoClicked();
  38. if (!(e.getInventory().getTitle().contains("Inventory"))) {
  39. return;
  40. }
  41.  
  42. //Cancel them from taking the item and repair the item they click
  43. if (e.getInventory().getTitle().contains("Inventory")) {
  44. e.setCancelled(true);
  45.  
  46. if (e.getCurrentItem() == null) {
  47. return;
  48. }
  49. //Remember their inventory is 35 slots (starting at 0) so you need to do the following 35 times.
  50. if (e.getSlot() == 0){
  51. //Repair here
  52. p.closeInventory();
  53. }
  54.  
  55. }
  56.  
  57. }
  58. @EventHandler
  59. public void onClick(PlayerInteractEvent e){
  60. Player p = e.getPlayer();
  61. //Change the action if you want
  62. if(e.getAction() == Action.RIGHT_CLICK_AIR){
  63. //Make the item I just did a book :P
  64. if(e.getPlayer().getInventory().getItemInHand().equals(Material.BOOK)){
  65. //Opening the inventory
  66. p.performCommand("repair");
  67. //Removing the item
  68. p.getInventory().remove(Material.BOOK);
  69. }
  70. }
  71. }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement