/**
   * 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
 /**
  * Set block type.
  *
  * @param pt
  * @param type
  * @return
  */
 @Override
 public boolean setBlockType(Vector pt, int type) {
   world.setBlockId(
       pt.getBlockX(),
       pt.getBlockY(),
       pt.getBlockZ(),
       (short) type,
       WorldEditPlugin.getInstance());
   return world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()) != type;
 }
  // @EventHandler(event = PreCommandEvent.class, order = Order.EARLY)
  public void onPlayerCommandPreprocess(PreCommandEvent event) {

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

    if (split.length > 0) {
      split[0] = "/" + split[0];
      split = plugin.getWorldEdit().commandDetection(split);
      event.setMessage(StringUtil.joinString(split, " "));
    }
  }
示例#4
0
 /**
  * set block type & data
  *
  * @param pt
  * @param type
  * @param data
  * @return
  */
 @Override
 public boolean setTypeIdAndData(Vector pt, int type, int data) {
   int origType = getBlockType(pt), origData = getBlockData(pt);
   world.setBlockIdAndData(
       pt.getBlockX(),
       pt.getBlockY(),
       pt.getBlockZ(),
       (short) type,
       (short) data,
       WorldEditPlugin.getInstance());
   return origType != type && origData != data;
 }
  @EventHandler(event = PlayerChatEvent.class)
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Matcher matcher = cuipattern.matcher(event.getMessage());
    if (matcher.find()) {
      String type = matcher.group(1);
      String args = matcher.group(2);

      if (type.equals("v")) {
        try {
          plugin.getSession(event.getPlayer()).setCUIVersion(Integer.parseInt(args));
          event.setCancelled(true);
        } catch (NumberFormatException e) {
        }
      }
    }
  }
 /**
  * Called when a player leaves a server
  *
  * @param event Relevant event details
  */
 @EventHandler(event = PlayerLeaveEvent.class)
 public void onPlayerQuit(PlayerLeaveEvent event) {
   plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
 }
 @EventHandler(event = PlayerJoinEvent.class, order = Order.EARLIEST)
 public void onPlayerJoin(PlayerJoinEvent event) {
   plugin.wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
 }