public void savePlayerInfo(PlayerInfo pi) { YamlConfiguration yamlPlayerInfo = new YamlConfiguration(); File filePlayerInfo = new File(this.directoryPlayers, pi.getPlayerName() + ".yml"); // island info if (pi.getIslandInfo() != null) { yamlPlayerInfo.set( EnumPlayerConfig.ISLAND_NUMBER.getPath(), pi.getIslandInfo().getIslandNumber()); } yamlPlayerInfo.set(EnumPlayerConfig.IS_PLAYING.getPath(), pi.isPlaying()); yamlPlayerInfo.set(EnumPlayerConfig.IS_DEAD.getPath(), pi.isDead()); yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_FOOD.getPath(), "" + pi.getIslandFood()); yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_HEALTH.getPath(), "" + pi.getIslandHealth()); yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_EXP.getPath(), "" + pi.getIslandExp()); yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_LEVEL.getPath(), "" + pi.getIslandLevel()); yamlPlayerInfo.set( EnumPlayerConfig.ISLAND_INVENTORY.getPath(), ItemParser.getListFromItemStackArray(pi.getIslandInventory())); yamlPlayerInfo.set( EnumPlayerConfig.ISLAND_ARMOR.getPath(), ItemParser.getListFromItemStackArray(pi.getIslandArmor())); yamlPlayerInfo.set( EnumPlayerConfig.OLD_LOCATION.getPath(), LocationParser.getStringFromLocation(pi.getOldLocation())); yamlPlayerInfo.set(EnumPlayerConfig.OLD_FOOD.getPath(), "" + pi.getOldFood()); yamlPlayerInfo.set(EnumPlayerConfig.OLD_HEALTH.getPath(), "" + pi.getOldHealth()); yamlPlayerInfo.set(EnumPlayerConfig.OLD_EXP.getPath(), "" + pi.getOldExp()); yamlPlayerInfo.set(EnumPlayerConfig.OLD_LEVEL.getPath(), "" + pi.getOldLevel()); yamlPlayerInfo.set( EnumPlayerConfig.OLD_INVENTORY.getPath(), ItemParser.getListFromItemStackArray(pi.getOldInventory())); yamlPlayerInfo.set( EnumPlayerConfig.OLD_ARMOR.getPath(), ItemParser.getListFromItemStackArray(pi.getOldArmor())); yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_BUILTLIST.getPath(), pi.getBuildListNumbers()); try { yamlPlayerInfo.save(filePlayerInfo); } catch (IOException e) { e.printStackTrace(); } }
@SuppressWarnings("unchecked") public PlayerInfo loadPlayerInfo(String playerName) { YamlConfiguration yamlPlayerInfo = new YamlConfiguration(); File filePlayerInfo = new File(this.directoryPlayers, playerName + ".yml"); if (!filePlayerInfo.exists()) { return null; } try { yamlPlayerInfo.load(filePlayerInfo); } catch (Exception e) { e.printStackTrace(); return null; } PlayerInfo pi = new PlayerInfo(playerName); // Find own Island int ownsIslandNr = -1; if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_NUMBER.getPath())) { ownsIslandNr = yamlPlayerInfo.getInt(EnumPlayerConfig.ISLAND_NUMBER.getPath()); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_NUMBER.getPath(), ownsIslandNr); } pi.setIslandInfo(settings.getIslandInfo(ownsIslandNr)); // Check consistency if (pi.getHasIsland() && !pi.getIslandInfo().isIslandOwner(playerName)) { pi.setIslandInfo(null); } // Find Buildpermissions // buildPermissions = new HashMap<Integer, IslandInfo>(); ArrayList<Integer> builtlist = new ArrayList<Integer>(); if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_BUILTLIST.getPath())) { builtlist = (ArrayList<Integer>) yamlPlayerInfo.getList(EnumPlayerConfig.ISLAND_BUILTLIST.getPath()); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_BUILTLIST.getPath(), builtlist); } // Go through buildlist with Islandnr to get IslandInfos for (int islandnr : builtlist) { IslandInfo friend = settings.getIslandInfo(islandnr); if (friend != null && friend.containsFriend(playerName)) { pi.addBuildPermission(islandnr, friend); } } boolean isPlaying = false; if (yamlPlayerInfo.contains(EnumPlayerConfig.IS_PLAYING.getPath())) { isPlaying = Boolean.parseBoolean( yamlPlayerInfo.get(EnumPlayerConfig.IS_PLAYING.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.IS_PLAYING.getPath(), false); } pi.setIsPlaying(isPlaying); boolean isDead = false; if (yamlPlayerInfo.contains(EnumPlayerConfig.IS_DEAD.getPath())) { isDead = Boolean.parseBoolean(yamlPlayerInfo.get(EnumPlayerConfig.IS_DEAD.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.IS_DEAD.getPath(), false); } pi.setDead(isDead); int islandFood = 20; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_FOOD.getPath())) { islandFood = Integer.parseInt(yamlPlayerInfo.get(EnumPlayerConfig.ISLAND_FOOD.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_FOOD.getPath(), 20); } } catch (Exception e) { } pi.setIslandFood(islandFood); int islandHealth = 20; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_HEALTH.getPath())) { islandHealth = Integer.parseInt( yamlPlayerInfo.get(EnumPlayerConfig.ISLAND_HEALTH.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_HEALTH.getPath(), 20); } } catch (Exception e) { } pi.setIslandHealth(islandHealth); int islandExp = 0; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_EXP.getPath())) { islandExp = Integer.parseInt(yamlPlayerInfo.get(EnumPlayerConfig.ISLAND_EXP.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_EXP.getPath(), 0); } } catch (Exception e) { } pi.setIslandExp(islandExp); int islandLevel = 0; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_LEVEL.getPath())) { islandLevel = Integer.parseInt( yamlPlayerInfo.get(EnumPlayerConfig.ISLAND_LEVEL.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_LEVEL.getPath(), 0); } } catch (Exception e) { } pi.setIslandLevel(islandLevel); ItemStack[] islandInventory = new ItemStack[36]; if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_INVENTORY.getPath())) { ArrayList<String> listIslandInventory = (ArrayList<String>) yamlPlayerInfo.get(EnumPlayerConfig.ISLAND_INVENTORY.getPath()); islandInventory = ItemParser.getItemStackArrayFromList(listIslandInventory, 36); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_INVENTORY.getPath(), new ArrayList<String>()); } pi.setIslandInventory(islandInventory); ItemStack[] islandArmor = new ItemStack[4]; if (yamlPlayerInfo.contains(EnumPlayerConfig.ISLAND_ARMOR.getPath())) { ArrayList<String> listIslandArmor = (ArrayList<String>) yamlPlayerInfo.get(EnumPlayerConfig.ISLAND_ARMOR.getPath()); islandArmor = ItemParser.getItemStackArrayFromList(listIslandArmor, 4); } else { yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_ARMOR.getPath(), new ArrayList<String>()); } pi.setIslandArmor(islandArmor); Location oldLocation = null; if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_LOCATION.getPath())) { oldLocation = LocationParser.parseStringToLocation( yamlPlayerInfo.get(EnumPlayerConfig.OLD_LOCATION.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_LOCATION.getPath(), ""); } pi.setOldLocation(oldLocation); int oldFood = 20; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_FOOD.getPath())) { oldFood = Integer.parseInt(yamlPlayerInfo.get(EnumPlayerConfig.OLD_FOOD.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_FOOD.getPath(), 20); } } catch (Exception e) { } pi.setOldFood(oldFood); int oldHealth = 20; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_HEALTH.getPath())) { oldHealth = Integer.parseInt(yamlPlayerInfo.get(EnumPlayerConfig.OLD_HEALTH.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_HEALTH.getPath(), 20); } } catch (Exception e) { } pi.setOldHealth(oldHealth); int oldExp = 0; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_EXP.getPath())) { oldExp = Integer.parseInt(yamlPlayerInfo.get(EnumPlayerConfig.OLD_EXP.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_EXP.getPath(), 0); } } catch (Exception e) { } pi.setOldExp(oldExp); int oldLevel = 0; try { if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_LEVEL.getPath())) { oldLevel = Integer.parseInt(yamlPlayerInfo.get(EnumPlayerConfig.OLD_LEVEL.getPath()).toString()); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_LEVEL.getPath(), 0); } } catch (Exception e) { } pi.setOldLevel(oldLevel); ItemStack[] oldInventory = new ItemStack[36]; if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_INVENTORY.getPath())) { ArrayList<String> listOldInventory = (ArrayList<String>) yamlPlayerInfo.get(EnumPlayerConfig.OLD_INVENTORY.getPath()); oldInventory = ItemParser.getItemStackArrayFromList(listOldInventory, 36); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_INVENTORY.getPath(), new ArrayList<String>()); } pi.setOldInventory(oldInventory); ItemStack[] oldArmor = new ItemStack[4]; if (yamlPlayerInfo.contains(EnumPlayerConfig.OLD_ARMOR.getPath())) { ArrayList<String> listOldArmor = (ArrayList<String>) yamlPlayerInfo.get(EnumPlayerConfig.OLD_ARMOR.getPath()); oldArmor = ItemParser.getItemStackArrayFromList(listOldArmor, 4); } else { yamlPlayerInfo.set(EnumPlayerConfig.OLD_ARMOR.getPath(), new ArrayList<String>()); } pi.setOldArmor(oldArmor); try { yamlPlayerInfo.save(filePlayerInfo); } catch (IOException e) { e.printStackTrace(); return null; } return pi; }