11package fr .sandro642 .github ;
22
3+ import fr .sandro642 .github .enums .LangType ;
34import fr .sandro642 .github .hook .HookManager ;
5+ import fr .sandro642 .github .hook .LangSupport ;
46import fr .sandro642 .github .hook .MCSupport ;
57import fr .sandro642 .github .misc .*;
68import 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}
0 commit comments