-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
ConfigHeads.java
64 lines (54 loc) · 2.81 KB
/
ConfigHeads.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
package io.github.thatsmusic99.headsplus.config;
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import io.github.thatsmusic99.headsplus.HeadsPlus;
import io.github.thatsmusic99.headsplus.config.customheads.ConfigCustomHeads;
import io.github.thatsmusic99.headsplus.config.defaults.HeadsXEnums;
import io.github.thatsmusic99.headsplus.managers.HeadManager;
import org.bukkit.ChatColor;
public class ConfigHeads extends HPConfig {
private static ConfigHeads instance;
public ConfigHeads() throws Exception {
super("heads.yml");
instance = this;
}
@Override
public void addDefaults() {
addComment("This is the config where entirely custom heads can be made, with custom metadata, actions, etc.\n" +
"To reference a custom head, use HP#head_id.\n" +
"If you're looking for mobs.yml instead to change mob drops, please go there :)");
addDefault("update-heads", true, "Whether the plugin should add more heads included with updates.");
addDefault("version", 3.9);
makeSectionLenient("heads");
if (isNew() || getDouble("version") < 3.9) {
if (ConfigCustomHeads.get() != null) return;
for (HeadsXEnums head : HeadsXEnums.values()) {
if (isNew() || head.version > getDouble("version")) {
forceExample("heads." + head.name().toLowerCase() + ".display-name", head.displayName);
forceExample("heads." + head.name().toLowerCase() + ".texture", head.texture);
forceExample("heads.HP#" + head.name().toLowerCase() + ".section", head.section);
} else {
addExample("heads." + head.name().toLowerCase() + ".display-name", head.displayName);
addExample("heads." + head.name().toLowerCase() + ".texture", head.texture);
addExample("heads." + head.name().toLowerCase() + ".section", head.section);
}
}
}
}
@Override
public void postSave() {
for (String head : getConfigSection("heads").getKeys(false)) {
ConfigSection section = getConfigSection("heads." + head);
if (section == null) continue; // why?
HeadManager.HeadInfo headInfo = new HeadManager.HeadInfo()
.withDisplayName(ChatColor.translateAlternateColorCodes('&',
section.getString("display-name", "")))
.withTexture(section.getString("texture", ""));
headInfo.setLore(section.getStringList("lore"));
HeadManager.get().registerHead(head, headInfo);
}
HeadsPlus.get().getLogger().info("Registered " + HeadManager.get().getKeys().size() + " heads.");
}
public static ConfigHeads get() {
return instance;
}
}