Skip to content

Commit 639ba67

Browse files
committed
Add settings.toml - allow module and block level disable
1 parent eb772b1 commit 639ba67

File tree

7 files changed

+182
-69
lines changed

7 files changed

+182
-69
lines changed

core/src/main/java/org/dynmapblockscan/core/AbstractBlockScanBase.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public abstract class AbstractBlockScanBase {
5959
public static BlockScanLog logger;
6060
public static boolean verboselogging = false;
6161
protected BlockStateOverrides overrides;
62+
public Set<String> disabledModules = new HashSet<String>();
63+
public Set<String> disabledBlockNames = new HashSet<String>();
6264

6365
//private Gson gson = new GsonBuilder().setPrettyPrinting().create();
6466

@@ -143,6 +145,22 @@ private static PathElement findElement(Map<String, PathElement> m, String pth) {
143145
return m.get(tok[tok.length - 1]);
144146
}
145147

148+
public void setDisabledModules(List<String> modules) {
149+
disabledModules.addAll(modules);
150+
}
151+
152+
public void setDisabledBlockNames(List<String> blocknames) {
153+
disabledBlockNames.addAll(blocknames);
154+
}
155+
156+
public boolean isDisabledModule(String modid) {
157+
return disabledModules.contains(modid);
158+
}
159+
160+
public boolean isDisabledBlockName(String blockname) {
161+
return disabledBlockNames.contains(blockname);
162+
}
163+
146164
protected String scanForElement(Map<String, PathElement> m, String base, String fname) {
147165
for (Entry<String, PathElement> me : m.entrySet()) {
148166
PathElement p = me.getValue();
@@ -363,7 +381,7 @@ public void registerSimpleDynmapCubes(String blkname, StateRec state, BlockEleme
363381
String modid = tok[0];
364382
String blknm = tok[1];
365383

366-
if (tok[0].equals("minecraft")) { // Skip vanilla
384+
if (isDisabledModule(modid) || isDisabledBlockName(blkname)) {
367385
return;
368386
}
369387
// Get record for mod
@@ -436,7 +454,7 @@ public void registerModelListModel(String blkname, StateRec state, List<BlockEle
436454
String[] tok = blkname.split(":");
437455
String modid = tok[0];
438456
String blknm = tok[1];
439-
if (tok[0].equals("minecraft")) { // Skip vanilla
457+
if (isDisabledModule(modid) || isDisabledBlockName(blkname)) { // Skip vanilla
440458
return;
441459
}
442460
// Get record for mod
@@ -551,7 +569,7 @@ public void registerDynmapPatches(String blkname, StateRec state, List<BlockElem
551569
String[] tok = blkname.split(":");
552570
String modid = tok[0];
553571
String blknm = tok[1];
554-
if (tok[0].equals("minecraft")) { // Skip vanilla
572+
if (isDisabledModule(modid) || isDisabledBlockName(blkname)) { // Skip vanilla
555573
return;
556574
}
557575
// Get record for mod

forge-1.14.4/src/main/java/org/dynmapblockscan/forge_1_14_4/DynmapBlockScanMod.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package org.dynmapblockscan.forge_1_14_4;
22

33
import java.io.File;
4-
import java.util.Map;
4+
import java.util.Arrays;
5+
import java.util.List;
56

67
import net.minecraft.server.MinecraftServer;
8+
import net.minecraftforge.common.ForgeConfigSpec;
79
import net.minecraftforge.common.MinecraftForge;
810
import net.minecraftforge.eventbus.api.SubscribeEvent;
911
import net.minecraftforge.fml.DistExecutor;
1012
import net.minecraftforge.fml.ModList;
13+
import net.minecraftforge.fml.ModLoadingContext;
1114
import net.minecraftforge.fml.common.Mod;
1215
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
1316
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
1417
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
1518
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
1619
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
20+
import net.minecraftforge.fml.loading.FMLPaths;
21+
import net.minecraftforge.fml.loading.FileUtils;
1722

1823
@Mod("dynmapblockscan")
1924
public class DynmapBlockScanMod
@@ -34,22 +39,34 @@ public DynmapBlockScanMod() {
3439
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
3540

3641
MinecraftForge.EVENT_BUS.register(this);
42+
43+
FileUtils.getOrCreateDirectory(FMLPaths.CONFIGDIR.get().resolve("dynmapblockscan"), "dynmapblockscan");
44+
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, SettingsConfig.SPEC, "dynmapblockscan/settings.toml");
3745
}
3846

47+
public static class SettingsConfig
48+
{
49+
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
50+
public static final ForgeConfigSpec SPEC;
51+
52+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeModules;
53+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeBlockNames;
54+
55+
static
56+
{
57+
BUILDER.comment("DynmapBlockScan settings");
58+
BUILDER.push("settings");
59+
excludeModules = BUILDER.comment("Which modules to exclude").defineList("exclude_modules", Arrays.asList("minecraft"), entry -> true);
60+
excludeBlockNames = BUILDER.comment("Which block names to exclude").defineList("exclude_blocknames", Arrays.asList(), entry -> true);
61+
BUILDER.pop();
62+
63+
SPEC = BUILDER.build();
64+
}
65+
}
66+
3967
public void setup(final FMLCommonSetupEvent event) {
68+
logger.info("setup");
4069
jarfile = ModList.get().getModFileById("dynmapblockscan").getFile().getFilePath().toFile();
41-
42-
// Load configuration file - use suggested (config/DynmapBlockScan.cfg)
43-
// Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
44-
// try {
45-
// cfg.load();
46-
//
47-
// verboselogging = cfg.get("Settings", "verboselog", false).getBoolean(false);
48-
// }
49-
// finally
50-
// {
51-
// cfg.save();
52-
// }
5370
}
5471

5572
private MinecraftServer server;
@@ -59,6 +76,8 @@ public void onServerStarting(FMLServerStartingEvent event) {
5976
server = event.getServer();
6077
if(plugin == null)
6178
plugin = proxy.startServer(server);
79+
plugin.setDisabledModules((List<String>) SettingsConfig.excludeModules.get());
80+
plugin.setDisabledBlockNames((List<String>) SettingsConfig.excludeBlockNames.get());
6281
plugin.serverStarting();
6382
}
6483

forge-1.15.2/src/main/java/org/dynmapblockscan/forge_1_15_2/DynmapBlockScanMod.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package org.dynmapblockscan.forge_1_15_2;
22

33
import java.io.File;
4-
import java.util.Map;
4+
import java.util.Arrays;
5+
import java.util.List;
56

67
import net.minecraft.server.MinecraftServer;
8+
import net.minecraftforge.common.ForgeConfigSpec;
79
import net.minecraftforge.common.MinecraftForge;
810
import net.minecraftforge.eventbus.api.SubscribeEvent;
911
import net.minecraftforge.fml.DistExecutor;
1012
import net.minecraftforge.fml.ModList;
13+
import net.minecraftforge.fml.ModLoadingContext;
1114
import net.minecraftforge.fml.common.Mod;
1215
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
1316
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
1417
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
1518
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
1619
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
20+
import net.minecraftforge.fml.loading.FMLPaths;
21+
import net.minecraftforge.fml.loading.FileUtils;
1722

1823
@Mod("dynmapblockscan")
1924
public class DynmapBlockScanMod
@@ -34,22 +39,34 @@ public DynmapBlockScanMod() {
3439
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
3540

3641
MinecraftForge.EVENT_BUS.register(this);
42+
43+
FileUtils.getOrCreateDirectory(FMLPaths.CONFIGDIR.get().resolve("dynmapblockscan"), "dynmapblockscan");
44+
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, SettingsConfig.SPEC, "dynmapblockscan/settings.toml");
3745
}
3846

47+
public static class SettingsConfig
48+
{
49+
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
50+
public static final ForgeConfigSpec SPEC;
51+
52+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeModules;
53+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeBlockNames;
54+
55+
static
56+
{
57+
BUILDER.comment("DynmapBlockScan settings");
58+
BUILDER.push("settings");
59+
excludeModules = BUILDER.comment("Which modules to exclude").defineList("exclude_modules", Arrays.asList("minecraft"), entry -> true);
60+
excludeBlockNames = BUILDER.comment("Which block names to exclude").defineList("exclude_blocknames", Arrays.asList(), entry -> true);
61+
BUILDER.pop();
62+
63+
SPEC = BUILDER.build();
64+
}
65+
}
66+
3967
public void setup(final FMLCommonSetupEvent event) {
68+
logger.info("setup");
4069
jarfile = ModList.get().getModFileById("dynmapblockscan").getFile().getFilePath().toFile();
41-
42-
// Load configuration file - use suggested (config/DynmapBlockScan.cfg)
43-
// Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
44-
// try {
45-
// cfg.load();
46-
//
47-
// verboselogging = cfg.get("Settings", "verboselog", false).getBoolean(false);
48-
// }
49-
// finally
50-
// {
51-
// cfg.save();
52-
// }
5370
}
5471

5572
private MinecraftServer server;
@@ -59,6 +76,8 @@ public void onServerStarting(FMLServerStartingEvent event) {
5976
server = event.getServer();
6077
if(plugin == null)
6178
plugin = proxy.startServer(server);
79+
plugin.setDisabledModules((List<String>) SettingsConfig.excludeModules.get());
80+
plugin.setDisabledBlockNames((List<String>) SettingsConfig.excludeBlockNames.get());
6281
plugin.serverStarting();
6382
}
6483

forge-1.16.5/src/main/java/org/dynmapblockscan/forge_1_16_5/DynmapBlockScanMod.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package org.dynmapblockscan.forge_1_16_5;
22

33
import java.io.File;
4+
import java.util.Arrays;
5+
import java.util.List;
46

57
import net.minecraft.server.MinecraftServer;
8+
import net.minecraftforge.common.ForgeConfigSpec;
69
import net.minecraftforge.common.MinecraftForge;
710
import net.minecraftforge.eventbus.api.SubscribeEvent;
811
import net.minecraftforge.fml.DistExecutor;
912
import net.minecraftforge.fml.ModList;
13+
import net.minecraftforge.fml.ModLoadingContext;
1014
import net.minecraftforge.fml.common.Mod;
1115
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
1216
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
1317
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
1418
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
1519
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
20+
import net.minecraftforge.fml.loading.FMLPaths;
21+
import net.minecraftforge.fml.loading.FileUtils;
1622

1723
@Mod("dynmapblockscan")
1824
public class DynmapBlockScanMod
@@ -33,22 +39,34 @@ public DynmapBlockScanMod() {
3339
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
3440

3541
MinecraftForge.EVENT_BUS.register(this);
42+
43+
FileUtils.getOrCreateDirectory(FMLPaths.CONFIGDIR.get().resolve("dynmapblockscan"), "dynmapblockscan");
44+
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, SettingsConfig.SPEC, "dynmapblockscan/settings.toml");
3645
}
3746

47+
public static class SettingsConfig
48+
{
49+
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
50+
public static final ForgeConfigSpec SPEC;
51+
52+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeModules;
53+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeBlockNames;
54+
55+
static
56+
{
57+
BUILDER.comment("DynmapBlockScan settings");
58+
BUILDER.push("settings");
59+
excludeModules = BUILDER.comment("Which modules to exclude").defineList("exclude_modules", Arrays.asList("minecraft"), entry -> true);
60+
excludeBlockNames = BUILDER.comment("Which block names to exclude").defineList("exclude_blocknames", Arrays.asList(), entry -> true);
61+
BUILDER.pop();
62+
63+
SPEC = BUILDER.build();
64+
}
65+
}
66+
3867
public void setup(final FMLCommonSetupEvent event) {
68+
logger.info("setup");
3969
jarfile = ModList.get().getModFileById("dynmapblockscan").getFile().getFilePath().toFile();
40-
41-
// Load configuration file - use suggested (config/DynmapBlockScan.cfg)
42-
// Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
43-
// try {
44-
// cfg.load();
45-
//
46-
// verboselogging = cfg.get("Settings", "verboselog", false).getBoolean(false);
47-
// }
48-
// finally
49-
// {
50-
// cfg.save();
51-
// }
5270
}
5371

5472
private MinecraftServer server;
@@ -58,6 +76,8 @@ public void onServerStarting(FMLServerStartingEvent event) {
5876
server = event.getServer();
5977
if(plugin == null)
6078
plugin = proxy.startServer(server);
79+
plugin.setDisabledModules((List<String>) SettingsConfig.excludeModules.get());
80+
plugin.setDisabledBlockNames((List<String>) SettingsConfig.excludeBlockNames.get());
6181
plugin.serverStarting();
6282
}
6383

forge-1.16.5/src/main/java/org/dynmapblockscan/forge_1_16_5/DynmapBlockScanPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.dynmapblockscan.core.blockstate.BSBlockState;
2020
import org.dynmapblockscan.core.blockstate.VariantList;
2121
import org.dynmapblockscan.core.model.BlockModel;
22-
import org.dynmapblockscan.core.statehandlers.IStateHandlerFactory;
2322
import org.dynmapblockscan.core.statehandlers.StateContainer.StateRec;
2423
import org.dynmapblockscan.forge_1_16_5.statehandlers.ForgeStateContainer;
2524

@@ -40,7 +39,7 @@
4039
public class DynmapBlockScanPlugin extends AbstractBlockScanBase
4140
{
4241
public static DynmapBlockScanPlugin plugin;
43-
42+
4443
public DynmapBlockScanPlugin(MinecraftServer srv)
4544
{
4645
plugin = this;

forge-1.17.1/src/main/java/org/dynmapblockscan/forge_1_17_1/DynmapBlockScanMod.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package org.dynmapblockscan.forge_1_17_1;
22

33
import java.io.File;
4-
import java.util.Map;
4+
import java.util.Arrays;
5+
import java.util.List;
56

67
import net.minecraft.server.MinecraftServer;
8+
import net.minecraftforge.common.ForgeConfigSpec;
79
import net.minecraftforge.common.MinecraftForge;
810
import net.minecraftforge.eventbus.api.SubscribeEvent;
911
import net.minecraftforge.fml.DistExecutor;
1012
import net.minecraftforge.fml.ModList;
13+
import net.minecraftforge.fml.ModLoadingContext;
1114
import net.minecraftforge.fml.common.Mod;
1215
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
1316
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
17+
import net.minecraftforge.fml.loading.FMLPaths;
18+
import net.minecraftforge.fml.loading.FileUtils;
1419
import net.minecraftforge.fmlserverevents.FMLServerStartedEvent;
1520
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
1621
import net.minecraftforge.fmlserverevents.FMLServerStoppingEvent;
@@ -34,22 +39,34 @@ public DynmapBlockScanMod() {
3439
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
3540

3641
MinecraftForge.EVENT_BUS.register(this);
42+
43+
FileUtils.getOrCreateDirectory(FMLPaths.CONFIGDIR.get().resolve("dynmapblockscan"), "dynmapblockscan");
44+
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, SettingsConfig.SPEC, "dynmapblockscan/settings.toml");
3745
}
3846

47+
public static class SettingsConfig
48+
{
49+
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
50+
public static final ForgeConfigSpec SPEC;
51+
52+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeModules;
53+
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> excludeBlockNames;
54+
55+
static
56+
{
57+
BUILDER.comment("DynmapBlockScan settings");
58+
BUILDER.push("settings");
59+
excludeModules = BUILDER.comment("Which modules to exclude").defineList("exclude_modules", Arrays.asList("minecraft"), entry -> true);
60+
excludeBlockNames = BUILDER.comment("Which block names to exclude").defineList("exclude_blocknames", Arrays.asList(), entry -> true);
61+
BUILDER.pop();
62+
63+
SPEC = BUILDER.build();
64+
}
65+
}
66+
3967
public void setup(final FMLCommonSetupEvent event) {
68+
logger.info("setup");
4069
jarfile = ModList.get().getModFileById("dynmapblockscan").getFile().getFilePath().toFile();
41-
42-
// Load configuration file - use suggested (config/DynmapBlockScan.cfg)
43-
// Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
44-
// try {
45-
// cfg.load();
46-
//
47-
// verboselogging = cfg.get("Settings", "verboselog", false).getBoolean(false);
48-
// }
49-
// finally
50-
// {
51-
// cfg.save();
52-
// }
5370
}
5471

5572
private MinecraftServer server;
@@ -59,6 +76,8 @@ public void onServerStarting(FMLServerStartingEvent event) {
5976
server = event.getServer();
6077
if(plugin == null)
6178
plugin = proxy.startServer(server);
79+
plugin.setDisabledModules((List<String>) SettingsConfig.excludeModules.get());
80+
plugin.setDisabledBlockNames((List<String>) SettingsConfig.excludeBlockNames.get());
6281
plugin.serverStarting();
6382
}
6483

0 commit comments

Comments
 (0)