コード例 #1
0
  /**
   * Handle a "setBuildQueue"-message.
   *
   * @param server The <code>FreeColServer</code> handling the message.
   * @param player The <code>Player</code> the message applies to.
   * @param connection The <code>Connection</code> message was received on.
   * @return An update containing the new queue or an error <code>Element</code> on failure.
   */
  public Element handle(FreeColServer server, Player player, Connection connection) {
    ServerPlayer serverPlayer = server.getPlayer(connection);
    Game game = server.getGame();
    Specification spec = game.getSpecification();

    Colony colony;
    try {
      colony = player.getOurFreeColGameObject(colonyId, Colony.class);
    } catch (Exception e) {
      return DOMMessage.clientError(e.getMessage());
    }

    if (queue == null) {
      return DOMMessage.clientError("Empty queue");
    }
    List<BuildableType> buildQueue = new ArrayList<BuildableType>();
    for (int i = 0; i < queue.length; i++) {
      try {
        buildQueue.add(i, spec.getType(queue[i], BuildableType.class));
      } catch (Exception cce) {
        return DOMMessage.clientError("Not a buildable type: " + queue[i]);
      }
    }

    // Proceed to set the build queue.
    return server.getInGameController().setBuildQueue(serverPlayer, colony, buildQueue);
  }
コード例 #2
0
  /**
   * Get a FreeColGameObjectType by identifier from a stream from a specification.
   *
   * @param spec The <code>Specification</code> to look in.
   * @param attributeName the name of the attribute identifying the <code>FreeColGameObjectType
   *     </code>.
   * @param returnClass The expected class of the return value.
   * @param defaultValue A default value to return if the attributeName attribute is not present.
   * @return The <code>FreeColGameObjectType</code> found, or the <code>defaultValue</code>.
   */
  public <T extends FreeColGameObjectType> T getType(
      Specification spec, String attributeName, Class<T> returnClass, T defaultValue) {

    final String attrib =
        // @compat 0.10.7
        (FreeColObject.ID_ATTRIBUTE_TAG.equals(attributeName))
            ? readId()
            :
            // end @compat
            getAttribute(attributeName, (String) null);

    return (attrib == null) ? defaultValue : spec.getType(attrib, returnClass);
  }
コード例 #3
0
  // @compat 0.10.7
  public <T extends FreeColGameObjectType> T getRole(
      Specification spec, String attributeName, Class<T> returnClass, T defaultValue) {

    String attrib =
        (FreeColObject.ID_ATTRIBUTE_TAG.equals(attributeName))
            ? readId()
            : getAttribute(attributeName, (String) null);

    if (attrib == null) {
      return defaultValue;
    }
    attrib = Role.fixRoleId(attrib);
    return spec.getType(attrib, returnClass);
  }