Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AnvilListener implements Listener {
- @EventHandler
- public boolean onPlayerInteract(PlayerInteractEvent e) {
- if (checkEvent(e)) {
- Player p = e.getPlayer();
- List<Block> lastTwoTargetBlocks = p.getLastTwoTargetBlocks(null, 5);
- Block prevBlock = lastTwoTargetBlocks.get(0);
- Block targetBlock = lastTwoTargetBlocks.get(1);
- if (targetBlock.getType().equals(Material.ANVIL) && prevBlock.getType().equals(Material.AIR)) {
- ItemStack item = e.getItem();
- Material type = item.getType();
- if (type.equals(Material.ACTIVATOR_RAIL)) {
- prevBlock.setType(type);
- if (targetBlock.getData == 0 || targetBlock.getData == 2) {
- prevBlock.setData(0);
- } else if (targetBlock.getData == 1 || targetBlock.getData == 3) {
- prevBlock.setData(1);
- }
- }
- ItemUtil.removeItemFromPlayer(p, item); // Helper method I have to remove 1 item from a player's inventory
- }
- }
- }
- private boolean checkEvent(PlayerInteractEvent e) {
- if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.hasItem() && e.hasBlock()) {
- if (e.getItem.getType() == Material.ACTIVATOR_RAIL) return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement