private void convertFiles() { /** create database */ try { recMan = RecordManagerFactory.createRecordManager(name2UUID.getAbsolutePath()); String recordName = "nameToUUID"; treeMap = recMan.hashMap(recordName); // Load all the files from the player folder FilenameFilter ymlFilter = new FilenameFilter() { public boolean accept(File dir, String name) { String lowercaseName = name.toLowerCase(); if (lowercaseName.endsWith(".yml")) { return true; } else { return false; } } }; int count = 0; for (final File file : plugin.getPlayersFolder().listFiles(ymlFilter)) { if (count % 1000 == 0) { System.out.println("[ASkyBlock]: Processed " + count + " names to database"); } count++; try { // Get UUID String uuid = file.getName().substring(0, file.getName().length() - 4); // System.out.println("DEBUG: UUID is " + uuid); final UUID playerUUID = UUID.fromString(uuid); // Get the player's name Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { final String lineFromFile = scanner.nextLine(); if (lineFromFile.contains("playerName:")) { // Check against potentialUnowned list String playerName = lineFromFile.substring(lineFromFile.indexOf(' ')).trim(); // System.out.println("DEBUG: Player name is " + playerName); treeMap.put(playerName.toLowerCase(), playerUUID); break; } } scanner.close(); } catch (Exception ex) { System.err.println( "[ASkyBlock/AcidIsland]: Problem reading " + file.getName() + " skipping..."); // ex.printStackTrace(); } } /** Map changes are not persisted yet, commit them (save to disk) */ recMan.commit(); System.out.println("[ASkyBlock]: Complete. Processed " + count + " names to database"); // Set flag dbReady = true; } catch (Exception e) { System.err.println("[ASkyBlock/AcidIsland] : Problem creating database"); } }
/** Commits the database records and closes the database */ public void closeDB() { /** Map changes are not persisted yet, commit them (save to disk) */ try { recMan.commit(); /** close record manager */ recMan.close(); plugin.getLogger().info("Saved name database"); } catch (IOException e) { plugin.getLogger().severe("Problem saving name database!"); e.printStackTrace(); } }