Search in sources :

Example 1 with NbtRepository

use of de.Keyle.MyPet.repository.types.NbtRepository in project MyPet by xXKeyleXx.

the class Converter method convert.

public static boolean convert() {
    MyPetApi.getLogger().info("Converting from NBT to " + Configuration.Repository.REPOSITORY_TYPE + "...");
    NbtRepository fromRepo = new NbtRepository();
    fromRepo.init();
    SqLiteRepository toRepo = (SqLiteRepository) MyPetApi.getRepository();
    List<MyPetPlayer> playerList = fromRepo.getAllMyPetPlayers();
    toRepo.addMyPetPlayers(playerList);
    List<StoredMyPet> pets = fromRepo.getAllMyPets();
    toRepo.addMyPets(pets);
    toRepo.save();
    fromRepo.disable();
    File nbtFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "My.Pets");
    File nbtFileOld = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "My.Pets.old");
    nbtFile.renameTo(nbtFileOld);
    MyPetApi.getPlugin().getConfig().set("MyPet.Repository.NBT", null);
    MyPetApi.getPlugin().saveConfig();
    MyPetApi.getLogger().info("Conversion from NBT to " + Configuration.Repository.REPOSITORY_TYPE + " complete!");
    return true;
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) SqLiteRepository(de.Keyle.MyPet.repository.types.SqLiteRepository) NbtRepository(de.Keyle.MyPet.repository.types.NbtRepository) File(java.io.File) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Aggregations

StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)1 NbtRepository (de.Keyle.MyPet.repository.types.NbtRepository)1 SqLiteRepository (de.Keyle.MyPet.repository.types.SqLiteRepository)1 File (java.io.File)1