コード例 #1
0
  public void saveIslandInfo(IslandInfo ii) {
    YamlConfiguration yamlIslandInfo = new YamlConfiguration();
    File filePlayerInfo = new File(this.directoryIslands, ii.getIslandNumber() + ".yml");

    yamlIslandInfo.set(EnumIslandConfig.ISLAND_OWNER.getPath(), ii.getIslandOwner());
    yamlIslandInfo.set(
        EnumIslandConfig.ISLAND_LOCATION.getPath(),
        LocationParser.getStringFromLocation(ii.getIslandLocation()));
    yamlIslandInfo.set(
        EnumIslandConfig.HOME_LOCATION.getPath(),
        LocationParser.getStringFromLocation(ii.getHomeLocation()));

    yamlIslandInfo.set(EnumIslandConfig.FRIENDS.getPath(), ii.getFriends());
    try {
      yamlIslandInfo.save(filePlayerInfo);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public IslandInfo loadIslandInfo(String island) {
    YamlConfiguration yamlIslandInfo = new YamlConfiguration();
    File fileIslandInfo = new File(this.directoryIslands, island);
    if (!fileIslandInfo.exists()) {
      return null;
    }
    try {
      yamlIslandInfo.load(fileIslandInfo);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

    int islandNumber = Integer.parseInt(fileIslandInfo.getName().replace(".yml", ""));
    IslandInfo ii = new IslandInfo(islandNumber);

    String islandOwner = "";
    if (yamlIslandInfo.contains(EnumIslandConfig.ISLAND_OWNER.getPath())) {
      islandOwner = yamlIslandInfo.get(EnumIslandConfig.ISLAND_OWNER.getPath()).toString();
    } else {
      yamlIslandInfo.set(EnumIslandConfig.ISLAND_OWNER.getPath(), false);
    }
    ii.setIslandOwner(islandOwner);

    Location islandLocation = null;
    if (yamlIslandInfo.contains(EnumIslandConfig.ISLAND_LOCATION.getPath())) {
      islandLocation =
          LocationParser.parseStringToLocation(
              yamlIslandInfo.get(EnumIslandConfig.ISLAND_LOCATION.getPath()).toString());
    } else {
      yamlIslandInfo.set(
          EnumIslandConfig.ISLAND_LOCATION.getPath(),
          LocationParser.getStringFromLocation(ii.getIslandLocation()));
    }
    ii.setIslandLocation(islandLocation);

    Location homeLocation = null;
    if (yamlIslandInfo.contains(EnumIslandConfig.HOME_LOCATION.getPath())) {
      islandLocation =
          LocationParser.parseStringToLocation(
              yamlIslandInfo.get(EnumIslandConfig.HOME_LOCATION.getPath()).toString());
    } else {
      yamlIslandInfo.set(
          EnumIslandConfig.HOME_LOCATION.getPath(),
          LocationParser.getStringFromLocation(ii.getHomeLocation()));
    }
    ii.setHomeLocation(homeLocation);

    ArrayList<String> friends = new ArrayList<String>();
    if (yamlIslandInfo.contains(EnumIslandConfig.FRIENDS.getPath())) {
      friends = (ArrayList<String>) yamlIslandInfo.get(EnumIslandConfig.FRIENDS.getPath());
    } else {
      yamlIslandInfo.set(EnumIslandConfig.FRIENDS.getPath(), ii.getFriends());
    }

    ii.setFriends(friends);

    boolean freeBuild = false;
    if (yamlIslandInfo.contains(EnumIslandConfig.FREE_BUILD.getPath())) {
      freeBuild =
          Boolean.parseBoolean(
              yamlIslandInfo.get(EnumIslandConfig.FREE_BUILD.getPath()).toString());
    } else {
      yamlIslandInfo.set(EnumIslandConfig.FREE_BUILD.getPath(), ii.isFreeBuild());
    }
    ii.setFreeBuild(freeBuild);

    try {
      yamlIslandInfo.save(fileIslandInfo);
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }

    return ii;
  }