Advertisement
Guest User

Untitled

a guest
Jul 8th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public void onEnable(){
  4.  
  5. File f = new File(this.getDataFolder() + "/database/" + "data.hashmap");
  6. map = HashBiMap.create();
  7. if(!f.exists()){
  8. System.out.println("Hashmap not found, creating a new one");
  9. map = HashBiMap.create();
  10. }else{
  11. try{
  12. System.out.println("Hashmap found, loading...");
  13. FileInputStream fileIn = new FileInputStream(this.getDataFolder() + "/database/" + "data.hashmap");
  14. ObjectInputStream in = new ObjectInputStream(fileIn);
  15. map = (HashBiMap<String, BlockVector>) in.readObject();
  16. in.close();
  17. fileIn.close();
  18. }catch (Exception e){
  19. e.printStackTrace();
  20. }
  21. }
  22.  
  23. getServer().getPluginManager().registerEvents(this, this);
  24. }
  25.  
  26. @Override
  27. public void onDisable(){
  28. try{
  29. System.out.println("Saving hashmap...");
  30. FileOutputStream fileOut = new
  31. FileOutputStream(this.getDataFolder() + "/database/" +
  32. "data.hashmap");
  33. ObjectOutputStream out = new ObjectOutputStream(fileOut);
  34. out.writeObject(map);
  35. out.flush();
  36. out.close();
  37. fileOut.flush();
  38. fileOut.close();
  39. }catch (Exception e){
  40. e.printStackTrace();
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement