Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.configuration.serialization.ConfigurationSerialization;
- @SuppressWarnings("unchecked")
- @Override
- public void onEnable(){
- File f = new File(this.getDataFolder() + "/database/" + "data.hashmap");
- map = HashBiMap.create();
- if(!f.exists()){
- System.out.println("Hashmap not found, creating a new one");
- map = HashBiMap.create();
- }else{
- try{
- System.out.println("Hashmap found, loading...");
- FileInputStream fileIn = new FileInputStream(this.getDataFolder() + "/database/" + "data.hashmap");
- ObjectInputStream in = new ObjectInputStream(fileIn);
- Map<String, Object> inMap = in.readObject();
- for (Map.Entry<String, Object> entry : inMap.entrySet()) {
- BlockVector bvec = (BlockVector) ConfigurationSerialization.deserializeObject(entry.getValue());
- map.put(entry.getKey(), bvec);
- }
- in.close();
- fileIn.close();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- getServer().getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable(){
- Map<String, Object> outMap = new HashMap<String, Object>();
- for (Map.Entry<String, BlockVector> entry : map.entrySet()) {
- Map<String, Object> ser = entry.getValue().serialize();
- ser.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, "BlockVector");
- outMap.put(entry.getKey(), ser);
- }
- try{
- System.out.println("Saving hashmap...");
- FileOutputStream fileOut = new
- FileOutputStream(this.getDataFolder() + "/database/" +
- "data.hashmap");
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
- out.writeObject(outMap);
- out.flush();
- out.close();
- fileOut.flush();
- fileOut.close();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement