1+ package fr .sandro642 .github .hook ;
2+
3+ import fr .sandro642 .github .ConnectLib ;
4+ import fr .sandro642 .github .enums .ResourceType ;
5+ import fr .sandro642 .github .utils .Logger ;
6+
7+ /**
8+ * HookManager is a class that manages hooks for different resource types.
9+ * It allows for the initialization and management of hooks based on the specified resource type.
10+ * @see HookManager#BASE_PATH()
11+ * @see HookManager#FILE_LOCATION_KEY()
12+ * @author Sandro642
13+ * @version 1.0
14+ */
15+
16+ public class HookManager {
17+
18+ /**
19+ * Singleton instance of HookManager.
20+ * This instance is used to manage hooks for different resource types.
21+ */
22+ private static HookManager instance ;
23+
24+ /**
25+ * Logger instance for logging messages.
26+ * This logger is used to log errors and other messages related to the hook management.
27+ */
28+ private static Logger logger = new Logger ();
29+
30+ /**
31+ * Initializes the HookManager with the specified resource type.
32+ *
33+ * @param resourceType the type of resource to initialize the hook for
34+ */
35+ private static ResourceType resourceType ;
36+
37+ /**
38+ * Initializes the hook for the specified resource type.
39+ * * This method sets the resource type for the hook manager and returns the initialized resource type.
40+ *
41+ * @param resourceType
42+ * @return the initialized resource type
43+ */
44+ public ResourceType initHook (ResourceType resourceType ) {
45+ this .resourceType = resourceType ;
46+ return this .resourceType ;
47+ }
48+
49+ /**
50+ * Sets the file location key based on the resource type.
51+ * This method updates the store with the file location key based on the resource type.
52+ * It handles different resource types such as MC_RESOURCES, MAIN_RESOURCES, and TEST_RESOURCES.
53+ */
54+ public void FILE_LOCATION_KEY () {
55+ switch (resourceType ) {
56+ case MC_RESOURCES :
57+ ConnectLib .StoreAndRetrieve ().store .put (ConnectLib .StoreAndRetrieve ().FILE_LOCATION_KEY , ConnectLib .MCSupport ().getPluginPath ());
58+ break ;
59+ case MAIN_RESOURCES , TEST_RESOURCES :
60+ ConnectLib .StoreAndRetrieve ().store .put (ConnectLib .StoreAndRetrieve ().FILE_LOCATION_KEY , resourceType .getPath ());
61+ break ;
62+
63+
64+ default :
65+ logger .CRITICAL ("Unsupported resource type: " + resourceType );
66+ }
67+ }
68+
69+ public String BASE_PATH () {
70+ switch (resourceType ) {
71+ case MC_RESOURCES :
72+ return ConnectLib .MCSupport ().getPluginPath ();
73+
74+ case MAIN_RESOURCES , TEST_RESOURCES :
75+ return resourceType .getPath ();
76+
77+
78+ default :
79+ logger .CRITICAL ("Unsupported resource type: " + resourceType );
80+ throw new IllegalArgumentException ("Unsupported resource type: " + resourceType );
81+ }
82+ }
83+
84+ /**
85+ * Returns the singleton instance of HookManager.
86+ * This method ensures that only one instance of HookManager is created and returned.
87+ *
88+ * @return the singleton instance of HookManager
89+ */
90+ public static HookManager getInstance () {
91+ if (instance == null ) {
92+ instance = new HookManager ();
93+ }
94+ return instance ;
95+ }
96+ }
0 commit comments