public void changeToOldInventory(PlayerInfo pi) { if (!pi.isPlaying()) return; if (this.settings.getAllowContent()) { pi.setIsPlaying(false); return; } // save island inventory pi.setIslandInventory(pi.getPlayer().getInventory().getContents()); pi.setIslandArmor(pi.getPlayer().getInventory().getArmorContents()); pi.setIslandHealth(pi.getPlayer().getHealth()); pi.setIslandFood(pi.getPlayer().getFoodLevel()); pi.setIslandLevel(pi.getPlayer().getLevel()); pi.setIslandExp(pi.getPlayer().getExp()); // set old inventory pi.getPlayer().getInventory().setContents(pi.getOldInventory()); pi.getPlayer().getInventory().setArmorContents(pi.getOldArmor()); if (pi.getOldHealth() <= 0) { pi.getPlayer().setHealth(pi.getPlayer().getMaxHealth()); } else { pi.getPlayer().setHealth(pi.getOldHealth()); } if (pi.getOldFood() <= 0) { pi.getPlayer().setFoodLevel(20); } else { pi.getPlayer().setHealth(pi.getOldFood()); } pi.getPlayer().setLevel(pi.getOldLevel()); pi.getPlayer().setExp(pi.getOldExp()); pi.setIsPlaying(false); }
@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; }