Ejemplo n.º 1
0
 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");
   }
 }
Ejemplo n.º 2
0
  /**
   * Opens the database
   *
   * @param plugin
   */
  public TinyDB(ASkyBlock plugin) {
    this.plugin = plugin;
    this.dbReady = false;
    // Open database
    dbFolder = new File(plugin.getDataFolder(), "database");
    name2UUID = new File(dbFolder, fileName);
    if (!dbFolder.exists()) {
      plugin.getLogger().info("Creating a tiny playerName-UUID database");
      // Create folder
      dbFolder.mkdir();
      // Run async task to do conversion
      plugin
          .getServer()
          .getScheduler()
          .runTaskAsynchronously(
              plugin,
              new Runnable() {

                @Override
                public void run() {
                  convertFiles();
                }
              });

    } else {
      try {
        recMan = RecordManagerFactory.createRecordManager(name2UUID.getAbsolutePath());
        String recordName = "nameToUUID";
        treeMap = recMan.hashMap(recordName);
        dbReady = true;
      } catch (IOException e) {
        dbReady = false;
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }