ScriptsLab
WikiDownloadsSourcesSupport
ScriptsLab
DocumentationDownloadsGitHubDiscord

© 2026 ScriptsLab

Back to src/main/java/com/scriptslab/api/module
J

Module.java

Java · 110 lines · 2.5 KB

src/main/java/com/scriptslab/api/module/Module.java
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
package com.scriptslab.api.module;

import org.bukkit.configuration.file.FileConfiguration;

import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;

/**
 * Base interface for all modules in the plugin system.
 * Modules are self-contained units of functionality that can be
 * loaded, enabled, disabled, and reloaded independently.
 * 
 * Thread-safety: Implementations must be thread-safe.
 */
public interface Module {
    
    /**
     * Gets the unique identifier of this module.
     * Must be lowercase, alphanumeric with underscores only.
     * 
     * @return module identifier
     */
    String getId();
    
    /**
     * Gets the human-readable name of this module.
     * 
     * @return module name
     */
    String getName();
    
    /**
     * Gets the module version.
     * 
     * @return version string
     */
    String getVersion();
    
    /**
     * Gets the module descriptor containing metadata.
     * 
     * @return module descriptor
     */
    ModuleDescriptor getDescriptor();
    
    /**
     * Gets the module's data folder.
     * 
     * @return path to module data folder
     */
    Path getDataFolder();
    
    /**
     * Gets the module's configuration.
     * 
     * @return configuration file
     */
    FileConfiguration getConfig();
    
    /**
     * Checks if the module is currently enabled.
     * 
     * @return true if enabled
     */
    boolean isEnabled();
    
    /**
     * Called when the module is loaded (before enable).
     * Use this for initialization that doesn't require other modules.
     * 
     * @return future that completes when loading is done
     */
    CompletableFuture<Void> onLoad();
    
    /**
     * Called when the module is enabled.
     * Register listeners, commands, items here.
     * 
     * @return future that completes when enabling is done
     */
    CompletableFuture<Void> onEnable();
    
    /**
     * Called when the module is disabled.
     * Clean up resources, unregister everything.
     * 
     * @return future that completes when disabling is done
     */
    CompletableFuture<Void> onDisable();
    
    /**
     * Called when the module is reloaded.
     * Default implementation: disable then enable.
     * 
     * @return future that completes when reloading is done
     */
    default CompletableFuture<Void> onReload() {
        return onDisable().thenCompose(v -> onEnable());
    }
    
    /**
     * Gets the module's logger name.
     * 
     * @return logger name
     */
    default String getLoggerName() {
        return "Module:" + getId();
    }
}