Advertisement
TheReturningVoid

Untitled

Oct 5th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public class AnvilListener implements Listener {
  2.  
  3.   @EventHandler
  4.   public boolean onPlayerInteract(PlayerInteractEvent e) {
  5.     if (checkEvent(e)) {
  6.       Player p = e.getPlayer();
  7.       List<Block> lastTwoTargetBlocks = p.getLastTwoTargetBlocks(null, 5);
  8.       Block prevBlock = lastTwoTargetBlocks.get(0);
  9.       Block targetBlock = lastTwoTargetBlocks.get(1);
  10.       if (targetBlock.getType().equals(Material.ANVIL) && prevBlock.getType().equals(Material.AIR)) {
  11.         ItemStack item = e.getItem();
  12.         Material type = item.getType();
  13.         if (type.equals(Material.ACTIVATOR_RAIL)) {
  14.           prevBlock.setType(type);
  15.           if (targetBlock.getData == 0 || targetBlock.getData == 2) {
  16.             prevBlock.setData(0);
  17.           } else if (targetBlock.getData == 1 || targetBlock.getData == 3) {
  18.             prevBlock.setData(1);
  19.           }
  20.         }
  21.         ItemUtil.removeItemFromPlayer(p, item); // Helper method I have to remove 1 item from a player's inventory
  22.       }
  23.     }
  24.   }
  25.  
  26.   private boolean checkEvent(PlayerInteractEvent e) {
  27.     if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.hasItem() && e.hasBlock()) {
  28.       if (e.getItem.getType() == Material.ACTIVATOR_RAIL) return true;
  29.     }
  30.     return false;
  31.   }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement