Facebook
From Edgy Giraffe, 3 Years ago, written in Java.
This paste is a reply to Untitled from Ample Pig - view diff
Embed
Download Paste or View Raw
Hits: 218
  1. package me.bnjrKemal.org;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.nio.charset.StandardCharsets;
  7. import java.nio.file.StandardOpenOption;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. import org.bukkit.Bukkit;
  12. import org.bukkit.Location;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14. import org.json.simple.JSONObject;
  15. import org.omg.CORBA.Any;
  16.  
  17. import com.google.common.io.Files;
  18. import com.google.gson.Gson;
  19. import com.google.gson.GsonBuilder;
  20. import com.google.gson.JsonIOException;
  21. import com.google.gson.JsonSyntaxException;
  22.  
  23. public class Main extends JavaPlugin{
  24.  
  25.         public Map<Location, ForTriple> map = new HashMap<>();
  26.         public final Gson gson = new GsonBuilder().setPrettyPrinting().create();
  27.         private File configFile;
  28.        
  29.         @SuppressWarnings("unchecked")
  30.         @Override
  31.         public void onEnable() {
  32.                 configFile = new File(getDataFolder(), "database.json");
  33.                 if (!configFile.exists()) saveResource(configFile.getName(), false);
  34.                 try {
  35.                         map = gson.fromJson(new FileReader(configFile), new HashMap<Location, ForTriple>().getClass());
  36.                 } catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) {
  37.                         e.printStackTrace();
  38.                 }
  39.                 Bukkit.getPluginManager().registerEvents(new PlaceOreBreakSP(this), this);
  40.                 Bukkit.getPluginManager().registerEvents(new BreakOreBreakSP(this), this);
  41.         }
  42.        
  43.         @Override
  44.         public void onDisable() {
  45.                 final String json = gson.toJson(map);
  46.                 configFile.delete();
  47.                 Files.write(configFile.toPath(), json.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
  48.         }
  49. }
  50.