@@ -16,72 +16,112 @@ import org.bukkit.plugin.java.JavaPlugin
1616import org.jetbrains.annotations.ApiStatus
1717
1818/* *
19- * NDCore is the main plugin class for managing the core functionalities of the plugin.
20- * It extends the `JavaPlugin` class and provides lifecycle management, event registration,
21- * and configuration management for the plugin.
19+ * The NDCore class is a custom implementation of a JavaPlugin for Bukkit/Spigot servers,
20+ * providing core functionalities, event handling, password hashing, and update checks.
21+ * This plugin serves as the central framework for managing player events and utilities
22+ * in the server environment.
2223 */
2324class NDCore : JavaPlugin () {
2425
2526 /* *
26- * Companion object for the NDCore class.
27- * Provides shared functionality, properties, and configuration
28- * management for the NDCore plugin.
27+ * Companion object for the NDCore class, providing utility functions and shared resources.
2928 */
3029 companion object {
3130 /* *
32- * A shared [CoroutineScope] instance backed by a [SupervisorJob].
33- * This scope can be used to launch coroutines that are lifecycle-aware
34- * and tied to the [NDCore] plugin lifecycle.
35- * Coroutines launched in this scope will not be cancelled if one of its child
36- * coroutines fails, due to the behavior of [SupervisorJob].
31+ * A `CoroutineScope` associated with the `SupervisorJob` that manages the execution of coroutines within the scope.
32+ * This scope allows the creation and structured management of coroutines in a way that failures in child coroutines
33+ * do not propagate to sibling coroutines. It is primarily used to handle asynchronous tasks in a controlled lifecycle.
3734 */
3835 val coroutineScope = CoroutineScope (SupervisorJob ())
3936
4037 /* *
41- * A mutex used to synchronize access to shared resources or critical sections
42- * within the application. This prevents race conditions and ensures thread-safe
43- * operations where concurrent access could occur.
38+ * A mutual exclusion lock used to protect shared resources from being accessed by multiple threads concurrently.
39+ *
40+ * This `Mutex` instance ensures that only one coroutine at a time can operate on the protected resource,
41+ * allowing for proper synchronization and avoiding race conditions.
4442 */
4543 val mutex = Mutex ()
4644
45+ /* *
46+ * Instance of the Argon2 password hashing algorithm using the Argon2id variant.
47+ * This variable is utilized for securely hashing passwords with a balance
48+ * of computational effort and resistance to side-channel attacks.
49+ */
4750 private val argon2: Argon2 = Argon2Factory .create(Argon2Factory .Argon2Types .ARGON2id )
4851
52+ /* *
53+ * Hashes the given password using a secure hashing algorithm.
54+ *
55+ * @param password the plain text password to be hashed
56+ * @return the hashed representation of the password
57+ */
4958 fun hashPassword (password : String ): String = hashPassword(password.toCharArray())
59+
60+ /* *
61+ * Hashes a password using the Argon2 algorithm.
62+ *
63+ * @param passwordCharArray The password represented as a character array that will be hashed.
64+ * @return A hashed representation of the input password as a String.
65+ */
5066 fun hashPassword (passwordCharArray : CharArray ): String = argon2.hash(4 , 65536 , 1 , passwordCharArray)
67+
68+ /* *
69+ * Verifies whether the provided password matches the given hash.
70+ *
71+ * @param password the plain text password to verify.
72+ * @param hash the hashed password to compare against.
73+ * @return true if the password matches the hash, false otherwise.
74+ */
5175 fun verifyPassword (password : String , hash : String ): Boolean = verifyPassword(password.toCharArray(), hash)
76+
77+ /* *
78+ * Verifies if the provided password matches the given hash using the Argon2 algorithm.
79+ *
80+ * @param passwordCharArray The password provided as a character array.
81+ * @param hash The hashed value to compare the password against.
82+ * @return True if the password matches the hash, otherwise false.
83+ */
5284 fun verifyPassword (passwordCharArray : CharArray , hash : String ): Boolean = argon2.verify(hash, passwordCharArray)
5385
5486 /* *
55- * Represents the configuration data for the plugin .
56- * This variable is expected to hold the parsed YAML configuration file .
57- * It can be null if the configuration has not been loaded or initialized .
87+ * Represents the YAML configuration used within the NDCore class .
88+ * This variable holds the parsed data from a YAML file, allowing access to configuration settings .
89+ * It is nullable and may be uninitialized. Ensure proper initialization before utilizing its data .
5890 */
5991 var config: YamlConfiguration ? = null
6092
6193 /* *
62- * The prefix used for messages within the plugin. It is retrieved from the configuration file using the key "prefix".
63- * If the value is missing or empty in the configuration, it defaults to "&9&lNelmin &8&l»&r".
94+ * Represents the prefix used within the application, which is retrieved from the configuration or defaults
95+ * to a predefined format if no valid value is provided.
96+ *
97+ * This prefix is used as a marker or identifier in specific parts of the application, often for logging,
98+ * message formatting, or similar purposes.
99+ *
100+ * The default value is set to "&9&lNelmin &8&l»&r" when the configuration does not provide a non-empty value.
64101 */
65102 var prefix: String = config?.getString(" prefix" ).takeIf { ! it.isNullOrEmpty() } ? : " &9&lNelmin &8&l»&r"
66103 }
67104
68105 /* *
69- * Provides access to the server's plugin manager, allowing for registration
70- * and management of plugins and their related operations within the server .
106+ * Provides access to the server's plugin management system, enabling interactions
107+ * with plugins such as loading, enabling, disabling, and retrieving plugin details .
71108 */
72109 val pluginManager = server.pluginManager
73110
74111 /* *
75- * Handles the initialization of the plugin when it is enabled.
76- * Sets up the plugin's instance, logging configuration, and event listeners. Also checks for plugin updates.
112+ * Handles the initialization logic for the plugin when it is enabled in the server.
77113 *
78- * Key functionalities include:
79- * - Setting the singleton instance of the plugin.
80- * - Defining the logger's name to identify logs from the plugin.
81- * - Registering event listeners for managing custom player actions such as freezing and unfreezing.
82- * - Printing log messages to confirm successful plugin loading.
83- * - Initiating a check to verify if the plugin is up-to-date by interacting with a GitHub repository,
84- * and logging relevant information about update availability.
114+ * This method performs the following tasks:
115+ * - Configures the Logger with the appropriate name and coroutine scope.
116+ * - Starts listening for incoming log messages.
117+ * - Registers various event listeners for handling player and menu-related events:
118+ * - `PlayerFreezeListener`: Handles events related to freezing players.
119+ * - `PlayerUnfreezeListener`: Handles events related to unfreezing players.
120+ * - `PlayerJoinListener`: Manages player join-related actions.
121+ * - `PlayerQuitListener`: Manages player quit-related actions.
122+ * - `MenuClickListener`: Handles menu interaction events.
123+ * - Logs the enablement of the plugin.
124+ * - Initiates a version check to determine if a newer version of the plugin is available.
85125 */
86126 @ApiStatus.Experimental
87127 override fun onEnable () {
@@ -105,18 +145,19 @@ class NDCore : JavaPlugin() {
105145 NDUtils .checkForPluginUpdates(
106146 currentVersion = getPlugin(this ::class .java).pluginMeta.version,
107147 callback = { (hasUpdate, updateType, _, currentVersion) ->
108- if (hasUpdate) {
109- Logger .queueWarn(" An update is available for NDCore ($currentVersion -> $updateType )" )
110- } else {
111- Logger .queueInfo(" You are running the latest version of NDCore ($currentVersion )" )
112- }
113- })
148+ if (hasUpdate) {
149+ Logger .queueWarn(" An update is available for NDCore ($currentVersion -> $updateType )" )
150+ } else {
151+ Logger .queueInfo(" You are running the latest version of NDCore ($currentVersion )" )
152+ }
153+ })
114154 }
115155
116156 /* *
117- * Called when the plugin is disabled by the server.
118- * This method is triggered as part of the plugin lifecycle and is commonly used to release
119- * resources, save plugin state, or perform cleanup operations before the plugin fully unloads.
157+ * Called when the plugin is disabled.
158+ *
159+ * This method performs cleanup operations when the plugin is stopped,
160+ * such as logging the plugin's disabled state and stopping the log message listener.
120161 */
121162 override fun onDisable () {
122163 Logger .queueInfo(" Plugin disabled!" )
0 commit comments