ScriptsLab
WikiDownloadsSourcesSupport
ScriptsLab
DocumentationDownloadsGitHubDiscord

© 2026 ScriptsLab

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

ModuleDescriptor.java

Java · 82 lines · 2.1 KB

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

import java.util.List;
import java.util.Set;

/**
 * Immutable descriptor containing module metadata.
 * Loaded from module.yml.
 */
public record ModuleDescriptor(
    String id,
    String name,
    String version,
    String description,
    List<String> authors,
    Set<String> dependencies,
    Set<String> softDependencies,
    LoadOrder loadOrder,
    boolean enabled
) {
    
    /**
     * Load order for modules.
     */
    public enum LoadOrder {
        STARTUP,  // Load at plugin startup
        POSTWORLD, // Load after worlds are loaded
        LAZY      // Load on demand
    }
    
    /**
     * Validates the descriptor.
     * 
     * @throws IllegalArgumentException if invalid
     */
    public void validate() {
        if (id == null || id.isBlank()) {
            throw new IllegalArgumentException("Module ID cannot be null or blank");
        }
        if (!id.matches("[a-z0-9_]+")) {
            throw new IllegalArgumentException("Module ID must be lowercase alphanumeric with underscores");
        }
        if (name == null || name.isBlank()) {
            throw new IllegalArgumentException("Module name cannot be null or blank");
        }
        if (version == null || version.isBlank()) {
            throw new IllegalArgumentException("Module version cannot be null or blank");
        }
    }
    
    /**
     * Checks if this module depends on another module.
     * 
     * @param moduleId module to check
     * @return true if depends on it
     */
    public boolean dependsOn(String moduleId) {
        return dependencies.contains(moduleId);
    }
    
    /**
     * Checks if this module soft-depends on another module.
     * 
     * @param moduleId module to check
     * @return true if soft-depends on it
     */
    public boolean softDependsOn(String moduleId) {
        return softDependencies.contains(moduleId);
    }
    
    /**
     * Gets all dependencies (hard + soft).
     * 
     * @return all dependencies
     */
    public Set<String> getAllDependencies() {
        var all = new java.util.HashSet<>(dependencies);
        all.addAll(softDependencies);
        return all;
    }
}