-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModuleCommand.java
More file actions
65 lines (50 loc) · 1.81 KB
/
ModuleCommand.java
File metadata and controls
65 lines (50 loc) · 1.81 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
package singularity.command;
import lombok.Getter;
import singularity.Singularity;
import singularity.modules.ModuleLike;
import java.io.File;
@Getter
public abstract class ModuleCommand extends CosmicCommand {
private final ModuleLike owningModule;
public ModuleCommand(ModuleLike module, String base, String permission, String... aliases) {
this(module, base, permission, new File(module.getDataFolder(), Singularity.getCommandsFolderChild()), aliases);
}
public ModuleCommand(ModuleLike module, String base, String permission, File parentDirectory, String... aliases) {
super(module.getIdentifier(), base, permission, parentDirectory, aliases);
this.owningModule = module;
}
// public static String[] withLabel(ModuleLike module, String base, String... before) {
// List<String> names = new ArrayList<>(List.of(before));
// names.add(base);
//
// List<String> newAliases = new ArrayList<>();
// for (String name : names) {
// newAliases.add(name);
// newAliases.add(module.getIdentifier() + ":" + name);
// }
//
// return newAliases.toArray(String[]::new);
// }
public void modulize() {
getOwningModule().addCommand(this);
}
public void demodulize() {
getOwningModule().removeCommand(this);
}
@Override
public void register() {
if (! isEnabled()) return;
CommandHandler.registerModuleCommand(this);
modulize();
}
@Override
public void unregister() {
if (! isEnabled()) if (! CommandHandler.getLoadedModuleCommands().containsKey(getIdentifier())) return;
CommandHandler.unregisterModuleCommand(this);
demodulize();
}
@Override
public void disable() {
CommandHandler.unregisterModuleCommand(this);
}
}