Skip to content

Commit 02a1b92

Browse files
authored
Merge pull request #12 from Sandro642/feature/hook
Feature/hook
2 parents 627d32c + 11c1564 commit 02a1b92

15 files changed

Lines changed: 193 additions & 42 deletions

File tree

.github/workflows/work-jar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ jobs:
9292
git tag -a "${{ steps.extract_version.outputs.version }}" -m "Release version ${{ steps.extract_version.outputs.version }}"
9393
git push origin "${{ steps.extract_version.outputs.version }}"
9494
env:
95-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ plugins {
55
id("maven-publish") // Plugin pour la publication
66
}
77

8+
89
group = "fr.sandro642.github"
9-
version = "0.1.2"
10+
version = "0.1.3.17.1-SNAPSHOT" // Version de votre projet
11+
1012

1113
// Ajoutez cette tâche à votre build.gradle.kts
1214
tasks.register("printVersion") {
@@ -17,6 +19,9 @@ tasks.register("printVersion") {
1719

1820
repositories {
1921
mavenCentral()
22+
23+
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
24+
maven("https://oss.sonatype.org/content/repositories/snapshots/")
2025
}
2126

2227
dependencies {
@@ -28,6 +33,8 @@ dependencies {
2833

2934
implementation("org.openjfx:javafx-controls:21")
3035
implementation("org.openjfx:javafx-fxml:21")
36+
37+
compileOnly("org.spigotmc:spigot-api:1.8-R0.1-SNAPSHOT")
3138
}
3239

3340
javafx {

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ Hook -----------------------|
2121
```
2222
---
2323

24+
Changelog :
25+
26+
```java
27+
- [0.1.3.9-SNAPSHOT] : Ajout de la sérialisation des données pour une compatibilisation parfaite des données avec les HOOK.
28+
```
29+
30+
---
31+
2432
## 🌟 Pourquoi ConnectorAPI ?
2533

2634
Imaginez une API qui ne se contente pas de relier des services, mais qui devient le chef d’orchestre de vos intégrations. ConnectorAPI est conçu pour :

src/main/java/fr/sandro642/github/ConnectorAPI.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package fr.sandro642.github;
22

3+
import fr.sandro642.github.hook.MCSupport;
34
import fr.sandro642.github.jobs.JobGetInfos;
4-
import fr.sandro642.github.jobs.misc.MethodType;
55
import fr.sandro642.github.jobs.misc.ResourceType;
6-
import fr.sandro642.github.jobs.misc.VersionType;
76
import fr.sandro642.github.utils.Logger;
87
import fr.sandro642.github.utils.StoreAndRetrieve;
98
import fr.sandro642.github.utils.YamlUtils;
@@ -37,7 +36,11 @@ public static void initialize(ResourceType resourceType) {
3736
// Génère le template si nécessaire
3837
yamlUtils.generateTemplateIfNotExists(resourceType);
3938

40-
storeAndRetrieve.store.put(storeAndRetrieve.FILE_LOCATION_KEY, resourceType.getPath());
39+
if (resourceType == ResourceType.MC_RESOURCES) {
40+
storeAndRetrieve.store.put(storeAndRetrieve.FILE_LOCATION_KEY, MCSupport().getPluginPath());
41+
} else {
42+
storeAndRetrieve.store.put(storeAndRetrieve.FILE_LOCATION_KEY, resourceType.getPath());
43+
}
4144

4245
// Charge l'URL depuis le fichier YAML
4346
String baseUrl = yamlUtils.getURL();
@@ -82,4 +85,12 @@ public static YamlUtils YamlUtils() {
8285
}
8386
return yamlUtils;
8487
}
88+
89+
/**
90+
* Retourne une instance de MCSupport si le projet est un projet Minecraft
91+
* @return MCSupport ou null si ce n'est pas un projet Minecraft
92+
*/
93+
public static MCSupport MCSupport() {
94+
return MCSupport.getInstance();
95+
}
8596
}

src/main/java/fr/sandro642/github/api/ApiClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.sandro642.github.api;
22

33
import fr.sandro642.github.ConnectorAPI;
4-
import fr.sandro642.github.jobs.misc.ResourceType;
54
import fr.sandro642.github.utils.Logger;
65
import org.springframework.core.ParameterizedTypeReference;
76
import org.springframework.web.reactive.function.client.WebClient;
@@ -29,12 +28,12 @@ public class ApiClient {
2928

3029
/**
3130
* Constructeur de ApiClient qui initialise WebClient avec l'URL de base.
32-
* @param resourceType Type de ressource (peut être utilisé pour des configurations spécifiques).
3331
*/
34-
public ApiClient(ResourceType resourceType) {
32+
public ApiClient() {
3533
String baseUrl = (String) ConnectorAPI.StoreAndRetrieve().store.get(ConnectorAPI.StoreAndRetrieve().URL_KEY);
34+
3635
if (baseUrl == null) {
37-
throw new RuntimeException("URL de base non trouvée. Assurez-vous d'avoir initialisé ConnectorAPI.");
36+
throw new RuntimeException("URL de base non trouvée. Assurez-vous d'avoir initialisé ConnectorAPI. ");
3837
}
3938

4039
this.webClient = WebClient.builder()

src/main/java/fr/sandro642/github/api/ApiResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ public String display() {
250250
", msg='" + msg + '\'' +
251251
", code=" + code +
252252
", data=" + data +
253-
", extra=" + extra +
254253
'}';
255254
}
256255
}

src/main/java/fr/sandro642/github/example/ExampleUsage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import fr.sandro642.github.jobs.misc.ResourceType;
77
import fr.sandro642.github.jobs.misc.VersionType;
88

9+
import java.util.Arrays;
910
import java.util.HashMap;
11+
import java.util.List;
1012
import java.util.Map;
1113

1214
/**
@@ -132,7 +134,7 @@ public static void main(String[] args) {
132134
complexBody.put("nestedObject", subObject);
133135

134136
// Array
135-
java.util.List<String> arrayValue = java.util.Arrays.asList("item1", "item2", "item3");
137+
List<String> arrayValue = Arrays.asList("item1", "item2", "item3");
136138
complexBody.put("arrayValue", arrayValue);
137139

138140
ApiResponse<Void> complexResponse = ConnectorAPI.JobGetInfos()
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package fr.sandro642.github.hook;
2+
3+
import org.bukkit.plugin.Plugin;
4+
5+
/**
6+
* MCSupport est une classe utilitaire pour gérer les hooks liés à Minecraft.
7+
* Elle permet de vérifier si le projet est un projet Minecraft et de gérer les ressources associées.
8+
* @author Sandro642
9+
* @version 1.0
10+
*/
11+
public class MCSupport {
12+
13+
/**
14+
* Création de l'instance unique de MCSupport.
15+
*/
16+
private static MCSupport instance;
17+
18+
/**
19+
* Instance unique du plugin Minecraft.
20+
* Utilisée pour stocker la variable du plugin Minecraft.
21+
*/
22+
private Plugin pluginSingleton;
23+
24+
/**
25+
* Constructeur privé pour empêcher l'instanciation directe.
26+
*/
27+
private MCSupport() {
28+
// Constructeur privé pour le pattern Singleton
29+
}
30+
31+
/**
32+
* Méthode permettant de vérifier si le projet est un projet Minecraft.
33+
* Elle vérifie si le chemin du fichier de configuration contient le chemin des ressources Minecraft.
34+
*
35+
* @return true si c'est un projet Minecraft, false sinon.
36+
*/
37+
public boolean isMCProject() {
38+
try {
39+
40+
String fileLocation = (String) fr.sandro642.github.ConnectorAPI.StoreAndRetrieve().store.get(fr.sandro642.github.ConnectorAPI.StoreAndRetrieve().FILE_LOCATION_KEY);
41+
return fileLocation != null && fileLocation.contains(fr.sandro642.github.jobs.misc.ResourceType.MC_RESOURCES.getPath());
42+
} catch (Exception e) {
43+
// En cas d'erreur, considérer que ce n'est pas un projet MC
44+
return false;
45+
}
46+
}
47+
48+
/**
49+
* Méthode permettant de définir la variable du plugin Minecraft.
50+
* Elle doit être appelée dans un projet Minecraft pour initialiser le plugin.
51+
*
52+
* @param plugin Le plugin Minecraft à définir.
53+
* @return L'instance du plugin définie.
54+
* @throws IllegalStateException Si la méthode n'est pas appelée dans un projet Minecraft.
55+
* @throws IllegalArgumentException Si le plugin fourni est null.
56+
*/
57+
public Plugin setPluginVariable(Plugin plugin) {
58+
if (plugin == null) {
59+
throw new IllegalArgumentException("Plugin cannot be null.");
60+
}
61+
this.pluginSingleton = plugin;
62+
return this.pluginSingleton;
63+
}
64+
65+
/**
66+
* Méthode permettant d'obtenir le chemin du path du plugin Minecraft.
67+
* Elle doit être appelée dans un projet Minecraft pour récupérer le chemin du dossier de données du plugin.
68+
*
69+
* @return Le chemin du dossier de données du plugin.
70+
* @throws IllegalStateException Si la méthode n'est pas appelée dans un projet Minecraft ou si le plugin n'est pas initialisé.
71+
*/
72+
public String getPluginPath() {
73+
74+
if (pluginSingleton == null) {
75+
throw new IllegalStateException("Plugin variable is not set. Please call setPluginVariable first.");
76+
}
77+
78+
return pluginSingleton.getDataFolder().getAbsolutePath();
79+
}
80+
81+
/**
82+
* Méthode permettant de vérifier si le plugin est initialisé.
83+
*
84+
* @return true si le plugin est initialisé, false sinon.
85+
*/
86+
public boolean isPluginInitialized() {
87+
return pluginSingleton != null;
88+
}
89+
90+
/**
91+
* Méthode permettant d'obtenir l'instance du plugin (si initialisé).
92+
*
93+
* @return L'instance du plugin ou null si non initialisé.
94+
*/
95+
public Plugin getPlugin() {
96+
return pluginSingleton;
97+
}
98+
99+
/**
100+
* Méthode permettant de réinitialiser l'instance du plugin.
101+
* Utile pour les tests ou le rechargement.
102+
*/
103+
public void resetPlugin() {
104+
this.pluginSingleton = null;
105+
}
106+
107+
/**
108+
* Méthode permettant d'obtenir l'instance unique de MCSupport.
109+
*
110+
* @return L'instance unique de MCSupport.
111+
*/
112+
public static MCSupport getInstance() {
113+
if (instance == null) {
114+
synchronized (MCSupport.class) {
115+
if (instance == null) {
116+
instance = new MCSupport();
117+
}
118+
}
119+
}
120+
return instance;
121+
}
122+
}

src/main/java/fr/sandro642/github/jobs/JobGetInfos.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import fr.sandro642.github.api.ApiClient;
55
import fr.sandro642.github.api.ApiResponse;
66
import fr.sandro642.github.jobs.misc.MethodType;
7-
import fr.sandro642.github.jobs.misc.ResourceType;
87
import fr.sandro642.github.jobs.misc.VersionType;
98
import fr.sandro642.github.utils.YamlUtils;
109

@@ -25,15 +24,14 @@ public class JobGetInfos {
2524
* ApiClient est utilisé pour effectuer les requêtes HTTP vers l'API.
2625
* YamlUtils est utilisé pour lire les routes depuis le fichier YAML.
2726
*/
28-
private ApiClient apiClient;
29-
private YamlUtils yamlUtils;
27+
private final ApiClient apiClient;
28+
private final YamlUtils yamlUtils;
3029

3130
/**
3231
* Constructeur de JobGetInfos qui initialise ApiClient et YamlUtils.
33-
* Utilise ResourceType.MAIN_RESOURCES pour le type de ressource par défaut.
3432
*/
3533
public JobGetInfos() {
36-
this.apiClient = new ApiClient(ResourceType.MAIN_RESOURCES);
34+
this.apiClient = new ApiClient();
3735
this.yamlUtils = ConnectorAPI.YamlUtils();
3836
}
3937

@@ -135,7 +133,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Str
135133
String paramKey = "{" + entry.getKey() + "}";
136134
String paramValue = entry.getValue().toString();
137135

138-
// Remplace tous les occurrences du paramètre dans la route
136+
// Remplace toutes les occurrences du paramètre dans la route
139137
fullRoute = fullRoute.replace(paramKey, paramValue);
140138
}
141139
}
@@ -169,6 +167,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Str
169167
*/
170168
public ApiResponse<Void> getResponse() {
171169
try {
170+
172171
String route = (String) ConnectorAPI.StoreAndRetrieve().store.get("currentRoute");
173172
MethodType method = (MethodType) ConnectorAPI.StoreAndRetrieve().store.get("currentMethod");
174173
Map<String, Object> body = (Map<String, Object>) ConnectorAPI.StoreAndRetrieve().store.get("currentBody");

0 commit comments

Comments
 (0)