use of com.solinia.solinia.Models.SoliniaSpell in project solinia3-core by mixxit.
the class SoliniaSpellFactory method CreateSpellCopy.
public static void CreateSpellCopy(int spellid, String name) throws Exception {
try {
SoliniaSpell source = (SoliniaSpell) StateManager.getInstance().getConfigurationManager().getSpell(spellid);
if (source == null)
throw new Exception("Source Spell could not be found!");
Gson gson = new Gson();
String tmp = gson.toJson(source);
SoliniaSpell obj = gson.fromJson(tmp, SoliniaSpell.class);
obj.setId(StateManager.getInstance().getConfigurationManager().getNextSpellId());
obj.setName(name);
obj.setLastUpdatedTimeNow();
StateManager.getInstance().getConfigurationManager().addSpell(obj);
System.out.println("New Spell Added: " + obj.getId() + " - " + obj.getName());
StateManager.getInstance().getConfigurationManager().setSpellsChanged(true);
} catch (CoreStateInitException e) {
}
}
use of com.solinia.solinia.Models.SoliniaSpell in project solinia3-core by mixxit.
the class JsonSpellRepository method reload.
@Override
public void reload() {
List<ISoliniaSpell> readObj = new ArrayList<ISoliniaSpell>();
Gson gson = new Gson();
File folder = new File(filePath);
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
try {
if (file.isFile() && file.getName().endsWith(".json")) {
BufferedReader br = new BufferedReader(new FileReader(filePath + "/" + file.getName()));
readObj.add(gson.fromJson(br, new TypeToken<SoliniaSpell>() {
}.getType()));
br.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
spells.clear();
for (ISoliniaSpell i : readObj) {
spells.put(i.getId(), i);
}
System.out.println("Reloaded " + spells.size() + " spells");
}
Aggregations