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(); } }
public void loadIslandFiles() { ArrayList<String> playersInSkb = new ArrayList<String>(); for (Player player : this.skyBlockWorld.getPlayers()) { playersInSkb.add(player.getName()); } for (String f : new File(this.directoryIslands.getAbsolutePath()).list()) { if (new File(this.directoryIslands, f).isFile()) { IslandInfo ii = null; try { ii = this.loadIslandInfo(f); } catch (Exception e) { e.printStackTrace(); continue; } if (ii != null) { if (ii.isFreeBuild()) { settings.addIslandInfo(ii); continue; } // check if a player for this island (owner or friend is online) boolean foundPlayer = false; if (playersInSkb.contains(ii.getIslandOwner())) { foundPlayer = true; } else { for (String friend : ii.getFriends()) { if (playersInSkb.contains(friend)) { foundPlayer = true; break; } } } if (foundPlayer) settings.addIslandInfo(ii); } } } }
@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; }