Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Repair extends JavaPlugin implements Listener{
- public void onEnable(){
- getServer().getPluginManager().registerEvents(this, this);
- }
- public void onDisable(){
- }
- @Override
- public boolean onCommand(CommandSender sender,Command cmd,String label,String args[]){
- Player player = (Player)sender;
- if(label.equalsIgnoreCase("repair")){
- if(sender.hasPermission("repair.use")){
- player.openInventory(player.getInventory());
- }else{
- sender.sendMessage("§cYou do not have permission to perform this command!");
- return true;
- }
- }
- return true;
- }
- @EventHandler
- public void InventoryClick(InventoryClickEvent e) {
- Player p = (Player) e.getWhoClicked();
- if (!(e.getInventory().getTitle().contains("Inventory"))) {
- return;
- }
- //Cancel them from taking the item and repair the item they click
- if (e.getInventory().getTitle().contains("Inventory")) {
- e.setCancelled(true);
- if (e.getCurrentItem() == null) {
- return;
- }
- //Remember their inventory is 35 slots (starting at 0) so you need to do the following 35 times.
- if (e.getSlot() == 0){
- //Repair here
- p.closeInventory();
- }
- }
- }
- @EventHandler
- public void onClick(PlayerInteractEvent e){
- Player p = e.getPlayer();
- //Change the action if you want
- if(e.getAction() == Action.RIGHT_CLICK_AIR){
- //Make the item I just did a book :P
- if(e.getPlayer().getInventory().getItemInHand().equals(Material.BOOK)){
- //Opening the inventory
- p.performCommand("repair");
- //Removing the item
- p.getInventory().remove(Material.BOOK);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement