Search in sources :

Example 1 with SoliniaPlayer

use of com.solinia.solinia.Models.SoliniaPlayer in project solinia3-core by mixxit.

the class JsonCharacterListRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(CharacterLists.values(), new TypeToken<List<SoliniaPlayer>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + CharacterLists.size() + " CharacterLists");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaPlayer(com.solinia.solinia.Models.SoliniaPlayer) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Example 2 with SoliniaPlayer

use of com.solinia.solinia.Models.SoliniaPlayer in project solinia3-core by mixxit.

the class SoliniaPlayerFactory method CreatePlayer.

public static ISoliniaPlayer CreatePlayer(Player player, boolean main) throws CoreStateInitException {
    // A player is different to a players entity
    ISoliniaPlayer soliniaPlayer = new SoliniaPlayer();
    soliniaPlayer.setUUID(player.getUniqueId());
    soliniaPlayer.setMain(main);
    String forename = getRandomNames(5, 1)[0];
    String lastname = "";
    try {
        while (StateManager.getInstance().getPlayerManager().IsNewNameValid(forename, lastname) == false) {
            forename = getRandomNames(5, 1)[0];
        }
        soliniaPlayer.setForename(forename);
        soliniaPlayer.setLastname(lastname);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    StateManager.getInstance().getPlayerManager().addPlayer(soliniaPlayer);
    soliniaPlayer = SoliniaPlayerAdapter.Adapt(player);
    soliniaPlayer.setExperience(0d);
    soliniaPlayer.setAAExperience(0d);
    soliniaPlayer.setMana(0);
    return soliniaPlayer;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaPlayer(com.solinia.solinia.Models.SoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 3 with SoliniaPlayer

use of com.solinia.solinia.Models.SoliniaPlayer in project solinia3-core by mixxit.

the class JsonPlayerRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(players.values(), new TypeToken<List<SoliniaPlayer>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + players.size() + " players");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaPlayer(com.solinia.solinia.Models.SoliniaPlayer) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)3 SoliniaPlayer (com.solinia.solinia.Models.SoliniaPlayer)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1