Search in sources :

Example 1 with SoliniaNPCMerchant

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

the class JsonNPCMerchantRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    gsonbuilder.registerTypeAdapterFactory(new ISoliniaNPCMerchantEntryTypeAdapterFactory(SoliniaNPCMerchantEntry.class));
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(npcmerchants.values(), new TypeToken<List<SoliniaNPCMerchant>>() {
    }.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 " + npcmerchants.size() + " npcmerchants");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaNPCMerchant(com.solinia.solinia.Interfaces.ISoliniaNPCMerchant) SoliniaNPCMerchant(com.solinia.solinia.Models.SoliniaNPCMerchant) GsonBuilder(com.google.gson.GsonBuilder) ISoliniaNPCMerchantEntryTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaNPCMerchantEntryTypeAdapterFactory) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) SoliniaNPCMerchantEntry(com.solinia.solinia.Models.SoliniaNPCMerchantEntry) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Example 2 with SoliniaNPCMerchant

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

the class SoliniaNPCMerchantFactory method CreateNPCMerchant.

public static void CreateNPCMerchant(String name) throws CoreStateInitException {
    SoliniaNPCMerchant merchant = new SoliniaNPCMerchant();
    merchant.setId(StateManager.getInstance().getConfigurationManager().getNextNPCMerchantId());
    merchant.setName(name);
    StateManager.getInstance().getConfigurationManager().addNPCMerchant(merchant);
}
Also used : SoliniaNPCMerchant(com.solinia.solinia.Models.SoliniaNPCMerchant) ISoliniaNPCMerchant(com.solinia.solinia.Interfaces.ISoliniaNPCMerchant)

Aggregations

ISoliniaNPCMerchant (com.solinia.solinia.Interfaces.ISoliniaNPCMerchant)2 SoliniaNPCMerchant (com.solinia.solinia.Models.SoliniaNPCMerchant)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 ISoliniaNPCMerchantEntryTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaNPCMerchantEntryTypeAdapterFactory)1 SoliniaNPCMerchantEntry (com.solinia.solinia.Models.SoliniaNPCMerchantEntry)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1