Search in sources :

Example 6 with SoliniaZone

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

the class JsonZoneRepository method reload.

@Override
public void reload() {
    List<SoliniaZone> file = new ArrayList<SoliniaZone>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaZone>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Zones.clear();
    for (SoliniaZone i : file) {
        Zones.put(i.getId(), i);
    }
    System.out.println("Reloaded " + Zones.size() + " Zones");
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) SoliniaZone(com.solinia.solinia.Models.SoliniaZone)

Example 7 with SoliniaZone

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

the class JsonZoneRepository method commit.

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

Aggregations

SoliniaZone (com.solinia.solinia.Models.SoliniaZone)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 Gson (com.google.gson.Gson)2 SoliniaZoneCreationException (com.solinia.solinia.Exceptions.SoliniaZoneCreationException)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 CommandSender (org.bukkit.command.CommandSender)2 Player (org.bukkit.entity.Player)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 InvalidZoneSettingException (com.solinia.solinia.Exceptions.InvalidZoneSettingException)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 List (java.util.List)1 EventException (org.bukkit.event.EventException)1