예제 #1
0
  /**
   * Called when a player interacts
   *
   * @param event Relevant event details
   */
  @EventHandler(event = PlayerInteractEvent.class)
  public void onPlayerInteract(PlayerInteractEvent event) {

    final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
    final LocalWorld world = player.getWorld();
    final WorldEdit we = plugin.getWorldEdit();

    PlayerInteractEvent.Action action = event.getAction();
    if (action == Action.LEFT_CLICK) {
      if (event.isAir() && ignoreLeftClickAir) {
        return;
      }

      if (!event.isAir()) {
        final Point clickedBlock = event.getInteractedPoint();
        final WorldVector pos =
            new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

        if (we.handleBlockLeftClick(player, pos)) {
          event.setCancelled(true);
        }
      }

      if (we.handleArmSwing(player)) {
        event.setCancelled(true);
      }

      if (!event.isAir() && !ignoreLeftClickAir) {
        final int taskId =
            Spout.getGame()
                .getScheduler()
                .scheduleSyncDelayedTask(
                    plugin,
                    new Runnable() {
                      public void run() {
                        ignoreLeftClickAir = false;
                      }
                    },
                    2);

        if (taskId != -1) {
          ignoreLeftClickAir = true;
        }
      }
    } else if (action == Action.RIGHT_CLICK) {
      if (!event.isAir()) {
        final Point clickedBlock = event.getInteractedPoint();
        final WorldVector pos =
            new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

        if (we.handleBlockRightClick(player, pos)) {
          event.setCancelled(true);
        }
      }

      if (we.handleRightClick(player)) {
        event.setCancelled(true);
      }
    }
  }
예제 #2
0
  /**
   * Called when a player interacts
   *
   * @param event Relevant event details
   */
  @EventHandler(event = PlayerInteractEvent.class)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.useItemInHand() == Result.DENY) {
      return;
    }

    final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
    final LocalWorld world = player.getWorld();
    final WorldEdit we = plugin.getWorldEdit();

    Action action = event.getAction();
    if (action == Action.LEFT_CLICK_BLOCK) {
      final Block clickedBlock = event.getClickedBlock();
      final WorldVector pos =
          new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

      if (we.handleBlockLeftClick(player, pos)) {
        event.setCancelled(true);
      }

      if (we.handleArmSwing(player)) {
        event.setCancelled(true);
      }

      if (!ignoreLeftClickAir) {
        final int taskId =
            Bukkit.getScheduler()
                .scheduleSyncDelayedTask(
                    plugin,
                    new Runnable() {
                      public void run() {
                        ignoreLeftClickAir = false;
                      }
                    },
                    2);

        if (taskId != -1) {
          ignoreLeftClickAir = true;
        }
      }
    } else if (action == Action.LEFT_CLICK_AIR) {
      if (ignoreLeftClickAir) {
        return;
      }

      if (we.handleArmSwing(player)) {
        event.setCancelled(true);
      }

    } else if (action == Action.RIGHT_CLICK_BLOCK) {
      final Block clickedBlock = event.getClickedBlock();
      final WorldVector pos =
          new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

      if (we.handleBlockRightClick(player, pos)) {
        event.setCancelled(true);
      }

      if (we.handleRightClick(player)) {
        event.setCancelled(true);
      }
    } else if (action == Action.RIGHT_CLICK_AIR) {
      if (we.handleRightClick(player)) {
        event.setCancelled(true);
      }
    }
  }