예제 #1
0
  /**
   * Called when a player attempts to use a command
   *
   * @param event Relevant event details
   */
  @EventHandler(priority = EventPriority.LOW, event = PlayerCommandPreprocessEvent.class)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    if (event.isCancelled()) {
      return;
    }

    String[] split = event.getMessage().split(" ");

    if (split.length > 0) {
      split = plugin.getWorldEdit().commandDetection(split);
      split[0] = "/" + split[0];
    }

    event.setMessage(StringUtil.joinString(split, " "));
  }
예제 #2
0
 /**
  * Called when a player leaves a server
  *
  * @param event Relevant event details
  */
 @EventHandler(event = PlayerQuitEvent.class)
 public void onPlayerQuit(PlayerQuitEvent event) {
   plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
 }
예제 #3
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);
      }
    }
  }