Esempio n. 1
0
 private boolean importIsland(uSkyBlock plugin, File file) {
   log.info("Importing " + file);
   FileConfiguration config = new YamlConfiguration();
   readConfig(config, file);
   if (config.contains("party.leader") && !config.contains("party.leader.name")) {
     String leaderName = config.getString("party.leader");
     ConfigurationSection leaderSection = config.createSection("party.leader");
     leaderSection.set("name", leaderName);
     leaderSection.set("uuid", UUIDUtil.asString(getUUID(leaderName)));
   }
   ConfigurationSection members = config.getConfigurationSection("party.members");
   if (members != null) {
     for (String member : members.getKeys(false)) {
       ConfigurationSection section = members.getConfigurationSection(member);
       if (!section.contains("name")) {
         members.set(member, null);
         String uuid = UUIDUtil.asString(getUUID(member));
         members.createSection(uuid, section.getValues(true));
         members.set(uuid + ".name", member);
       } else {
         log.info("Skipping " + member + ", already has a name");
       }
     }
   }
   try {
     config.save(file);
     return true;
   } catch (IOException e) {
     log.log(Level.SEVERE, "Failed to import " + file, e);
     return false;
   }
 }
Esempio n. 2
0
 @SuppressWarnings("deprecation")
 private boolean importPlayer(uSkyBlock plugin, File file) {
   log.info("Importing " + file);
   String name = file.getName().substring(0, file.getName().lastIndexOf("."));
   OfflinePlayer player = plugin.getServer().getOfflinePlayer(name);
   if (player == null) {
     // TODO: 04/01/2015 - R4zorax: Some report-logging to a .txt file would be nice
     return false;
   }
   UUID uniqueId = player.getUniqueId();
   name2uuid.put(player.getName(), uniqueId);
   if (uniqueId.toString().equals(name)) {
     log.info("Skipping, the filename is already a UUID");
     return true; // Skipped
   }
   File newConfig =
       new File(plugin.getDataFolder() + File.separator + "players", uniqueId.toString() + ".yml");
   if (file.renameTo(newConfig)) {
     FileConfiguration config = new YamlConfiguration();
     readConfig(config, newConfig);
     if (config.contains("player.uuid")) {
       log.info("Skipping, player.uuid already present");
       return true;
     }
     config.set("player.name", player.getName());
     config.set("player.uuid", UUIDUtil.asString(uniqueId));
     // TODO: 04/01/2015 - R4zorax: Move the challenges now we're at it...
     try {
       config.save(newConfig);
       if (!newConfig.getName().equals(file.getName())) {
         if (file.exists() && !file.delete()) {
           file.deleteOnExit();
         }
       }
       return true;
     } catch (IOException e) {
       log.log(Level.SEVERE, "Failed!", e);
       return false;
     }
   }
   return false;
 }