-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectLib.java
More file actions
186 lines (163 loc) · 5.3 KB
/
ConnectLib.java
File metadata and controls
186 lines (163 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package fr.sandro642.github;
import fr.sandro642.github.enums.LangType;
import fr.sandro642.github.enums.ResourceType;
import fr.sandro642.github.enums.lang.CategoriesType;
import fr.sandro642.github.hook.HookManager;
import fr.sandro642.github.hook.LangSupport;
import fr.sandro642.github.hook.MCSupport;
import fr.sandro642.github.jobs.JobGetInfos;
import fr.sandro642.github.misc.*;
import fr.sandro642.github.update.RetrieveLastVersion;
import java.util.HashMap;
import java.util.Map;
/**
* ConnectLib is the main class of the ConnectorAPI library for Standard API.
* It provides methods to initialize the library with resource types, routes, and schemas,
*
* @author Sandro642
* @version 1.0
* @see ConnectLib#JobGetInfos()
* @see ConnectLib#Logger()
* @see ConnectLib#StoreAndRetrieve()
* @see ConnectLib#YamlUtils()
* @see ConnectLib#MCSupport()
* @see ConnectLib#HookManager()
* @see ConnectLib#LangSupport()
* @see ConnectLib#LangManager()
*/
public class ConnectLib {
private static Logger logger = new Logger();
private static StoreAndRetrieve storeAndRetrieve = new StoreAndRetrieve();
private static YamlUtils yamlUtils = new YamlUtils();
private static final Map<String, String> routes = new HashMap<>();
private static Logs logs = new Logs();
private static LangManager langManager;
private static RetrieveLastVersion rlv;
/**
* Init the ConnectLib with the specified resource type and routes.
*
* @param resourceType the type of resource to initialize
* @param routes the routes to be used in the ConnectLib
*/
public void Init(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
try {
logger = new Logger();
storeAndRetrieve = new StoreAndRetrieve();
yamlUtils = new YamlUtils();
logs = new Logs();
rlv = new RetrieveLastVersion();
rlv.isLatestVersion();
HookManager().initHook(resourceType);
LangSupport().setLangTypeVariable(langType);
HookManager().FILE_LOCATION_KEY();
langManager = new LangManager();
Map<Enum<?>, String> routesEnums = new HashMap<>();
for (Class<? extends Enum<?>> route : routes) {
if (route == null) {
Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "initialise.routeclass"));
continue;
}
routesEnums.putAll(EnumLoader.convertRouteImport(route));
}
yamlUtils.generateTemplateIfNotExists(routesEnums);
logs.setPathFile();
String baseUrl = yamlUtils.getURL();
if (baseUrl != null) {
storeAndRetrieve.store.put(storeAndRetrieve.URL_KEY, baseUrl);
}
Map<String, String> yamlRoutes = yamlUtils.getRoutes();
if (yamlRoutes != null) {
ConnectLib.routes.putAll(yamlRoutes);
}
} catch (Exception e) {
Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "initialise.catcherror", Map.of("exception", e.getMessage())));
}
}
/**
* Return the route associated with the given route name.
*
* @param routeName the name of the route to retrieve
* @return the route as a String
*/
public String getRoute(String routeName) {
if (routes.containsKey(routeName)) {
return routes.get(routeName);
} else {
Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "getroute.error", Map.of("route", routeName)));
return null;
}
}
/**
* Return an instance of JobGetInfos.
*
* @return JobGetInfos instance
*/
public JobGetInfos JobGetInfos() {
return new JobGetInfos();
}
/**
* Return the instance of Logger.
*
* @return Logger instance
*/
public Logger Logger() {
if (logger == null) {
logger = new Logger();
}
return logger;
}
/**
* Return the instance of StoreAndRetrieve.
*
* @return StoreAndRetrieve instance
*/
public StoreAndRetrieve StoreAndRetrieve() {
if (storeAndRetrieve == null) {
storeAndRetrieve = new StoreAndRetrieve();
}
return storeAndRetrieve;
}
/**
* Return the instance of YamlUtils.
*
* @return YamlUtils instance
*/
public YamlUtils YamlUtils() {
if (yamlUtils == null) {
yamlUtils = new YamlUtils();
}
return yamlUtils;
}
/**
* Return the instance of Logs.
*
* @return Logs instance
*/
public MCSupport MCSupport() {
return MCSupport.getInstance();
}
/**
* Return the instance of HookManager.
*
* @return HookManager instance
*/
public HookManager HookManager() {
return HookManager.getInstance();
}
/**
* Return the instance of LangSupport.
*
* @return LangSupport instance
*/
public LangSupport LangSupport() {
return LangSupport.getInstance();
}
/**
* Return the instance of LangManager.
*
* @return LangManager instance
*/
public LangManager LangManager() {
return langManager;
}
}