Ejemplo n.º 1
0
  /**
   * Validates the sign's environment.
   *
   * @param signText
   * @return false to deny
   */
  public static boolean validateEnvironment(CraftBookPlayer player, Vector pt, SignText signText) {

    ToggleArea area = new ToggleArea(player.getWorldType(), pt, signText);

    String activeID = area.getSignActiveStateID();
    String inactiveID = area.getSignInactiveStateID();
    String signNS = area.getSignNamespace();
    String playerNS = StringUtil.trimLength(player.getName(), 15);

    boolean noInactiveCopy = inactiveID.equals("-");

    if (!CopyManager.isValidName(activeID)) {
      player.printError("An invalid area name was indicated.");
      return false;
    }

    if (inactiveID.length() > 0 && !noInactiveCopy && !CopyManager.isValidName(inactiveID)) {
      player.printError("An invalid off state area name was indicated.");
      return false;
    }

    // Coerce the namespace to the player's name
    if (signNS.equals("") || signNS.equalsIgnoreCase(playerNS)) {
      signText.setLine3(playerNS);
    } else if (signNS.equals("@")) {
      if (!player.hasPermission("savensarea")) {
        player.printError("You are unable to make toggles for global areas.");
        return false;
      }
    } else {
      if (!player.hasPermission("savensarea")) {
        player.printError("You are unable to make toggles for global areas.");
        return false;
      }
    }

    if (area.isNewArea) {
      signText.setLine2("[Area]");
    } else {
      signText.setLine2("[Toggle]");
    }

    player.print("Area toggle created!");

    return true;
  }
Ejemplo n.º 2
0
  /**
   * Get the on state ID. This may raise a InvalidSignStateID exception if the specified ID is
   * invalid.
   *
   * @return
   * @throws InvalidSignStateID
   */
  public String getActiveStateID() throws InvalidSignStateID {
    String id = getSignActiveStateID();

    if (CopyManager.isValidName(id)) {
      return id;
    }

    throw new InvalidSignStateID();
  }
Ejemplo n.º 3
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());
    }
  }
Ejemplo n.º 4
0
  /**
   * Get the off state ID. This may raise a InvalidSignStateID exception if the specified ID is
   * invalid. If the returned string is empty, that means that the area should be cleared. If it is
   * null, it means that the area should not be changed.
   *
   * @return
   * @throws InvalidSignStateID
   */
  public String getInactiveStateID() throws InvalidSignStateID {
    String id = getSignInactiveStateID();

    if (id.equals("")) {
      return "";
    } else if (id.equals("-")) {
      return null;
    } else if (CopyManager.isValidName(id)) {
      return id;
    }

    throw new InvalidSignStateID();
  }
Ejemplo n.º 5
0
  /**
   * Get the namespace used for loading. This may raise a InvalidSignNamespace if the specified
   * namespace for the sign is not an acceptable value.
   *
   * @return
   * @throws InvalidSignNamespace
   */
  public String getNamespace() throws InvalidSignNamespace {
    String namespace = getSignNamespace();

    if (namespace.equals("@") || !isNewArea) {
      return "global";
    } else {
      if (CopyManager.isValidNamespace(namespace)) {
        return "~" + namespace;
      }

      throw new InvalidSignNamespace();
    }
  }
Ejemplo n.º 6
0
  /**
   * Set the area inactive.
   *
   * @param player
   * @param bag
   */
  public void setInactive(BlockBag bag) {
    try {
      String namespace = getNamespace();
      String inactiveID = getInactiveStateID();

      CuboidCopy copy = null;

      if (inactiveID == null) {
        // Do nothing
      } else if (inactiveID.length() == 0) {
        String activeID = getActiveStateID();
        copy = copyManager.load(namespace, activeID);

        if (!isNewArea && copy.distance(pt) > 4) {
          return;
        }

        copy.clear(bag);
      } else {
        copy = copyManager.load(namespace, inactiveID);

        if (!isNewArea && copy.distance(pt) > 4) {
          return;
        }

        copy = copyManager.load(namespace, inactiveID);
        copy.paste(bag);
      }
    } catch (BlockSourceException e) {
    } catch (InvalidSignNamespace e) {
    } catch (InvalidSignStateID e) {
    } catch (MissingCuboidCopyException e) {
    } catch (CuboidCopyException e) {
    } catch (IOException e) {
    }
  }
Ejemplo n.º 7
0
  /**
   * Set the area active.
   *
   * @param player
   * @param bag
   */
  public void setActive(BlockBag bag) {
    try {
      String namespace = getNamespace();
      String activeID = getActiveStateID();

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

      if (!isNewArea && copy.distance(pt) > 4) {
        return;
      }

      copy.paste(bag);
    } catch (BlockSourceException e) {;
    } catch (InvalidSignNamespace e) {
    } catch (InvalidSignStateID e) {
    } catch (MissingCuboidCopyException e) {
    } catch (CuboidCopyException e) {
    } catch (IOException e) {
    }
  }