Beispiel #1
0
  /**
   * Toggle the area.
   *
   * @param player
   * @param bag
   * @throws BlockSourceException
   */
  public void playerToggle(CraftBookPlayer player, BlockBag bag) throws BlockSourceException {
    try {
      String namespace = getNamespace();
      String activeID = getActiveStateID();

      CuboidCopy copy = copyManager.load(namespace, activeID);

      if (!isNewArea && copy.distance(pt) > 4) {
        player.printError("This sign is too far away!");
        return;
      }

      if (!copy.shouldClear()) {
        copy.paste(bag);
      } else {
        String inactiveID = getInactiveStateID();

        if (inactiveID == null) {
          // Do nothing
        } else if (inactiveID.length() == 0) {
          copy.clear(bag);
        } else {
          copy = copyManager.load(namespace, inactiveID);
          copy.paste(bag);
        }
      }

      player.print("Toggled!");
    } catch (InvalidSignNamespace e) {
      player.printError("The namespace on the sign is invalid.");
    } catch (InvalidSignStateID e) {
      player.printError("A copy ID on the sign is invalid.");
    } catch (MissingCuboidCopyException e) {
      player.printError("The '" + e.getCopyName() + "' area does not exist.");
    } catch (CuboidCopyException e) {
      player.printError("Could not load area: " + e.getMessage());
    } catch (IOException e) {
      player.printError("Could not load area: " + e.getMessage());
    }
  }