Search in sources :

Example 11 with JavaPlugin

use of org.bukkit.plugin.java.JavaPlugin in project MyMaid2 by jaoafa.

the class Jail method LoadJailData.

/**
 * Jail情報をロードする。
 * @return 実行できたかどうか
 * @author mine_book000
 * @throws Exception 何かしらのExceptionが発生したときに発生(FileNotFoundException, IOException)
 */
@SuppressWarnings("unchecked")
public static boolean LoadJailData() throws Exception {
    JSONParser parser = new JSONParser();
    String json = "";
    try {
        JavaPlugin plugin = JavaPlugin();
        File file = new File(plugin.getDataFolder(), "jail.json");
        BufferedReader br = new BufferedReader(new FileReader(file));
        String separator = System.getProperty("line.separator");
        String str;
        while ((str = br.readLine()) != null) {
            json += str + separator;
        }
        br.close();
    } catch (FileNotFoundException e1) {
        BugReporter(e1);
        throw new FileNotFoundException(e1.getMessage());
    } catch (IOException e1) {
        BugReporter(e1);
        throw new IOException(e1.getMessage());
    }
    JSONObject obj;
    try {
        obj = (JSONObject) parser.parse(json);
    } catch (ParseException e1) {
        obj = new JSONObject();
    }
    JSONArray JailJSON;
    if (obj.containsKey("Jail")) {
        JailJSON = (JSONArray) obj.get("Jail");
        for (int i = 0; i < JailJSON.size(); i++) {
            String player = (String) JailJSON.get(i);
            Jail.add(player);
        }
    }
    if (obj.containsKey("Block")) {
        for (Entry<String, Boolean> one : (Set<Map.Entry<String, Boolean>>) ((JSONObject) obj.get("Block")).entrySet()) {
            block.put(one.getKey(), one.getValue());
        }
    }
    if (obj.containsKey("Area")) {
        for (Entry<String, Boolean> one : (Set<Map.Entry<String, Boolean>>) ((JSONObject) obj.get("Area")).entrySet()) {
            area.put(one.getKey(), one.getValue());
        }
    }
    if (obj.containsKey("LastText")) {
        for (Entry<String, Boolean> one : (Set<Map.Entry<String, Boolean>>) ((JSONObject) obj.get("LastText")).entrySet()) {
            lasttext.put(one.getKey(), one.getValue());
        }
    }
    return true;
}
Also used : HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) FileNotFoundException(java.io.FileNotFoundException) JSONArray(org.json.simple.JSONArray) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) IOException(java.io.IOException) JSONObject(org.json.simple.JSONObject) BufferedReader(java.io.BufferedReader) JSONParser(org.json.simple.parser.JSONParser) FileReader(java.io.FileReader) ParseException(org.json.simple.parser.ParseException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JavaPlugin (org.bukkit.plugin.java.JavaPlugin)11 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Plugin (org.bukkit.plugin.Plugin)4 JSONArray (org.json.simple.JSONArray)4 ParseException (org.json.simple.parser.ParseException)4 MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)2 MapSession (com.bergerkiller.bukkit.common.map.MapSession)2 Plugin (com.karuslabs.plugin.annotations.annotations.Plugin)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 FileWriter (java.io.FileWriter)2 Map (java.util.Map)2 Player (org.bukkit.entity.Player)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 CommonPlugin (com.bergerkiller.bukkit.common.internal.CommonPlugin)1 LegacyContainerAnvilHook (com.bergerkiller.bukkit.common.internal.hooks.LegacyContainerAnvilHook)1 MapDisplayProperties (com.bergerkiller.bukkit.common.map.MapDisplayProperties)1