-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathPeripheralsConfig.java
More file actions
296 lines (216 loc) · 15.3 KB
/
PeripheralsConfig.java
File metadata and controls
296 lines (216 loc) · 15.3 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package de.srendi.advancedperipherals.common.configuration;
import de.srendi.advancedperipherals.common.addons.computercraft.operations.SimpleFreeOperation;
import de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation;
import de.srendi.advancedperipherals.common.addons.computercraft.operations.SphereOperation;
import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.config.ModConfig;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@FieldsAreNonnullByDefault
public class PeripheralsConfig implements IAPConfig {
// Player Detector
public final ForgeConfigSpec.IntValue playerDetMaxRange;
public final ForgeConfigSpec.BooleanValue enablePlayerPosFunction;
public final ForgeConfigSpec.BooleanValue morePlayerInformation;
public final ForgeConfigSpec.BooleanValue enablePlayerDetector;
public final ForgeConfigSpec.BooleanValue playerDetMultiDimensional;
public final ForgeConfigSpec.BooleanValue playerSpyRandError;
public final ForgeConfigSpec.IntValue playerSpyRandErrorAmount;
public final ForgeConfigSpec.IntValue playerSpyPreciseMaxRange;
// Energy Detector
public final ForgeConfigSpec.IntValue energyDetectorMaxFlow;
public final ForgeConfigSpec.BooleanValue enableEnergyDetector;
// Fluid Detector
public final ForgeConfigSpec.IntValue fluidDetectorMaxFlow;
public final ForgeConfigSpec.BooleanValue enableFluidDetector;
// Gas Detector
public final ForgeConfigSpec.IntValue gasDetectorMaxFlow;
public final ForgeConfigSpec.BooleanValue enableGasDetector;
// NBT Storage
public final ForgeConfigSpec.IntValue nbtStorageMaxSize;
public final ForgeConfigSpec.BooleanValue enableNBTStorage;
// Chunky turtle
public final ForgeConfigSpec.IntValue chunkLoadValidTime;
public final ForgeConfigSpec.IntValue chunkyTurtleRadius;
public final ForgeConfigSpec.BooleanValue enableChunkyTurtle;
// Chat box
public final ForgeConfigSpec.BooleanValue enableChatBox;
public final ForgeConfigSpec.ConfigValue<String> defaultChatBoxPrefix;
public final ForgeConfigSpec.IntValue chatBoxMaxRange;
public final ForgeConfigSpec.BooleanValue chatBoxMultiDimensional;
public final ForgeConfigSpec.BooleanValue chatBoxPreventRunCommand;
public final ForgeConfigSpec.BooleanValue chatBoxWrapCommand;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> chatBoxBannedCommands;
private List<Predicate<String>> chatBoxCommandFilters = null;
// ME Bridge
public final ForgeConfigSpec.BooleanValue enableMEBridge;
public final ForgeConfigSpec.IntValue meConsumption;
// Rs Bridge
public final ForgeConfigSpec.BooleanValue enableRSBridge;
public final ForgeConfigSpec.IntValue rsConsumption;
// Environment Detector
public final ForgeConfigSpec.BooleanValue enableEnvironmentDetector;
// Smart glasses
public final ForgeConfigSpec.BooleanValue enableSmartGlasses;
// Inventory Manager
public final ForgeConfigSpec.BooleanValue enableInventoryManager;
// Redstone Integrator
public final ForgeConfigSpec.BooleanValue enableRedstoneIntegrator;
// Block reader
public final ForgeConfigSpec.BooleanValue enableBlockReader;
// Geo Scanner
public final ForgeConfigSpec.BooleanValue enableGeoScanner;
// Colony integrator
public final ForgeConfigSpec.BooleanValue enableColonyIntegrator;
// Compass turtle
public final ForgeConfigSpec.BooleanValue enableCompassTurtle;
public final ForgeConfigSpec.IntValue compassAccurePlaceRadius;
public final ForgeConfigSpec.IntValue compassAccurePlaceFreeRadius;
// Distance Detector
public final ForgeConfigSpec.BooleanValue enableDistanceDetector;
public final ForgeConfigSpec.DoubleValue distanceDetectorRange;
public final ForgeConfigSpec.IntValue distanceDetectorUpdateRate;
// Powered Peripherals
public final ForgeConfigSpec.BooleanValue enablePoweredPeripherals;
public final ForgeConfigSpec.BooleanValue disablePocketFuelConsumption;
public final ForgeConfigSpec.IntValue poweredPeripheralMaxEnergyStorage;
private final ForgeConfigSpec configSpec;
// Saddle turtle (it's tamed)
public final ForgeConfigSpec.BooleanValue enableSaddleTurtle;
public final ForgeConfigSpec.BooleanValue allowSaddleTurtleCapturePlayer;
private static final List<String> chatBoxDefaultBannedCommands = Arrays.asList(
"/execute",
"/op",
"/deop",
"/gamemode",
"/gamerule",
"/stop",
"/give",
"/fill",
"/setblock",
"/summon",
"/whitelist",
"^/ban-(?:ip)?\\s*",
"^/pardon-(?:ip)?\\s*",
"^/save-(?:on|off)\\s*"
);
public PeripheralsConfig() {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
builder.comment("Peripherals config").push("Peripherals");
builder.push("Player_Detector");
enablePlayerDetector = builder.comment("Enable the Player Detector or not.").define("enablePlayerDetector", true);
playerDetMaxRange = builder.comment("The max range of the player detector functions. If anyone use a higher range, the detector will use this max range. -1 for unlimited").defineInRange("playerDetMaxRange", -1, -1, Integer.MAX_VALUE);
enablePlayerPosFunction = builder.comment("Activates the \"getPlayerPos\" function of the Player Detector").define("enablePlayerPosFunction", true);
morePlayerInformation = builder.comment("Adds more information to `getPlayerPos` of the Player Detector. Like rotation and dimension").define("morePlayerInformation", true);
playerDetMultiDimensional = builder.comment("If true, the player detector can observe players which aren't in the same dimension as the detector itself. `playerDetMaxRange` needs to be infinite(-1) for it to work.").define("chatBoxMultiDimensional", true);
playerSpyRandError = builder.comment("If true, add random error to `getPlayerPos` player position that varies based on how far the player is from the detector. Prevents getting the exact position of players far from the detector.").define("enablePlayerPosRandomError", false);
playerSpyRandErrorAmount = builder.comment("The maximum amount of error (in blocks) that can be applied to each axis of the player's position.").defineInRange("playerPosRandomErrorAmount", 1000, 0, Integer.MAX_VALUE);
playerSpyPreciseMaxRange = builder.comment("If random error is enabled: this is the maximum range at which an exact player position is returned, before random error starts to be applied.").defineInRange("playerPosPreciseMaxRange", 100, 0, Integer.MAX_VALUE);
pop("Energy_Detector", builder);
enableEnergyDetector = builder.comment("Enable the Energy Detector or not.").define("enableEnergyDetector", true);
energyDetectorMaxFlow = builder.comment("Defines the maximum energy flow of the energy detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
pop("Fluid_Detector", builder);
enableFluidDetector = builder.comment("Enable the Fluid Detector or not.").define("enableFluidDetector", true);
fluidDetectorMaxFlow = builder.comment("Defines the maximum fluid flow of the fluid detector.").defineInRange("energyDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
pop("Gas_Detector", builder);
enableGasDetector = builder.comment("Enable the Gas Detector or not.").define("enableGasDetector", true);
gasDetectorMaxFlow = builder.comment("Defines the maximum gas flow of the gas detector.").defineInRange("gasDetectorMaxFlow", Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
pop("NBT_Storage", builder);
enableNBTStorage = builder.comment("Enable the nbt storage block or not").define("enableNBTStorage", true);
nbtStorageMaxSize = builder.comment("Defines max nbt string length that can be stored in nbt storage").defineInRange("nbtStorageMaxSize", 1048576, 0, Integer.MAX_VALUE);
pop("Chunky_Turtle", builder);
enableChunkyTurtle = builder.comment("Enable the Chunky Turtle or not.").define("enableChunkyTurtle", true);
chunkLoadValidTime = builder.comment("Time in seconds, while loaded chunk can be consider as valid without touch").defineInRange("chunkLoadValidTime", 600, 60, Integer.MAX_VALUE);
chunkyTurtleRadius = builder.comment("Radius in chunks a single chunky turtle will load. The default value (0) only loads the chunk the turtle is in, 1 would also load the 8 surrounding chunks (9 in total) and so on").defineInRange("chunkyTurtleRadius", 0, 0, 16);
pop("Chat_Box", builder);
enableChatBox = builder.comment("Enable the Chat Box or not.").define("enableChatBox", true);
defaultChatBoxPrefix = builder.comment("Defines default chatbox prefix").define("defaultChatBoxPrefix", "AP");
chatBoxMaxRange = builder.comment("Defines the maximal range of the chat box in blocks. -1 for infinite. If the range is not -1, players in other dimensions won't able to receive messages").defineInRange("chatBoxMaxRange", -1, -1, 30000000);
chatBoxMultiDimensional = builder.comment("If true, the chat box is able to send messages to other dimensions than its own").define("chatBoxMultiDimensional", true);
chatBoxPreventRunCommand = builder.comment("If true, the chat box cannot use 'run_command' action").define("chatBoxPreventRunCommand", false);
chatBoxWrapCommand = builder.comment("If true, the chat box will wrap and execute 'run_command' or 'suggest_command' action with zero permission, in order to prevent operators accidently run dangerous commands.").define("chatBoxWrapCommand", true);
chatBoxBannedCommands = builder.comment("These commands below will not be able to send by 'run_command' or 'suggest_command' action. It will match as prefix if starts with '/', other wise use regex pattern").defineList("chatBoxBannedCommands", chatBoxDefaultBannedCommands, (o) -> o instanceof String value && value.length() > 0);
pop("ME_Bridge", builder);
enableMEBridge = builder.comment("Enable the Me Bridge or not.").define("enableMeBridge", true);
meConsumption = builder.comment("Power consumption per tick.").defineInRange("mePowerConsumption", 10, 0, Integer.MAX_VALUE);
pop("RS_Bridge", builder);
enableRSBridge = builder.comment("Enable the Rs Bridge or not.").define("enableRsBridge", true);
rsConsumption = builder.comment("Power consumption per tick.").defineInRange("rsPowerConsumption", 10, 0, Integer.MAX_VALUE);
pop("Environment_Detector", builder);
enableEnvironmentDetector = builder.comment("Enable the Environment Detector or not.").define("enableEnvironmentDetector", true);
pop("AR_Controller", builder);
enableSmartGlasses = builder.comment("Enable the smart glasses or not.").define("enableSmartGlasses", true);
pop("Inventory_Manager", builder);
enableInventoryManager = builder.comment("Enable the inventory manager or not.").define("enableInventoryManager", true);
pop("Redstone_Integrator", builder);
enableRedstoneIntegrator = builder.comment("Enable the redstone integrator or not.").define("enableRedstoneIntegrator", true);
pop("Block_Reader", builder);
enableBlockReader = builder.comment("Enable the block reader or not.").define("enableBlockReader", true);
pop("Geo_Scanner", builder);
enableGeoScanner = builder.comment("Enable the geo scanner or not.").define("enableGeoScanner", true);
pop("Colony_Integrator", builder);
enableColonyIntegrator = builder.comment("Enable the colony integrator or not.").define("enableColonyIntegrator", true);
pop("Compass_Turtle", builder);
enableCompassTurtle = builder.comment("Enable the compass turtle or not.").define("enableCompassTurtle", true);
compassAccurePlaceRadius = builder.comment("The maximum distance the compass can locate accurately with in each axis.").defineInRange("compassAccurePlaceRadius", 3, 0, 8);
compassAccurePlaceFreeRadius = builder.comment("The free distance the compass can locate accurately with in each axis.").defineInRange("compassAccurePlaceFreeRadius", 1, 0, 4);
pop("Distance_Detector", builder);
enableDistanceDetector = builder.comment("Enable the distance detector or not.").define("enableDistanceDetector", true);
distanceDetectorRange = builder.comment("Maximum range of the distance detector").defineInRange("distanceDetectorRange", 64D, 0D, Integer.MAX_VALUE);
distanceDetectorUpdateRate = builder.comment("Defines how often the distance detector updates it's distance if periodically updates are enabled. \n" +
"Periodically updates exists so we do not need to run \"getDistance\" on the main thread which eliminates the 1 tick yield of the lua function").defineInRange("maxUpdateRate", 2, 1, 100);
pop("Powered_Peripherals", builder);
enablePoweredPeripherals = builder.comment("Enable RF storage for peripherals, that could use it").define("enablePoweredPeripherals", false);
poweredPeripheralMaxEnergyStorage = builder.comment("Defines max energy storage in any powered peripheral").defineInRange("poweredPeripheralMaxEnergyStored", 100_000_000, 1_000_000, Integer.MAX_VALUE);
pop("Pocket_Peripherals", builder);
disablePocketFuelConsumption = builder.comment("If true, pockets will have infinite fuel").define("disablePocketFuelConsumption", true);
pop("Saddle_Turtle", builder);
enableSaddleTurtle = builder.comment("Enable saddle turtle").define("enableSaddleTurtle", true);
allowSaddleTurtleCapturePlayer = builder.comment("Allow saddle turtle to capture player").define("allowSaddleTurtleCapturePlayer", true);
pop("Operations", builder);
register(SingleOperation.values(), builder);
register(SphereOperation.values(), builder);
register(SimpleFreeOperation.values(), builder);
builder.pop();
configSpec = builder.build();
}
@Override
public ForgeConfigSpec getConfigSpec() {
return configSpec;
}
@Override
public String getFileName() {
return "peripherals";
}
@Override
public ModConfig.Type getType() {
return ModConfig.Type.COMMON;
}
private List<Predicate<String>> parseChatBoxCommandFilters() {
List<Predicate<String>> filters = new ArrayList<>();
for (final String s : chatBoxBannedCommands.get()) {
String p = s;
if (p.charAt(0) == '/') {
p = p.replaceAll("\\s+", "\\\\s+");
if (p.equals(s)) {
final String prefix = s;
filters.add((v) -> v.startsWith(prefix) && (v.length() == prefix.length() || " \t".indexOf(v.charAt(prefix.length())) != -1));
continue;
}
p = "^" + p + "\\s*";
}
filters.add(Pattern.compile(p).asPredicate());
}
return filters;
}
public List<Predicate<String>> getChatBoxCommandFilters() {
if (chatBoxCommandFilters == null) {
chatBoxCommandFilters = parseChatBoxCommandFilters();
}
return chatBoxCommandFilters;
}
}