use of com.solinia.solinia.Factories.ISoliniaNPCEventHandlerTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonNPCRepository method reload.
@Override
public void reload() {
List<ISoliniaNPC> file = new ArrayList<ISoliniaNPC>();
try {
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaNPCEventHandlerTypeAdapterFactory(SoliniaNPCEventHandler.class));
Gson gson = gsonbuilder.create();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaNPC>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
NPCs.clear();
for (ISoliniaNPC i : file) {
if (i.getEventHandlers().size() > 0) {
for (ISoliniaNPCEventHandler handler : i.getEventHandlers()) {
if (handler.getNpcId() == 0) {
handler.setNpcId(i.getId());
System.out.println("Corrected invalid NPC event handler " + handler.getTriggerdata() + " on npc: " + i.getId());
}
}
}
NPCs.put(i.getId(), i);
}
System.out.println("Reloaded " + NPCs.size() + " NPCs");
}
use of com.solinia.solinia.Factories.ISoliniaNPCEventHandlerTypeAdapterFactory in project solinia3-core by mixxit.
the class JsonNPCRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaNPCEventHandlerTypeAdapterFactory(SoliniaNPCEventHandler.class));
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(NPCs.values(), new TypeToken<List<SoliniaNPC>>() {
}.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 " + NPCs.size() + " NPCs");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations