コード例 #1
0
  private boolean warpExists(Warp warp) {
    WarpDataAccess data = schema.getInstance();

    try {
      HashMap<String, Object> filter = new HashMap<String, Object>();
      filter.put("name", warp.getName());
      Database.get().load(data, filter);
    } catch (DatabaseReadException e) {
      log.error(e.getMessage(), e);
    }
    return data.hasData();
  }
コード例 #2
0
  /**
   * Load and return all warps
   *
   * @return An ArrayList containing all loaded Warp instances.
   */
  public List<Warp> loadWarps() {
    List<Warp> warps = Lists.newArrayList();
    List<DataAccess> daos = Lists.newArrayList();
    boolean needsUpdate = false;

    try {
      Database.get().loadAll(schema, daos, new HashMap<String, Object>());
      for (DataAccess dao : daos) {
        WarpDataAccess data = (WarpDataAccess) dao;
        Group[] groups = makeGroupArray(data.groups);
        String owner = ToolBox.stringToNull(data.owner);
        String name = data.name;
        boolean playerHome = data.isPlayerHome;
        Location loc = null;
        if (((WarpDataAccess) dao).location.equals("N/A")) {
          loc = Location.fromDataAccess((LocationDataAccess) dao);
        } else {
          needsUpdate = true;
          loc = Location.fromString(data.location);
        }
        Warp warp;

        if (owner != null) {
          warp = new Warp(loc, name, owner, playerHome);
        } else if (groups != null && groups.length > 0) {
          warp = new Warp(loc, groups, name);
        } else {
          // assume this is a public warp
          warp = new Warp(loc, name);
        }
        warps.add(warp);
      }
    } catch (DatabaseReadException e) {
      log.error(e.getMessage(), e);
    }

    // Apply pending updates
    if (needsUpdate) {
      Canary.log.debug("Updating data for Warps...");
      for (Warp warp : warps) {
        this.updateWarp(warp);
      }
    }
    return warps;
  }