11package fr .sandro642 .github .utils ;
22
33import fr .sandro642 .github .ConnectorAPI ;
4+ import org .bukkit .plugin .Plugin ;
45
5- import java .io .FileInputStream ;
6- import java .io .FileOutputStream ;
7- import java .io .ObjectInputStream ;
8- import java .io .ObjectOutputStream ;
6+ import java .io .*;
97import java .util .HashMap ;
108
119/**
@@ -36,9 +34,17 @@ private SerialMap() {
3634 * @param map La HashMap à sauvegarder.
3735 * @param fileName Le nom du fichier dans lequel la HashMap sera sauvegardée.
3836 */
39- public void saveData (HashMap <String , Object > map , String fileName ) {
37+ public void saveData (HashMap <String , Object > map , String fileName , Plugin plugin ) {
4038 try {
41- ObjectOutputStream outputStream = new ObjectOutputStream (new FileOutputStream (fileName ));
39+ File file ;
40+
41+ if (plugin != null ) {
42+ file = new File (plugin .getDataFolder () + fileName );
43+ } else {
44+ file = new File (fileName );
45+ }
46+
47+ ObjectOutputStream outputStream = new ObjectOutputStream (new FileOutputStream (file ));
4248 outputStream .writeObject (map );
4349 outputStream .close ();
4450 //ConnectorAPI.Logger().INFO("✓ Sauvegarde réussie dans " + fileName);
@@ -47,15 +53,27 @@ public void saveData(HashMap<String, Object> map, String fileName) {
4753 }
4854 }
4955
56+ public void saveData (HashMap <String , Object > map , String FileName ) {
57+ saveData (map , FileName , null );
58+ }
59+
5060 /**
5161 * Méthode pour charger une HashMap depuis un fichier.
5262 *
5363 * @param fileName Le nom du fichier à partir duquel la HashMap sera chargée.
5464 * @return La HashMap chargée, ou une nouvelle HashMap vide en cas d'erreur.
5565 */
56- public HashMap <String , Object > loadData (String fileName ) {
66+ public HashMap <String , Object > loadData (String fileName , Plugin plugin ) {
5767 try {
58- ObjectInputStream inputStream = new ObjectInputStream (new FileInputStream (fileName ));
68+ File file ;
69+
70+ if (plugin != null ) {
71+ file = new File (plugin .getDataFolder () + fileName );
72+ } else {
73+ file = new File (fileName );
74+ }
75+
76+ ObjectInputStream inputStream = new ObjectInputStream (new FileInputStream (file ));
5977 HashMap <String , Object > data = (HashMap <String , Object >) inputStream .readObject ();
6078 inputStream .close ();
6179 //ConnectorAPI.Logger().INFO("✓ Chargement réussi depuis " + fileName);
@@ -67,6 +85,10 @@ public HashMap<String, Object> loadData(String fileName) {
6785 }
6886 }
6987
88+ public HashMap <String , Object > loadData (String fileName ) {
89+ return loadData (fileName , null );
90+ }
91+
7092 /**
7193 * Méthode pour obtenir l'instance unique de serialMap.
7294 *
0 commit comments