示例#1
0
  /**
   * Gets the region selection for the player.
   *
   * @param player
   * @return the selection or null if there was none
   */
  public Selection getSelection(Player player) {
    if (player == null) {
      throw new IllegalArgumentException("Null player not allowed");
    }
    if (!player.isOnline()) {
      throw new IllegalArgumentException("Offline player not allowed");
    }

    LocalSession session = controller.getSession(wrapPlayer(player));
    RegionSelector selector =
        session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));

    try {
      Region region = selector.getRegion();
      World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();

      if (region instanceof CuboidRegion) {
        return new CuboidSelection(world, selector, (CuboidRegion) region);
      } else if (region instanceof Polygonal2DRegion) {
        return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
      } else {
        return null;
      }
    } catch (IncompleteRegionException e) {
      return null;
    }
  }
示例#2
0
  /**
   * Sets the region selection for a player.
   *
   * @param player
   * @param selection
   */
  public void setSelection(Player player, Selection selection) {
    if (player == null) {
      throw new IllegalArgumentException("Null player not allowed");
    }
    if (!player.isOnline()) {
      throw new IllegalArgumentException("Offline player not allowed");
    }
    if (selection == null) {
      throw new IllegalArgumentException("Null selection not allowed");
    }

    LocalSession session = controller.getSession(wrapPlayer(player));
    RegionSelector sel = selection.getRegionSelector();
    session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
    session.dispatchCUISelection(wrapPlayer(player));
  }