Ejemplo n.º 1
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    if (event.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK
        || event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) {
      PlayerEvent playerEvent;
      if (SignUtil.isSign(event.getClickedBlock())) {
        playerEvent =
            new PlayerEvent(
                SignUtil.getSign(event.getClickedBlock()),
                event.getAction() == Action.LEFT_CLICK_BLOCK
                    ? PlayerEvent.Action.LEFT_CLICK
                    : PlayerEvent.Action.RIGHT_CLICK,
                event.getPlayer(),
                event);
      } else {
        playerEvent =
            new PlayerEvent(
                event.getClickedBlock(),
                event.getAction() == Action.LEFT_CLICK_BLOCK
                    ? PlayerEvent.Action.LEFT_CLICK
                    : PlayerEvent.Action.RIGHT_CLICK,
                event.getPlayer(),
                event);
      }
      mechanicsHandler.callPlayerEvent(playerEvent);
    }
  }
Ejemplo n.º 2
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.isCancelled()) return;
   PlayerEvent playerEvent;
   if (SignUtil.isSign(event.getBlock())) {
     playerEvent =
         new PlayerEvent(
             SignUtil.getSign(event.getBlock()),
             PlayerEvent.Action.BREAK,
             event.getPlayer(),
             event);
   } else {
     playerEvent =
         new PlayerEvent(event.getBlock(), PlayerEvent.Action.BREAK, event.getPlayer(), event);
   }
   mechanicsHandler.callPlayerEvent(playerEvent);
   event.setCancelled(playerEvent.isCancelled());
 }
Ejemplo n.º 3
0
 @Override
 public void onPlayerRightClickSign(PlayerEvent event) {
   String activator = event.getMechanicIdentifier();
   BlockFace direction =
       activator.equals("[Lift Up]")
           ? BlockFace.UP
           : (activator.equals("[Lift Down]") ? BlockFace.DOWN : null);
   int maxSearchHeight = config.getMaxSearchHeight();
   if (direction == BlockFace.DOWN || direction == BlockFace.UP) {
     Block block;
     for (int dy = 1; dy < maxSearchHeight; dy++) {
       block = event.getBlock().getRelative(0, (direction == BlockFace.UP ? dy : -dy), 0);
       if (SignUtil.isSign(block)) {
         String id = SignUtil.getMechanicsIdentifier(SignUtil.getSign(block));
         if (id.equals("[Lift]") || id.equals("[Lift Up]") || id.equals("[Lift Down]")) {
           movePlayer(block, event.getPlayer());
         }
       }
     }
   }
 }
Ejemplo n.º 4
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onBlockRedstoneChange(BlockRedstoneEvent event) {
   if (event.getNewCurrent() == event.getOldCurrent()
       || event.getNewCurrent() > 0 && event.getOldCurrent() > 0) return;
   RedstoneEvent redstoneEvent =
       new RedstoneEvent(
           (event.getNewCurrent() > 0) ? RedstoneEvent.State.ON : RedstoneEvent.State.OFF, event);
   for (BlockFace blockFace : blockFaces) {
     Block block = event.getBlock().getRelative(blockFace);
     redstoneEvent.setData(
         SignUtil.isSign(event.getBlock().getRelative(blockFace))
             ? Event.Type.SIGN
             : Event.Type.BLOCK,
         event.getBlock(),
         blockFace.getOppositeFace());
     mechanicsHandler.callRedstoneEvent(redstoneEvent);
   }
 }