Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
Fulfill #239 + fully block stuff ability
Browse files Browse the repository at this point in the history
  • Loading branch information
robotia committed Mar 20, 2016
1 parent bd2f328 commit a616e59
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.minecraftforge.cauldron.configuration;

import java.util.ArrayList;
import java.util.HashSet;

public abstract class ArraySetting<T> extends Setting<String>{
public ArraySetting(String path, String def, String description) {
super(path, def, description);
initArr(def);
}

protected HashSet<T> value_set;
protected ArrayList<T> 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!");

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
package net.minecraftforge.cauldron.configuration;

import java.util.ArrayList;
import java.util.HashSet;

public class IntArraySetting extends Setting<Integer[]> {
private Integer[] value;
public class IntArraySetting extends ArraySetting<Integer> {
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;
}

@Override
public void setValue(String value)
{
String[] vals = value.split(",");
ArrayList<Integer> minty = new ArrayList<Integer>(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<Integer>(potential_values.length);
this.value_set = new HashSet<Integer>(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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.minecraftforge.cauldron.configuration;

import java.util.ArrayList;
import java.util.HashSet;

public class StringArraySetting extends ArraySetting<String> {
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<String>(vals.length);
value_set = new HashSet<String>(vals.length);
for(String val : vals)
{
value_array.add(val);
}
value_set.addAll(value_array);
}
}

0 comments on commit a616e59

Please sign in to comment.