예제 #1
0
 /**
  * Deserializes an MPoint from a string.
  *
  * @param string The string to deserialize.
  * @return The deserialized MPoint.
  */
 public static MPoint deserialize(String string) {
   try {
     return StringSerializer.fromString(string, MPoint.class);
   } catch (IOException ex) {
     MLogger.log(Level.SEVERE, "Could not deserialize an MPoint from a string!", ex);
   } catch (ClassNotFoundException ex) {
     MLogger.log(
         Level.SEVERE, "Could not deserialize an MPoint due to a class not being found!", ex);
   } catch (ClassCastException ex) {
     MLogger.log(Level.SEVERE, "Given string is not an MPoint!", ex);
   }
   return null;
 }
예제 #2
0
  /**
   * Saves all city/district mappings.
   *
   * @return This CityManager.
   */
  public CityManager saveCityDistrictMappings() {
    File mappingFile = Mafiacraft.getOrCreateSubFile("geo", "city_district_mappings.yml");
    YamlConfiguration conf = new YamlConfiguration();

    for (Entry<City, List<District>> mapping : cityDistrictMap.entrySet()) {
      City city = mapping.getKey();
      List<District> dists = mapping.getValue();
      List<String> distStrs = new ArrayList<String>();
      for (District district : dists) {
        distStrs.add(district.getUid());
      }
      conf.set(Integer.toString(city.getId()), dists);
    }

    try {
      conf.save(mappingFile);
    } catch (IOException ex) {
      MLogger.log(
          Level.SEVERE,
          "The city/district mapping file could not be written for some odd reason!",
          ex);
    }

    return this;
  }
예제 #3
0
 /**
  * Serializes the MPoint to a string.
  *
  * @return The serialized MPoint.
  */
 public String serializeToString() {
   try {
     return StringSerializer.toString(this);
   } catch (IOException ex) {
     MLogger.log(Level.SEVERE, "Could not serialize the MPoint " + this + "!", ex);
   }
   return null;
 }
예제 #4
0
 /**
  * Gets a section from its coordinates.
  *
  * @param world The world.
  * @param x The x coordinate.
  * @param y The y coordinate.
  * @param z The z coordinate.
  * @return The section.
  */
 public Section getSection(MWorld world, int x, int y, int z) {
   try {
     return getSectionCache(world).get(getSectionKey(x, y, z));
   } catch (ExecutionException ex) {
     MLogger.log(
         Level.SEVERE,
         "Could not retrieve section (" + world + ", " + x + ", " + y + ", " + z + ") from cache.",
         ex);
   }
   return null;
 }
예제 #5
0
  /**
   * Gets a district from their uid.
   *
   * @param uid The uid of the district as defined in District.getUid().
   * @return The District corresponding with the UID.
   */
  public District getDistrictFromUid(String uid) {
    String[] split = uid.split(";");
    if (split.length < 2) {
      MLogger.log(
          Level.SEVERE,
          "Invalid District UID encountered: not enough semicolon delimited parts! UID in question: '"
              + uid
              + "'.");
    }

    MWorld world = getWorld(split[0]);
    if (world == null) {
      MLogger.log(Level.SEVERE, "Invalid District UID encountered for world: '" + uid + "'!");
    }

    int id = 0;
    try {
      id = Integer.parseInt(split[1]);
    } catch (NumberFormatException ex) {
      MLogger.log(Level.SEVERE, "Invalid District UID encoutered for world: '" + uid + "'!");
    }

    return getDistrictMap(world).get(id);
  }
예제 #6
0
  /**
   * Saves all districts currently loaded to files.
   *
   * @return This CityManager.
   */
  public CityManager saveDistricts() {
    File districtFile = Mafiacraft.getOrCreateSubFile("geo", "districts.yml");
    YamlConfiguration conf = new YamlConfiguration();

    for (District district : getDistrictList()) {
      conf.set(district.getUid(), district);
    }

    try {
      conf.save(districtFile);
    } catch (IOException ex) {
      MLogger.log(Level.SEVERE, "The district file could not be written for some odd reason!", ex);
    }

    return this;
  }
예제 #7
0
  /**
   * Saves all cities currently loaded to files.
   *
   * @return This CityManager.
   */
  public CityManager saveCities() {
    File cityFile = Mafiacraft.getOrCreateSubFile("geo", "cities.yml");
    YamlConfiguration conf = new YamlConfiguration();

    for (City city : getCityList()) {
      conf.set(Integer.toString(city.getId()), city);
    }

    try {
      conf.save(cityFile);
    } catch (IOException ex) {
      MLogger.log(Level.SEVERE, "The city file could not be written for some odd reason!", ex);
    }

    return this;
  }
예제 #8
0
  /**
   * Saves all CityWorlds to the config.
   *
   * @return This City Manager.
   */
  public CityManager saveCityWorlds() {
    File cityFile = Mafiacraft.getOrCreateSubFile("geo", "cityworlds.yml");
    YamlConfiguration conf = new YamlConfiguration();

    for (MWorld cityWorld : getWorldList()) {
      conf.set(cityWorld.getName(), cityWorld);
    }

    try {
      conf.save(cityFile);
    } catch (IOException ex) {
      MLogger.log(
          Level.SEVERE, "The city world file could not be written for some odd reason!", ex);
    }

    return this;
  }