package me.bnjrKemal.org; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.nio.charset.StandardCharsets; import java.nio.file.StandardOpenOption; import java.util.HashMap; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.java.JavaPlugin; import org.json.simple.JSONObject; import org.omg.CORBA.Any; import com.google.common.io.Files; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonIOException; import com.google.gson.JsonSyntaxException; public class Main extends JavaPlugin{ public JSONObject json = new JSONObject(); public Map map = new HashMap<>(); public final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private File configFile; @SuppressWarnings("unchecked") @Override public void onEnable() { configFile = new File(getDataFolder(), "database.json"); if (!configFile.exists()) saveResource(configFile.getName(), false); try { map = gson.fromJson(new FileReader(configFile), new HashMap().getClass()); } catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) { e.printStackTrace(); } Bukkit.getPluginManager().registerEvents(new PlaceOreBreakSP(this), this); Bukkit.getPluginManager().registerEvents(new BreakOreBreakSP(this), this); } @Override public void onDisable() { final String json = gson.toJson(map); configFile.delete(); Files.write(configFile.toPath(), json.getBytes()); } }