Search in sources :

Example 1 with SoliniaSpell

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) {
    }
}
Also used : SoliniaSpell(com.solinia.solinia.Models.SoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Gson(com.google.gson.Gson) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 2 with SoliniaSpell

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");
}
Also used : ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) SoliniaSpell(com.solinia.solinia.Models.SoliniaSpell) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

Gson (com.google.gson.Gson)2 SoliniaSpell (com.solinia.solinia.Models.SoliniaSpell)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1