From a616e5910d8a20a8673239806b1573f3a866d498 Mon Sep 17 00:00:00 2001 From: Robotia Date: Sat, 19 Mar 2016 21:44:21 -0400 Subject: [PATCH] Fulfill #239 + fully block stuff ability --- .../cauldron/configuration/ArraySetting.java | 30 +++++++++ .../configuration/CauldronConfig.java | 67 +++++++------------ .../configuration/IntArraySetting.java | 55 +++++++-------- .../configuration/StringArraySetting.java | 41 ++++++++++++ 4 files changed, 123 insertions(+), 70 deletions(-) create mode 100644 src/main/java/net/minecraftforge/cauldron/configuration/ArraySetting.java create mode 100644 src/main/java/net/minecraftforge/cauldron/configuration/StringArraySetting.java diff --git a/src/main/java/net/minecraftforge/cauldron/configuration/ArraySetting.java b/src/main/java/net/minecraftforge/cauldron/configuration/ArraySetting.java new file mode 100644 index 00000000..ad016001 --- /dev/null +++ b/src/main/java/net/minecraftforge/cauldron/configuration/ArraySetting.java @@ -0,0 +1,30 @@ +package net.minecraftforge.cauldron.configuration; + +import java.util.ArrayList; +import java.util.HashSet; + +public abstract class ArraySetting extends Setting{ + public ArraySetting(String path, String def, String description) { + super(path, def, description); + initArr(def); + } + + protected HashSet value_set; + protected ArrayList value_array; + + public boolean contains(T t) + { + return value_set.contains(t); + } + + public T get(int i) + { + if(i < 0 || i > value_array.size() - 1) return null; + + return value_array.get(i); + + } + + public abstract void initArr(String array); + +} diff --git a/src/main/java/net/minecraftforge/cauldron/configuration/CauldronConfig.java b/src/main/java/net/minecraftforge/cauldron/configuration/CauldronConfig.java index 353c5935..4a67dbfb 100644 --- a/src/main/java/net/minecraftforge/cauldron/configuration/CauldronConfig.java +++ b/src/main/java/net/minecraftforge/cauldron/configuration/CauldronConfig.java @@ -3,6 +3,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraftforge.cauldron.command.CauldronCommand; +import java.lang.reflect.Field; + import org.bukkit.configuration.file.YamlConfiguration; public class CauldronConfig extends ConfigBase @@ -66,10 +68,10 @@ public class CauldronConfig extends ConfigBase public final BoolSetting affinity = new BoolSetting(this, "optimized.affinity-locking", false, "Whether to enable affinity locking. Very technical usage, recommended for dedicated hosts only. Ask on Discord or GitHub for info on how to set this up properly."); public final BoolSetting ramChunks = new BoolSetting(this, "optimized.ram-load-chunks", false, "Loads chunks into the system RAM (experimental). WARNING! ENABLING THIS WILL INCREASE RAM USAGE BY OVER 1GB."); - // World Protection options + //Protection options public final BoolSetting protectSP = new BoolSetting(this, "protection.spawn-protect", true, "Whether to enable Thermos' all-seeing protection in the spawn world"); - public final IntArraySetting instantRemove = new IntArraySetting(this, "protection.instant-removal", new Integer[] {}, "Contains Block IDs that you want to NEVER exist in the world i.e. world anchors (just in case)"); - + public final IntArraySetting instantRemove = new IntArraySetting(this, "protection.instant-removal", "", "Contains Block IDs that you want to NEVER exist in the world i.e. world anchors (just in case) (e.g. instant-removal: 1,93,56,24 "); + public final StringArraySetting blockedCMDs = new StringArraySetting(this, "protection.blocked-cmds", "", "Contains commands you want to block from being used in-game, you must also include command aliases (e.g. blocked-cmds: /op,/deop,/stop,/restart ."); // Plug-in options public final BoolSetting reloadPlugins = new BoolSetting(this, "plugin-settings.allow-reload", false, "Allow plugins to be reloaded. WARNING - breaks with some mods. We *will not* support this!"); @@ -86,46 +88,25 @@ public CauldronConfig(String fileName, String commandName) public void init() { - settings.put(dumpMaterials.path, dumpMaterials); - settings.put(disableWarnings.path, disableWarnings); - settings.put(worldLeakDebug.path, worldLeakDebug); - settings.put(connectionLogging.path, connectionLogging); - settings.put(tickIntervalLogging.path, tickIntervalLogging); - settings.put(chunkLoadLogging.path, chunkLoadLogging); - settings.put(chunkUnloadLogging.path, chunkUnloadLogging); - settings.put(entitySpawnLogging.path, entitySpawnLogging); - settings.put(entityDespawnLogging.path, entityDespawnLogging); - settings.put(entityDeathLogging.path, entityDeathLogging); - settings.put(logWithStackTraces.path, logWithStackTraces); - settings.put(dumpChunksOnDeadlock.path, dumpChunksOnDeadlock); - settings.put(dumpHeapOnDeadlock.path, dumpHeapOnDeadlock); - settings.put(dumpThreadsOnWarn.path, dumpThreadsOnWarn); - settings.put(logEntityCollisionChecks.path, logEntityCollisionChecks); - settings.put(logEntitySpeedRemoval.path, logEntitySpeedRemoval); - settings.put(largeCollisionLogSize.path, largeCollisionLogSize); - settings.put(largeEntityCountLogSize.path, largeEntityCountLogSize); - settings.put(loadChunkOnRequest.path, loadChunkOnRequest); - settings.put(loadChunkOnForgeTick.path, loadChunkOnForgeTick); - settings.put(checkEntityBoundingBoxes.path, checkEntityBoundingBoxes); - settings.put(checkEntityMaxSpeeds.path, checkEntityMaxSpeeds); - settings.put(largeBoundingBoxLogSize.path, largeBoundingBoxLogSize); - settings.put(enableThreadContentionMonitoring.path, enableThreadContentionMonitoring); - settings.put(infiniteWaterSource.path, infiniteWaterSource); - settings.put(flowingLavaDecay.path, flowingLavaDecay); - settings.put(fakePlayerLogin.path, fakePlayerLogin); - settings.put(remapPluginFile.path, remapPluginFile); - settings.put(reloadPlugins.path, reloadPlugins); - settings.put(userLogin.path, userLogin); - settings.put(allowTntPunishment.path, allowTntPunishment); - settings.put(maxPlayersVisible.path, maxPlayersVisible); - settings.put(chunkGCGracePeriod.path, chunkGCGracePeriod); - settings.put(repeaterL.path, repeaterL); - settings.put(redstoneTorchL.path, redstoneTorchL); - settings.put(protectSP.path, protectSP); - settings.put(realNames.path, realNames); - settings.put(affinity.path, affinity); - settings.put(ramChunks.path, ramChunks); - settings.put(instantRemove.path, instantRemove); + Setting setting = null; + for(Field f : this.getClass().getDeclaredFields()) + { + if(f.getType().isInstance(Setting.class)) + { + try + { + f.get(setting); + if(setting == null) continue; + settings.put(setting.path, setting); + } + catch(Throwable t) + { + System.out.println("[Thermos] Failed to initialize a CauldronConfig setting."); + t.printStackTrace(); + } + + } + } load(); } diff --git a/src/main/java/net/minecraftforge/cauldron/configuration/IntArraySetting.java b/src/main/java/net/minecraftforge/cauldron/configuration/IntArraySetting.java index 7a35eb52..3fbe7138 100644 --- a/src/main/java/net/minecraftforge/cauldron/configuration/IntArraySetting.java +++ b/src/main/java/net/minecraftforge/cauldron/configuration/IntArraySetting.java @@ -1,20 +1,22 @@ package net.minecraftforge.cauldron.configuration; import java.util.ArrayList; +import java.util.HashSet; -public class IntArraySetting extends Setting { - private Integer[] value; +public class IntArraySetting extends ArraySetting { + private String value; private ConfigBase config; - public IntArraySetting(ConfigBase config, String path, Integer[] def, String description) + public IntArraySetting(ConfigBase config, String path, String def, String description) { super(path, def, description); this.value = def; + this.config = config; } @Override - public Integer[] getValue() + public String getValue() { return value; } @@ -22,28 +24,27 @@ public Integer[] getValue() @Override public void setValue(String value) { - String[] vals = value.split(","); - ArrayList minty = new ArrayList(vals.length); - for(int i = 0; i < vals.length; i++) - { - try - { - minty.add(Integer.parseInt(vals[i])); - } - catch(Exception e) - { - - } - catch(Error eeek) - { - - } - } - this.value = new Integer[minty.size()]; - for(int i = 0; i < this.value.length; i++) - { - this.value[i] = minty.get(i); - } - config.set(path, this.value); + + config.set(path, this.value = value); } + + @Override + public void initArr(String array) { + String[] potential_values = array.split(","); + this.value_array = new ArrayList(potential_values.length); + this.value_set = new HashSet(potential_values.length); + for(String potval : potential_values) + { + try + { + this.value_array.add(Integer.parseInt(potval)); + } + catch ( Throwable t) + { + System.out.println("[Thermos] Failed to add an option from config file"); + t.printStackTrace(); + } + } + this.value_set.addAll(value_array); + } } diff --git a/src/main/java/net/minecraftforge/cauldron/configuration/StringArraySetting.java b/src/main/java/net/minecraftforge/cauldron/configuration/StringArraySetting.java new file mode 100644 index 00000000..41028a96 --- /dev/null +++ b/src/main/java/net/minecraftforge/cauldron/configuration/StringArraySetting.java @@ -0,0 +1,41 @@ +package net.minecraftforge.cauldron.configuration; + +import java.util.ArrayList; +import java.util.HashSet; + +public class StringArraySetting extends ArraySetting { + private String value; + private ConfigBase config; + + public StringArraySetting(ConfigBase config, String path, String def, + String description) { + super(path, def, description); + this.value = def; + this.config = config; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + + config.set(path, this.value = value); + } + + @Override + public void initArr(String values) + { + String[] vals = values.split(","); + + value_array = new ArrayList(vals.length); + value_set = new HashSet(vals.length); + for(String val : vals) + { + value_array.add(val); + } + value_set.addAll(value_array); + } +}