Facebook
From Small Capybara, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 146
  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 JSONObject json = new JSONObject();
  26.         public Map<Location, ForTriple> map = new HashMap<>();
  27.         public final Gson gson = new GsonBuilder().setPrettyPrinting().create();
  28.         private File configFile;
  29.        
  30.         @SuppressWarnings("unchecked")
  31.         @Override
  32.         public void onEnable() {
  33.                 configFile = new File(getDataFolder(), "database.json");
  34.                 if (!configFile.exists()) saveResource(configFile.getName(), false);
  35.                 try {
  36.                         map = gson.fromJson(new FileReader(configFile), new HashMap<Location, ForTriple>().getClass());
  37.                 } catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) {
  38.                         e.printStackTrace();
  39.                 }
  40.                 Bukkit.getPluginManager().registerEvents(new PlaceOreBreakSP(this), this);
  41.                 Bukkit.getPluginManager().registerEvents(new BreakOreBreakSP(this), this);
  42.         }
  43.        
  44.         @Override
  45.         public void onDisable() {
  46.                 final String json = gson.toJson(map);
  47.                 configFile.delete();
  48.                 Files.write(configFile.toPath(), json.getBytes());
  49.         }
  50. }
  51.