Skip to content

Commit 9e1bfd3

Browse files
authored
Merge pull request #38 from Sandro642/feature/lang
Feature/lang
2 parents 8d19662 + 4e3e389 commit 9e1bfd3

18 files changed

Lines changed: 454 additions & 24 deletions

File tree

.idea/copilot.data.migration.agent.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copilot.data.migration.edit.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'fr.sandro642.github'
8-
version = '0.2.9-STABLE'
8+
version = '0.3.0-STABLE'
99

1010
tasks.register('printVersion') {
1111
doLast {
@@ -19,6 +19,7 @@ repositories {
1919
maven {
2020
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
2121
}
22+
2223
maven {
2324
url 'https://oss.sonatype.org/content/repositories/snapshots/'
2425
}
@@ -31,7 +32,8 @@ dependencies {
3132
implementation 'io.projectreactor:reactor-core:3.6.9'
3233
implementation 'org.springframework.boot:spring-boot-starter-webflux:3.2.2'
3334

34-
compileOnly 'org.spigotmc:spigot-api:1.8-R0.1-SNAPSHOT'
35+
// Version moderne sans problèmes de dépendances
36+
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
3537
}
3638

3739
application {
@@ -93,4 +95,4 @@ publishing {
9395
url = uri(layout.buildDirectory.dir('repo'))
9496
}
9597
}
96-
}
98+
}

readme.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ And if you thought APIs were complicated, think again! With ConnectLib, it's lik
1717
---
1818

1919
```java
20-
Stable Version: 0.2.9-STABLE
20+
Stable Version: 0.3.0-STABLE
2121
```
2222

2323
---
@@ -26,11 +26,19 @@ Stable Version: 0.2.9-STABLE
2626
Support Lib : Java 23
2727
2828
Hook -----------------------|
29-
- Support Minecraft 1.8 - Latest Version
29+
- Support Minecraft 1.16 - Latest Version
30+
- Support LangType 0.1.0 - Latest Version
3031
3132
- Coming Soon.
3233
```
3334
---
35+
## LangManager
36+
```
37+
EN : Released - Latest Version
38+
FR : Sorti - Dernière Version
39+
```
40+
41+
---
3442

3543
Stay informed about the latest features and updates of ConnectLib.
3644

@@ -107,7 +115,7 @@ repositories {
107115

108116
dependencies {
109117

110-
implementation("fr.sandro642.github:ConnectLib:0.2.9-STABLE")
118+
implementation("fr.sandro642.github:ConnectLib:0.3.0-STABLE")
111119

112120
}
113121

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

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

3+
import fr.sandro642.github.enums.LangType;
34
import fr.sandro642.github.hook.HookManager;
5+
import fr.sandro642.github.hook.LangSupport;
46
import fr.sandro642.github.hook.MCSupport;
57
import fr.sandro642.github.misc.*;
68
import fr.sandro642.github.jobs.JobGetInfos;
@@ -29,33 +31,36 @@ public class ConnectLib {
2931
private static YamlUtils yamlUtils = new YamlUtils();
3032
private static final Map<String,String> routes = new HashMap<>();
3133
private static Logs logs = new Logs();
34+
private static LangManager langManager;
3235

3336
/**
3437
* Init the ConnectLib with the specified resource type and routes.
3538
* @param resourceType the type of resource to initialize
3639
* @param routes the routes to be used in the ConnectLib
3740
*/
38-
public static void initialize(ResourceType resourceType, Class<? extends Enum<?>>... routes) {
41+
public static void initialize(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
3942
try {
40-
Map<Enum<?>, String> routesEnums = new HashMap<>();
41-
for (Class<? extends Enum<?>> route : routes) {
42-
if (route == null) {
43-
ConnectLib.Logger().ERROR("Route class cannot be null.");
44-
}
45-
46-
routesEnums.putAll(EnumLoader.convertRouteImport(route));
47-
}
48-
4943
logger = new Logger();
5044
storeAndRetrieve = new StoreAndRetrieve();
5145
yamlUtils = new YamlUtils();
5246
logs = new Logs();
5347

5448
HookManager().initHook(resourceType);
49+
LangSupport().setLangTypeVariable(langType);
5550
HookManager().FILE_LOCATION_KEY();
5651

57-
yamlUtils.generateTemplateIfNotExists(routesEnums);
52+
langManager = new LangManager();
53+
54+
Map<Enum<?>, String> routesEnums = new HashMap<>();
55+
for (Class<? extends Enum<?>> route : routes) {
56+
if (route == null) {
57+
ConnectLib.Logger().ERROR(langManager.getMessage("connectlib.class", "initialise.routeclass"));
58+
continue;
59+
}
60+
routesEnums.putAll(EnumLoader.convertRouteImport(route));
61+
}
5862

63+
yamlUtils.generateTemplateIfNotExists(routesEnums);
5964
logs.setPathFile();
6065

6166
String baseUrl = yamlUtils.getURL();
@@ -68,7 +73,7 @@ public static void initialize(ResourceType resourceType, Class<? extends Enum<?>
6873
ConnectLib.routes.putAll(yamlRoutes);
6974
}
7075
} catch (Exception e) {
71-
ConnectLib.Logger().ERROR("Error while initializing ConnectLib: " + e.getMessage());
76+
ConnectLib.Logger().ERROR(langManager.getMessage("connectlib.class", "initialise.catcherror", Map.of("exception", e.getMessage())));
7277
}
7378
}
7479

@@ -81,7 +86,7 @@ public static String getRoute(String routeName) {
8186
if (routes.containsKey(routeName)) {
8287
return routes.get(routeName);
8388
} else {
84-
ConnectLib.Logger().ERROR("Route '" + routeName + "' not found in the ConnectorAPI routes.");
89+
ConnectLib.Logger().ERROR(langManager.getMessage("connectlib.class", "getroute.error", Map.of("route", routeName)));
8590
return null;
8691
}
8792
}
@@ -152,4 +157,21 @@ public static MCSupport MCSupport() {
152157
public static HookManager HookManager() {
153158
return HookManager.getInstance();
154159
}
160+
161+
/**
162+
* Return the instance of LangSupport.
163+
* @return LangSupport instance
164+
*/
165+
public static LangSupport LangSupport() {
166+
return LangSupport.getInstance();
167+
168+
}
169+
170+
/**
171+
* Return the instance of LangManager.
172+
* @return LangManager instance
173+
*/
174+
public static LangManager LangManager() {
175+
return langManager;
176+
}
155177
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package fr.sandro642.github.enums;
2+
3+
/**
4+
* LangType is an enumeration representing different language codes used in the ConnectLib library.
5+
*
6+
* @author Sandro642
7+
* @version 1.0
8+
*/
9+
10+
public enum LangType {
11+
ENGLISH("EN_US"),
12+
FRENCH("FR_EU"),
13+
SPANISH("ES_EU"),
14+
GERMAN("DE_EU"),
15+
ITALIAN("IT_EU"),
16+
PORTUGUESE("PT_EU"),
17+
RUSSIAN("RU_RU");
18+
19+
/**
20+
* Language code.
21+
*/
22+
private final String lang;
23+
24+
/**
25+
* Constructor to initialize the language code.
26+
* @param lang
27+
*/
28+
LangType(String lang) {
29+
this.lang = lang;
30+
}
31+
32+
/**
33+
* Get the language code.
34+
* @return the language code string
35+
*/
36+
public String getLang() {
37+
return lang;
38+
}
39+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import fr.sandro642.github.ConnectLib;
44
import fr.sandro642.github.api.ApiFactory;
5+
import fr.sandro642.github.enums.LangType;
56
import fr.sandro642.github.enums.MethodType;
67
import fr.sandro642.github.enums.ResourceType;
78
import fr.sandro642.github.enums.VersionType;
@@ -40,9 +41,9 @@ public String route() {
4041
public void initializeLib() {
4142

4243
// Optionally, you can specify routes if needed
43-
ConnectLib.initialize(ResourceType.MAIN_RESOURCES, ExampleRoutes.class);
44+
ConnectLib.initialize(ResourceType.MAIN_RESOURCES, LangType.FRENCH, ExampleRoutes.class);
4445
// You can also initialize without specifying routes
45-
ConnectLib.initialize(ResourceType.MAIN_RESOURCES);
46+
ConnectLib.initialize(ResourceType.MAIN_RESOURCES, LangType.FRENCH);
4647
}
4748

4849
// Add methods here to demonstrate how to use the ConnectLib library
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package fr.sandro642.github.hook;
2+
3+
import fr.sandro642.github.ConnectLib;
4+
import fr.sandro642.github.enums.LangType;
5+
6+
/**
7+
* LangSupport is a placeholder class for future language support implementations.
8+
* Currently, it does not contain any methods or properties.
9+
*
10+
* @author Sandro642
11+
* @version 1.0
12+
*/
13+
14+
public class LangSupport {
15+
16+
/**
17+
* Instance of LangSupport.
18+
*/
19+
private static LangSupport instance;
20+
21+
/**
22+
* Prefix for language files.
23+
*/
24+
private final String PREFIX = "lang/";
25+
26+
/**
27+
* Private singleton langType.
28+
* @return langTypeSingleton
29+
*/
30+
private LangType langTypeSingleton;
31+
32+
/**
33+
* Sets the LangType variable for this instance.
34+
* @param langType The language type to set. Must not be null.
35+
* @return The LangType that was set.
36+
*/
37+
public LangType setLangTypeVariable(LangType langType) {
38+
if (langType == null) {
39+
throw new IllegalArgumentException("LangType cannot be null");
40+
}
41+
this.langTypeSingleton = langType;
42+
return this.langTypeSingleton;
43+
}
44+
45+
/**
46+
* Method to get the path of the language file based on the LangType.
47+
* @return The path of the language file.
48+
* @throws IllegalArgumentException If the LangType is null or unsupported.
49+
*/
50+
public String getPathFile() {
51+
if (langTypeSingleton == null) {
52+
throw new IllegalArgumentException("LangType cannot be null");
53+
}
54+
55+
return PREFIX + langTypeSingleton.getLang() + ".lang";
56+
}
57+
58+
/**
59+
* Public Getter of LangSupport instance.
60+
* This method returns the singleton instance of LangSupport.
61+
* If the instance is null, it creates a new instance.
62+
* @return instance
63+
*/
64+
public static LangSupport getInstance() {
65+
if (instance == null) {
66+
instance = new LangSupport();
67+
}
68+
return instance;
69+
}
70+
}

0 commit comments

Comments
 (0)