/
BukkitConfiguration.java
128 lines (102 loc) · 5.82 KB
/
BukkitConfiguration.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* CraftBook Copyright (C) EngineHub and Contributors <https://enginehub.org/>
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*/
package org.enginehub.craftbook.bukkit;
import com.sk89q.util.yaml.YAMLProcessor;
import org.enginehub.craftbook.CraftBook;
import org.enginehub.craftbook.YamlConfiguration;
import org.enginehub.craftbook.mechanic.MechanicType;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Comparator;
public class BukkitConfiguration extends YamlConfiguration {
public BukkitConfiguration(YAMLProcessor config) {
super(config);
}
@Override
public void load() {
try {
config.load();
} catch (IOException e) {
CraftBook.LOGGER.error("Error loading CraftBook configuration", e);
e.printStackTrace();
}
if (config.getList("enabled-mechanics") != null) {
try {
Files.move(
CraftBook.getInstance().getPlatform().getWorkingDirectory().resolve("config.yml"),
CraftBook.getInstance().getPlatform().getWorkingDirectory().resolve("config.yml.old")
);
CraftBookPlugin.inst().createDefaultConfiguration("config.yml");
config.load();
} catch (IOException e) {
e.printStackTrace();
}
}
config.setWriteDefaults(true);
config.setHeader(
"# CraftBook Configuration for Bukkit.",
"# This configuration will automatically add new configuration options for you,",
"# So there is no need to regenerate this configuration unless you want to.",
"# More information about these features are available at:",
"# " + CraftBook.getDocsDomain() + "mechanics/",
"#",
"# NOTE! NOTHING IS ENABLED BY DEFAULT! ENABLE FEATURES TO USE THEM!",
"");
enabledMechanics = new ArrayList<>();
config.setComment("mechanics", "List of mechanics and whether they are enabled or not");
MechanicType.REGISTRY.values()
.stream()
.sorted(Comparator.comparing((MechanicType<?> t) -> t.getCategory().name()).thenComparing(MechanicType::getId))
.forEach(mechanicType -> {
String path = "mechanics." + mechanicType.getCategory().name().toLowerCase() + "." + mechanicType.getId();
boolean enabled = config.getBoolean(path, mechanicType.getId().equals("variables"));
if (enabled) {
enabledMechanics.add(mechanicType.getId());
}
});
config.setComment("st-think-ticks", "WARNING! Changing this can result in all ST mechanics acting very weirdly, only change this if you know what you are doing!");
stThinkRate = config.getInt("st-think-ticks", 2);
config.setComment("safe-destruction", "Causes many mechanics to require sufficient blocks to function, for example gates, bridges and doors.");
safeDestruction = config.getBoolean("safe-destruction", true);
config.setComment("no-op-permissions", "If on, OP's will not default to have access to everything.");
noOpPermissions = config.getBoolean("no-op-permissions", false);
config.setComment("indirect-redstone", "Allows redstone not directly facing a mechanism to trigger said mechanism.");
indirectRedstone = config.getBoolean("indirect-redstone", false);
config.setComment("obey-worldguard-flags", "Whether WorldGuard flags should be checked when performing CraftBook actions.");
obeyWorldGuard = config.getBoolean("obey-worldguard-flags", true);
config.setComment("obey-plugin-protections", "Whether to obey other plugins attempts to cancel CraftBook actions.");
obeyPluginProtections = config.getBoolean("obey-plugin-protections", true);
config.setComment("sign-click-timeout", "How often in milliseconds players can interact with CraftBook signs.");
signClickTimeout = config.getInt("sign-click-timeout", 500);
config.setComment("debug-mode", "Enable a mode that will print extra debug information to the console.");
debugMode = config.getBoolean("debug-mode", false);
config.setComment("debug-mode-file-logging", "Causes all debug mode output to be logged into a file. This file is reset every startup (And every /cb reload).");
debugLogToFile = config.getBoolean("debug-mode-file-logging", false);
config.setComment("debug-flags", "Enable certain debug types when debug mode is enabled.");
debugFlags = config.getStringList("debug-flags", new ArrayList<>());
config.setComment("show-permission-messages", "Show messages when a player does not have permission to do something.");
showPermissionMessages = config.getBoolean("show-permission-messages", true);
config.save();
}
@Override
public void save() {
for (MechanicType<?> availableMechanic : MechanicType.REGISTRY.values()) {
String path = "mechanics." + availableMechanic.getCategory().name().toLowerCase() + "." + availableMechanic.getId();
config.setProperty(path, enabledMechanics.contains(availableMechanic.getId()));
}
config.save();
}
}