Advertisement
Camer047

Untitled

Jan 13th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1.  
  2. public void writetodisk()
  3. {
  4. try
  5. {
  6. FileOutputStream fileOut =
  7. new FileOutputStream("plugins/coindata.txt");
  8. ObjectOutputStream out = new ObjectOutputStream(fileOut);
  9. out.writeObject(map);
  10. out.close();
  11. fileOut.close();
  12. System.out.printf("Serialized data is saved in data.txt");
  13. }catch(IOException i)
  14. {
  15. i.printStackTrace();
  16. }
  17. }
  18.  
  19. @SuppressWarnings("unchecked")
  20. public void readfromdisk () {
  21. try
  22. {
  23. FileInputStream fileIn =
  24. new FileInputStream("plugins/coindata.txt");
  25. ObjectInputStream in = new ObjectInputStream(fileIn);
  26. map = (HashMap<UUID, Integer>) in.readObject();
  27. in.close();
  28. fileIn.close();
  29. System.out.printf("Serialized data is saved in data.txt");
  30. }catch(IOException i)
  31. {
  32. i.printStackTrace();
  33. }
  34. catch(ClassNotFoundException c)
  35. {
  36. System.out.println("Class not found");
  37. c.printStackTrace();
  38. }
  39.  
  40.  
  41. }
  42.  
  43. public void giveCoins(UUID uuid, Integer amount, Player player)
  44. {
  45.  
  46. if (map.containsKey(uuid)) {
  47. player.sendMessage("Success!");
  48. int tempcoins = map.get(uuid);
  49. int finalcoins = tempcoins + amount;
  50. map.put(uuid, finalcoins);
  51. }
  52.  
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement