use of com.solinia.solinia.Factories.ISoliniaNPCMerchantEntryTypeAdapterFactory 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();
}
}
use of com.solinia.solinia.Factories.ISoliniaNPCMerchantEntryTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonNPCMerchantRepository method reload.
@Override
public void reload() {
List<ISoliniaNPCMerchant> file = new ArrayList<ISoliniaNPCMerchant>();
try {
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaNPCMerchantEntryTypeAdapterFactory(SoliniaNPCMerchantEntry.class));
Gson gson = gsonbuilder.create();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaNPCMerchant>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
npcmerchants.clear();
for (ISoliniaNPCMerchant i : file) {
npcmerchants.put(i.getId(), i);
}
System.out.println("Reloaded " + npcmerchants.size() + " npcmerchants");
}
Aggregations