Fix Tabbing issues with config classes.
This commit is contained in:
parent
9c7d20b3a1
commit
490573a71f
3 changed files with 451 additions and 453 deletions
|
@ -51,95 +51,95 @@ import net.minecraftforge.fml.common.discovery.asm.ModAnnotation.EnumHolder;
|
||||||
|
|
||||||
public class ConfigManager
|
public class ConfigManager
|
||||||
{
|
{
|
||||||
private static Map<String, Multimap<Config.Type, ASMData>> asm_data = Maps.newHashMap();
|
private static Map<String, Multimap<Config.Type, ASMData>> asm_data = Maps.newHashMap();
|
||||||
private static Map<Class<?>, ITypeAdapter> ADAPTERS = Maps.newHashMap();
|
private static Map<Class<?>, ITypeAdapter> ADAPTERS = Maps.newHashMap();
|
||||||
private static Map<Class<?>, ITypeAdapter.Map> MAP_ADAPTERS = Maps.newHashMap();
|
private static Map<Class<?>, ITypeAdapter.Map> MAP_ADAPTERS = Maps.newHashMap();
|
||||||
private static Map<String, Configuration> CONFIGS = Maps.newHashMap();
|
private static Map<String, Configuration> CONFIGS = Maps.newHashMap();
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
register(boolean.class, TypeAdapters.bool);
|
register(boolean.class, TypeAdapters.bool);
|
||||||
register(boolean[].class, TypeAdapters.boolA);
|
register(boolean[].class, TypeAdapters.boolA);
|
||||||
register(Boolean.class, TypeAdapters.Bool);
|
register(Boolean.class, TypeAdapters.Bool);
|
||||||
register(Boolean[].class, TypeAdapters.BoolA);
|
register(Boolean[].class, TypeAdapters.BoolA);
|
||||||
register(float.class, TypeAdapters.flt);
|
register(float.class, TypeAdapters.flt);
|
||||||
register(float[].class, TypeAdapters.fltA);
|
register(float[].class, TypeAdapters.fltA);
|
||||||
register(Float.class, TypeAdapters.Flt);
|
register(Float.class, TypeAdapters.Flt);
|
||||||
register(Float[].class, TypeAdapters.FltA);
|
register(Float[].class, TypeAdapters.FltA);
|
||||||
register(double.class, TypeAdapters.dbl);
|
register(double.class, TypeAdapters.dbl);
|
||||||
register(double[].class, TypeAdapters.dblA);
|
register(double[].class, TypeAdapters.dblA);
|
||||||
register(Double.class, TypeAdapters.Dbl);
|
register(Double.class, TypeAdapters.Dbl);
|
||||||
register(Double[].class, TypeAdapters.DblA);
|
register(Double[].class, TypeAdapters.DblA);
|
||||||
register(byte.class, TypeAdapters.byt);
|
register(byte.class, TypeAdapters.byt);
|
||||||
register(byte[].class, TypeAdapters.bytA);
|
register(byte[].class, TypeAdapters.bytA);
|
||||||
register(Byte.class, TypeAdapters.Byt);
|
register(Byte.class, TypeAdapters.Byt);
|
||||||
register(Byte[].class, TypeAdapters.BytA);
|
register(Byte[].class, TypeAdapters.BytA);
|
||||||
register(char.class, TypeAdapters.chr);
|
register(char.class, TypeAdapters.chr);
|
||||||
register(char[].class, TypeAdapters.chrA);
|
register(char[].class, TypeAdapters.chrA);
|
||||||
register(Character.class, TypeAdapters.Chr);
|
register(Character.class, TypeAdapters.Chr);
|
||||||
register(Character[].class, TypeAdapters.ChrA);
|
register(Character[].class, TypeAdapters.ChrA);
|
||||||
register(short.class, TypeAdapters.shrt);
|
register(short.class, TypeAdapters.shrt);
|
||||||
register(short[].class, TypeAdapters.shrtA);
|
register(short[].class, TypeAdapters.shrtA);
|
||||||
register(Short.class, TypeAdapters.Shrt);
|
register(Short.class, TypeAdapters.Shrt);
|
||||||
register(Short[].class, TypeAdapters.ShrtA);
|
register(Short[].class, TypeAdapters.ShrtA);
|
||||||
register(int.class, TypeAdapters.int_);
|
register(int.class, TypeAdapters.int_);
|
||||||
register(int[].class, TypeAdapters.intA);
|
register(int[].class, TypeAdapters.intA);
|
||||||
register(Integer.class, TypeAdapters.Int);
|
register(Integer.class, TypeAdapters.Int);
|
||||||
register(Integer[].class, TypeAdapters.IntA);
|
register(Integer[].class, TypeAdapters.IntA);
|
||||||
register(String.class, TypeAdapters.Str);
|
register(String.class, TypeAdapters.Str);
|
||||||
register(String[].class, TypeAdapters.StrA);
|
register(String[].class, TypeAdapters.StrA);
|
||||||
}
|
}
|
||||||
private static void register(Class<?> cls, ITypeAdapter adpt)
|
private static void register(Class<?> cls, ITypeAdapter adpt)
|
||||||
{
|
{
|
||||||
ADAPTERS.put(cls, adpt);
|
ADAPTERS.put(cls, adpt);
|
||||||
if (adpt instanceof ITypeAdapter.Map)
|
if (adpt instanceof ITypeAdapter.Map)
|
||||||
MAP_ADAPTERS.put(cls, (ITypeAdapter.Map)adpt);
|
MAP_ADAPTERS.put(cls, (ITypeAdapter.Map)adpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadData(ASMDataTable data)
|
public static void loadData(ASMDataTable data)
|
||||||
{
|
{
|
||||||
FMLLog.fine("Loading @Config anotation data");
|
FMLLog.fine("Loading @Config anotation data");
|
||||||
for (ASMData target : data.getAll(Config.class.getName()))
|
for (ASMData target : data.getAll(Config.class.getName()))
|
||||||
{
|
{
|
||||||
String modid = (String)target.getAnnotationInfo().get("modid");
|
String modid = (String)target.getAnnotationInfo().get("modid");
|
||||||
Multimap<Config.Type, ASMData> map = asm_data.get(modid);
|
Multimap<Config.Type, ASMData> map = asm_data.get(modid);
|
||||||
if (map == null)
|
if (map == null)
|
||||||
{
|
{
|
||||||
map = ArrayListMultimap.create();
|
map = ArrayListMultimap.create();
|
||||||
asm_data.put(modid, map);
|
asm_data.put(modid, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumHolder tholder = (EnumHolder)target.getAnnotationInfo().get("type");
|
EnumHolder tholder = (EnumHolder)target.getAnnotationInfo().get("type");
|
||||||
Config.Type type = tholder == null ? Config.Type.INSTANCE : Config.Type.valueOf(tholder.getValue());
|
Config.Type type = tholder == null ? Config.Type.INSTANCE : Config.Type.valueOf(tholder.getValue());
|
||||||
|
|
||||||
map.put(type, target);
|
map.put(type, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load(String modid, Config.Type type)
|
public static void load(String modid, Config.Type type)
|
||||||
{
|
{
|
||||||
FMLLog.fine("Attempting to inject @Config classes into %s for type %s", modid, type);
|
FMLLog.fine("Attempting to inject @Config classes into %s for type %s", modid, type);
|
||||||
ClassLoader mcl = Loader.instance().getModClassLoader();
|
ClassLoader mcl = Loader.instance().getModClassLoader();
|
||||||
File configDir = Loader.instance().getConfigDir();
|
File configDir = Loader.instance().getConfigDir();
|
||||||
Multimap<Config.Type, ASMData> map = asm_data.get(modid);
|
Multimap<Config.Type, ASMData> map = asm_data.get(modid);
|
||||||
|
|
||||||
if (map == null)
|
if (map == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (ASMData targ : map.get(type))
|
for (ASMData targ : map.get(type))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class<?> cls = Class.forName(targ.getClassName(), true, mcl);
|
Class<?> cls = Class.forName(targ.getClassName(), true, mcl);
|
||||||
String name = (String)targ.getAnnotationInfo().get("name");
|
String name = (String)targ.getAnnotationInfo().get("name");
|
||||||
if (name == null)
|
if (name == null)
|
||||||
name = modid;
|
name = modid;
|
||||||
File file = new File(configDir, name + ".cfg");
|
File file = new File(configDir, name + ".cfg");
|
||||||
|
|
||||||
Configuration cfg = CONFIGS.get(file.getAbsolutePath());
|
Configuration cfg = CONFIGS.get(file.getAbsolutePath());
|
||||||
if (cfg == null)
|
if (cfg == null)
|
||||||
{
|
{
|
||||||
cfg = new Configuration(file);
|
cfg = new Configuration(file);
|
||||||
cfg.load();
|
cfg.load();
|
||||||
CONFIGS.put(file.getAbsolutePath(), cfg);
|
CONFIGS.put(file.getAbsolutePath(), cfg);
|
||||||
}
|
}
|
||||||
|
@ -155,18 +155,18 @@ public class ConfigManager
|
||||||
throw new LoaderException(e);
|
throw new LoaderException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================
|
// =======================================================
|
||||||
// INTERNAL
|
// INTERNAL
|
||||||
// =======================================================
|
// =======================================================
|
||||||
private static void createConfig(Configuration cfg, Class<?> cls, String modid, boolean isStatic)
|
private static void createConfig(Configuration cfg, Class<?> cls, String modid, boolean isStatic)
|
||||||
{
|
{
|
||||||
String category = "general";
|
String category = "general";
|
||||||
for (Field f : cls.getDeclaredFields())
|
for (Field f : cls.getDeclaredFields())
|
||||||
{
|
{
|
||||||
if (!Modifier.isPublic(f.getModifiers()))
|
if (!Modifier.isPublic(f.getModifiers()))
|
||||||
continue;
|
continue;
|
||||||
if (Modifier.isStatic(f.getModifiers()) != isStatic)
|
if (Modifier.isStatic(f.getModifiers()) != isStatic)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -174,72 +174,72 @@ public class ConfigManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Joiner NEW_LINE = Joiner.on('\n');
|
private static final Joiner NEW_LINE = Joiner.on('\n');
|
||||||
private static final Joiner PIPE = Joiner.on('|');
|
private static final Joiner PIPE = Joiner.on('|');
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private static void createConfig(String modid, String category, Configuration cfg, Class<?> ftype, Field f, Object instance)
|
private static void createConfig(String modid, String category, Configuration cfg, Class<?> ftype, Field f, Object instance)
|
||||||
{
|
{
|
||||||
Property prop = null;
|
Property prop = null;
|
||||||
|
|
||||||
String comment = null;
|
String comment = null;
|
||||||
Comment ca = f.getAnnotation(Comment.class);
|
Comment ca = f.getAnnotation(Comment.class);
|
||||||
if (ca != null)
|
if (ca != null)
|
||||||
comment = NEW_LINE.join(ca.value());
|
comment = NEW_LINE.join(ca.value());
|
||||||
|
|
||||||
String langKey = modid + "." + category + "." + f.getName().toLowerCase(Locale.ENGLISH);
|
String langKey = modid + "." + category + "." + f.getName().toLowerCase(Locale.ENGLISH);
|
||||||
LangKey la = f.getAnnotation(LangKey.class);
|
LangKey la = f.getAnnotation(LangKey.class);
|
||||||
if (la != null)
|
if (la != null)
|
||||||
langKey = la.value();
|
langKey = la.value();
|
||||||
|
|
||||||
ITypeAdapter adapter = ADAPTERS.get(ftype);
|
ITypeAdapter adapter = ADAPTERS.get(ftype);
|
||||||
|
|
||||||
if (adapter != null)
|
if (adapter != null)
|
||||||
{
|
{
|
||||||
prop = adapter.getProp(cfg, category, f, instance, comment);
|
prop = adapter.getProp(cfg, category, f, instance, comment);
|
||||||
set(instance, f, adapter.getValue(prop));
|
set(instance, f, adapter.getValue(prop));
|
||||||
}
|
}
|
||||||
else if (ftype.getSuperclass() == Enum.class)
|
else if (ftype.getSuperclass() == Enum.class)
|
||||||
{
|
{
|
||||||
Enum enu = (Enum)get(instance, f);
|
Enum enu = (Enum)get(instance, f);
|
||||||
prop = cfg.get(category, f.getName(), enu.name(), comment);
|
prop = cfg.get(category, f.getName(), enu.name(), comment);
|
||||||
prop.setValidationPattern(makePattern((Class<? extends Enum>)ftype));
|
prop.setValidationPattern(makePattern((Class<? extends Enum>)ftype));
|
||||||
set(instance, f, Enum.valueOf((Class<? extends Enum>)ftype, prop.getString()));
|
set(instance, f, Enum.valueOf((Class<? extends Enum>)ftype, prop.getString()));
|
||||||
}
|
}
|
||||||
else if (ftype == Map.class)
|
else if (ftype == Map.class)
|
||||||
{
|
{
|
||||||
String sub = category + "." + f.getName().toLowerCase(Locale.ENGLISH);
|
String sub = category + "." + f.getName().toLowerCase(Locale.ENGLISH);
|
||||||
Map<String, Object> m = (Map<String, Object>)get(instance, f);
|
Map<String, Object> m = (Map<String, Object>)get(instance, f);
|
||||||
ParameterizedType type = (ParameterizedType)f.getGenericType();
|
ParameterizedType type = (ParameterizedType)f.getGenericType();
|
||||||
Type mtype = type.getActualTypeArguments()[1];
|
Type mtype = type.getActualTypeArguments()[1];
|
||||||
|
|
||||||
cfg.getCategory(sub).setComment(comment);
|
cfg.getCategory(sub).setComment(comment);
|
||||||
|
|
||||||
for (Entry<String, Object> e : m.entrySet())
|
for (Entry<String, Object> e : m.entrySet())
|
||||||
{
|
{
|
||||||
ITypeAdapter.Map adpt = MAP_ADAPTERS.get(mtype);
|
ITypeAdapter.Map adpt = MAP_ADAPTERS.get(mtype);
|
||||||
|
|
||||||
if (adpt != null)
|
if (adpt != null)
|
||||||
{
|
{
|
||||||
prop = adpt.getProp(cfg, sub, e.getKey(), e.getValue());
|
prop = adpt.getProp(cfg, sub, e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
else if (mtype instanceof Class && ((Class<?>)mtype).getSuperclass() == Enum.class)
|
else if (mtype instanceof Class && ((Class<?>)mtype).getSuperclass() == Enum.class)
|
||||||
{
|
{
|
||||||
prop = TypeAdapters.Str.getProp(cfg, sub, e.getKey(), ((Enum)e.getValue()).name());
|
prop = TypeAdapters.Str.getProp(cfg, sub, e.getKey(), ((Enum)e.getValue()).name());
|
||||||
prop.setValidationPattern(makePattern((Class<? extends Enum>)mtype));
|
prop.setValidationPattern(makePattern((Class<? extends Enum>)mtype));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new RuntimeException("Unknown type in map! " + f.getDeclaringClass() + "/" + f.getName() + " " + mtype);
|
throw new RuntimeException("Unknown type in map! " + f.getDeclaringClass() + "/" + f.getName() + " " + mtype);
|
||||||
|
|
||||||
prop.setLanguageKey(langKey + "." + e.getKey().toLowerCase(Locale.ENGLISH));
|
prop.setLanguageKey(langKey + "." + e.getKey().toLowerCase(Locale.ENGLISH));
|
||||||
|
|
||||||
}
|
}
|
||||||
prop = null;
|
prop = null;
|
||||||
}
|
}
|
||||||
else if (ftype.getSuperclass() == Object.class) //Only support classes that are one level below Object.
|
else if (ftype.getSuperclass() == Object.class) //Only support classes that are one level below Object.
|
||||||
{
|
{
|
||||||
String sub = category + "." + f.getName().toLowerCase(Locale.ENGLISH);
|
String sub = category + "." + f.getName().toLowerCase(Locale.ENGLISH);
|
||||||
Object sinst = get(instance, f);
|
Object sinst = get(instance, f);
|
||||||
for (Field sf : ftype.getDeclaredFields())
|
for (Field sf : ftype.getDeclaredFields())
|
||||||
{
|
{
|
||||||
if (!Modifier.isPublic(sf.getModifiers()))
|
if (!Modifier.isPublic(sf.getModifiers()))
|
||||||
|
@ -255,29 +255,29 @@ public class ConfigManager
|
||||||
|
|
||||||
if (prop != null)
|
if (prop != null)
|
||||||
{
|
{
|
||||||
prop.setLanguageKey(langKey);
|
prop.setLanguageKey(langKey);
|
||||||
RangeInt ia = f.getAnnotation(RangeInt.class);
|
RangeInt ia = f.getAnnotation(RangeInt.class);
|
||||||
if (ia != null)
|
if (ia != null)
|
||||||
{
|
{
|
||||||
prop.setMinValue(ia.min());
|
prop.setMinValue(ia.min());
|
||||||
prop.setMaxValue(ia.max());
|
prop.setMaxValue(ia.max());
|
||||||
if (comment != null)
|
if (comment != null)
|
||||||
prop.setComment(NEW_LINE.join(new String[]{comment, "Min: " + ia.min(), "Max: " + ia.max()}));
|
prop.setComment(NEW_LINE.join(new String[]{comment, "Min: " + ia.min(), "Max: " + ia.max()}));
|
||||||
else
|
else
|
||||||
prop.setComment(NEW_LINE.join(new String[]{"Min: " + ia.min(), "Max: " + ia.max()}));
|
prop.setComment(NEW_LINE.join(new String[]{"Min: " + ia.min(), "Max: " + ia.max()}));
|
||||||
}
|
}
|
||||||
RangeDouble da = f.getAnnotation(RangeDouble.class);
|
RangeDouble da = f.getAnnotation(RangeDouble.class);
|
||||||
if (da != null)
|
if (da != null)
|
||||||
{
|
{
|
||||||
prop.setMinValue(da.min());
|
prop.setMinValue(da.min());
|
||||||
prop.setMaxValue(da.max());
|
prop.setMaxValue(da.max());
|
||||||
if (comment != null)
|
if (comment != null)
|
||||||
prop.setComment(NEW_LINE.join(new String[]{comment, "Min: " + da.min(), "Max: " + da.max()}));
|
prop.setComment(NEW_LINE.join(new String[]{comment, "Min: " + da.min(), "Max: " + da.max()}));
|
||||||
else
|
else
|
||||||
prop.setComment(NEW_LINE.join(new String[]{"Min: " + da.min(), "Max: " + da.max()}));
|
prop.setComment(NEW_LINE.join(new String[]{"Min: " + da.min(), "Max: " + da.max()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO List length values
|
//TODO List length values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void set(Object instance, Field f, Object v)
|
private static void set(Object instance, Field f, Object v)
|
||||||
|
@ -298,12 +298,12 @@ public class ConfigManager
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private static Pattern makePattern(Class<? extends Enum> cls)
|
private static Pattern makePattern(Class<? extends Enum> cls)
|
||||||
{
|
{
|
||||||
List<String> lst = Lists.newArrayList();
|
List<String> lst = Lists.newArrayList();
|
||||||
for (Enum e : cls.getEnumConstants())
|
for (Enum e : cls.getEnumConstants())
|
||||||
lst.add(e.name());
|
lst.add(e.name());
|
||||||
return Pattern.compile(PIPE.join(lst));
|
return Pattern.compile(PIPE.join(lst));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.lang.reflect.Field;
|
||||||
//=========================================================
|
//=========================================================
|
||||||
// Run away thar' be dragons!
|
// Run away thar' be dragons!
|
||||||
//=========================================================
|
//=========================================================
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.google.common.primitives.Booleans;
|
import com.google.common.primitives.Booleans;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
|
@ -31,9 +32,6 @@ import com.google.common.primitives.Floats;
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import com.google.common.primitives.Shorts;
|
import com.google.common.primitives.Shorts;
|
||||||
|
|
||||||
import scala.actors.threadpool.Arrays;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
class TypeAdapters
|
class TypeAdapters
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -46,345 +44,345 @@ class TypeAdapters
|
||||||
* int, int[], Integer, Integer[]
|
* int, int[], Integer, Integer[]
|
||||||
* String, String[]
|
* String, String[]
|
||||||
*/
|
*/
|
||||||
static ITypeAdapter bool = new TypeAdapter() {
|
static ITypeAdapter bool = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getBoolean(instance, field), comment);
|
return cfg.get(category, field.getName(), getBoolean(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getBoolean();
|
return prop.getBoolean();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter boolA = new MapAdapter() {
|
static ITypeAdapter boolA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (boolean[])getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (boolean[])getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (boolean[])value, null);
|
return cfg.get(category, name, (boolean[])value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getBooleanList();
|
return prop.getBooleanList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Bool = new MapAdapter() {
|
static ITypeAdapter Bool = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Boolean)getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (Boolean)getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Boolean)value, null);
|
return cfg.get(category, name, (Boolean)value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Boolean.valueOf(prop.getBoolean());
|
return Boolean.valueOf(prop.getBoolean());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter BoolA = new MapAdapter() {
|
static ITypeAdapter BoolA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Booleans.toArray(Arrays.asList((Boolean[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Booleans.toArray(Arrays.asList((Boolean[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Boolean)value, null);
|
return cfg.get(category, name, (Boolean)value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Booleans.asList(prop.getBooleanList()).toArray(new Boolean[prop.getBooleanList().length]);
|
return Booleans.asList(prop.getBooleanList()).toArray(new Boolean[prop.getBooleanList().length]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter flt = new TypeAdapter() {
|
static ITypeAdapter flt = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getFloat(instance, field), comment);
|
return cfg.get(category, field.getName(), getFloat(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return (float)prop.getDouble();
|
return (float)prop.getDouble();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter fltA = new MapAdapter() {
|
static ITypeAdapter fltA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Doubles.toArray(Floats.asList((float[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Doubles.toArray(Floats.asList((float[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Doubles.toArray(Floats.asList((float[])value)), null);
|
return cfg.get(category, name, Doubles.toArray(Floats.asList((float[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Floats.toArray(Doubles.asList(prop.getDoubleList()));
|
return Floats.toArray(Doubles.asList(prop.getDoubleList()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Flt = new MapAdapter() {
|
static ITypeAdapter Flt = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Float)getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (Float)getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Float)value, null);
|
return cfg.get(category, name, (Float)value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Float.valueOf((float)prop.getDouble());
|
return Float.valueOf((float)prop.getDouble());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter FltA = new MapAdapter() {
|
static ITypeAdapter FltA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Doubles.toArray(Arrays.asList((Float[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Doubles.toArray(Arrays.asList((Float[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Doubles.toArray(Arrays.asList((Float[])value)), null);
|
return cfg.get(category, name, Doubles.toArray(Arrays.asList((Float[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Floats.asList(Floats.toArray(Doubles.asList(prop.getDoubleList()))).toArray(new Float[prop.getDoubleList().length]);
|
return Floats.asList(Floats.toArray(Doubles.asList(prop.getDoubleList()))).toArray(new Float[prop.getDoubleList().length]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter dbl = new TypeAdapter() {
|
static ITypeAdapter dbl = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getDouble(instance, field), comment);
|
return cfg.get(category, field.getName(), getDouble(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getDouble();
|
return prop.getDouble();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter dblA = new MapAdapter() {
|
static ITypeAdapter dblA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (double[])getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (double[])getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (double[])value, null);
|
return cfg.get(category, name, (double[])value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getDoubleList();
|
return prop.getDoubleList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Dbl = new MapAdapter() {
|
static ITypeAdapter Dbl = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Double)getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (Double)getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Double)value, null);
|
return cfg.get(category, name, (Double)value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Double.valueOf(prop.getDouble());
|
return Double.valueOf(prop.getDouble());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter DblA = new MapAdapter() {
|
static ITypeAdapter DblA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Doubles.toArray(Arrays.asList((Double[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Doubles.toArray(Arrays.asList((Double[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Doubles.toArray(Arrays.asList((Double[])value)), null);
|
return cfg.get(category, name, Doubles.toArray(Arrays.asList((Double[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Doubles.asList(prop.getDoubleList()).toArray(new Double[prop.getDoubleList().length]);
|
return Doubles.asList(prop.getDoubleList()).toArray(new Double[prop.getDoubleList().length]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter byt = new TypeAdapter() {
|
static ITypeAdapter byt = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getByte(instance, field), comment, Byte.MIN_VALUE, Byte.MAX_VALUE);
|
return cfg.get(category, field.getName(), getByte(instance, field), comment, Byte.MIN_VALUE, Byte.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return (byte)prop.getInt();
|
return (byte)prop.getInt();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter bytA = new MapAdapter() {
|
static ITypeAdapter bytA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Ints.toArray(Bytes.asList((byte[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Ints.toArray(Bytes.asList((byte[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Ints.toArray(Bytes.asList((byte[])value)), null);
|
return cfg.get(category, name, Ints.toArray(Bytes.asList((byte[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Bytes.toArray(Ints.asList(prop.getIntList()));
|
return Bytes.toArray(Ints.asList(prop.getIntList()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Byt = new MapAdapter() {
|
static ITypeAdapter Byt = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Byte)getObject(instance, field), comment, Byte.MIN_VALUE, Byte.MAX_VALUE);
|
return cfg.get(category, field.getName(), (Byte)getObject(instance, field), comment, Byte.MIN_VALUE, Byte.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Byte)value, null, Byte.MIN_VALUE, Byte.MAX_VALUE);
|
return cfg.get(category, name, (Byte)value, null, Byte.MIN_VALUE, Byte.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Byte.valueOf((byte)prop.getInt());
|
return Byte.valueOf((byte)prop.getInt());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter BytA = new MapAdapter() {
|
static ITypeAdapter BytA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Ints.toArray(Arrays.asList((Byte[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Ints.toArray(Arrays.asList((Byte[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Ints.toArray(Arrays.asList((Byte[])value)), null);
|
return cfg.get(category, name, Ints.toArray(Arrays.asList((Byte[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Bytes.asList(Bytes.toArray(Ints.asList(prop.getIntList()))).toArray(new Byte[prop.getIntList().length]);
|
return Bytes.asList(Bytes.toArray(Ints.asList(prop.getIntList()))).toArray(new Byte[prop.getIntList().length]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter chr = new TypeAdapter() {
|
static ITypeAdapter chr = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getChar(instance, field), comment, Character.MIN_VALUE, Character.MAX_VALUE);
|
return cfg.get(category, field.getName(), getChar(instance, field), comment, Character.MIN_VALUE, Character.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return (char)prop.getInt();
|
return (char)prop.getInt();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter chrA = new MapAdapter() {
|
static ITypeAdapter chrA = new MapAdapter() {
|
||||||
private int[] toPrim(char[] v) {
|
private int[] toPrim(char[] v) {
|
||||||
if (v == null) return new int[0];
|
if (v == null) return new int[0];
|
||||||
int[] ret = new int[v.length];
|
int[] ret = new int[v.length];
|
||||||
for (int x = 0; x < v.length; x++)
|
for (int x = 0; x < v.length; x++)
|
||||||
ret[x] = v[x];
|
ret[x] = v[x];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), toPrim((char[])getObject(instance, field)), comment);
|
return cfg.get(category, field.getName(), toPrim((char[])getObject(instance, field)), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, toPrim((char[])value), null);
|
return cfg.get(category, name, toPrim((char[])value), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
int[] v = prop.getIntList();
|
int[] v = prop.getIntList();
|
||||||
char[] ret = new char[v.length];
|
char[] ret = new char[v.length];
|
||||||
for (int x = 0; x < v.length; x++)
|
for (int x = 0; x < v.length; x++)
|
||||||
ret[x] = (char)v[x];
|
ret[x] = (char)v[x];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Chr = new MapAdapter() {
|
static ITypeAdapter Chr = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Character)getObject(instance, field), comment, Character.MIN_VALUE, Character.MAX_VALUE);
|
return cfg.get(category, field.getName(), (Character)getObject(instance, field), comment, Character.MIN_VALUE, Character.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Character)value, null, Character.MIN_VALUE, Character.MAX_VALUE);
|
return cfg.get(category, name, (Character)value, null, Character.MIN_VALUE, Character.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Character.valueOf((char)prop.getInt());
|
return Character.valueOf((char)prop.getInt());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter ChrA = new MapAdapter() {
|
static ITypeAdapter ChrA = new MapAdapter() {
|
||||||
private int[] toPrim(Character[] v) {
|
private int[] toPrim(Character[] v) {
|
||||||
if (v == null) return new int[0];
|
if (v == null) return new int[0];
|
||||||
int[] ret = new int[v.length];
|
int[] ret = new int[v.length];
|
||||||
for (int x = 0; x < v.length; x++)
|
for (int x = 0; x < v.length; x++)
|
||||||
ret[x] = v[x] == null ? 0 : v[x];
|
ret[x] = v[x] == null ? 0 : v[x];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), toPrim((Character[])getObject(instance, field)), comment);
|
return cfg.get(category, field.getName(), toPrim((Character[])getObject(instance, field)), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, toPrim((Character[])value), null);
|
return cfg.get(category, name, toPrim((Character[])value), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
int[] v = prop.getIntList();
|
int[] v = prop.getIntList();
|
||||||
Character[] ret = new Character[v.length];
|
Character[] ret = new Character[v.length];
|
||||||
for (int x = 0; x < v.length; x++)
|
for (int x = 0; x < v.length; x++)
|
||||||
ret[x] = Character.valueOf((char)v[x]);
|
ret[x] = Character.valueOf((char)v[x]);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter shrt = new TypeAdapter() {
|
static ITypeAdapter shrt = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getShort(instance, field), comment, Short.MIN_VALUE, Short.MAX_VALUE);
|
return cfg.get(category, field.getName(), getShort(instance, field), comment, Short.MIN_VALUE, Short.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return (short)prop.getInt();
|
return (short)prop.getInt();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter shrtA = new MapAdapter() {
|
static ITypeAdapter shrtA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Ints.toArray(Shorts.asList((short[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Ints.toArray(Shorts.asList((short[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Ints.toArray(Shorts.asList((short[])value)), null);
|
return cfg.get(category, name, Ints.toArray(Shorts.asList((short[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Shorts.toArray(Ints.asList(prop.getIntList()));
|
return Shorts.toArray(Ints.asList(prop.getIntList()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Shrt = new MapAdapter() {
|
static ITypeAdapter Shrt = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Short)getObject(instance, field), comment, Short.MIN_VALUE, Short.MAX_VALUE);
|
return cfg.get(category, field.getName(), (Short)getObject(instance, field), comment, Short.MIN_VALUE, Short.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Short)value, null, Short.MIN_VALUE, Short.MAX_VALUE);
|
return cfg.get(category, name, (Short)value, null, Short.MIN_VALUE, Short.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Short.valueOf((short)prop.getInt());
|
return Short.valueOf((short)prop.getInt());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter ShrtA = new MapAdapter() {
|
static ITypeAdapter ShrtA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Ints.toArray(Arrays.asList((Short[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Ints.toArray(Arrays.asList((Short[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Ints.toArray(Arrays.asList((Short[])value)), null);
|
return cfg.get(category, name, Ints.toArray(Arrays.asList((Short[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
int[] v = prop.getIntList();
|
int[] v = prop.getIntList();
|
||||||
Short[] ret = new Short[v.length];
|
Short[] ret = new Short[v.length];
|
||||||
for (int x = 0; x < ret.length; x++)
|
for (int x = 0; x < ret.length; x++)
|
||||||
ret[x] = Short.valueOf((short)v[x]);
|
ret[x] = Short.valueOf((short)v[x]);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter int_ = new TypeAdapter() {
|
static ITypeAdapter int_ = new TypeAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), getInt(instance, field), comment, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
return cfg.get(category, field.getName(), getInt(instance, field), comment, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getInt();
|
return prop.getInt();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter intA = new MapAdapter() {
|
static ITypeAdapter intA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (int[])getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (int[])getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (int[])value, null);
|
return cfg.get(category, name, (int[])value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getIntList();
|
return prop.getIntList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter Int = new MapAdapter() {
|
static ITypeAdapter Int = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (Integer)getObject(instance, field), comment, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
return cfg.get(category, field.getName(), (Integer)getObject(instance, field), comment, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (Integer)value, null, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
return cfg.get(category, name, (Integer)value, null, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return (Integer)prop.getInt();
|
return (Integer)prop.getInt();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter IntA = new MapAdapter() {
|
static ITypeAdapter IntA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), Ints.toArray(Arrays.asList((Integer[])getObject(instance, field))), comment);
|
return cfg.get(category, field.getName(), Ints.toArray(Arrays.asList((Integer[])getObject(instance, field))), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, Ints.toArray(Arrays.asList((Integer[])value)), null);
|
return cfg.get(category, name, Ints.toArray(Arrays.asList((Integer[])value)), null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return Ints.asList(prop.getIntList()).toArray(new Integer[prop.getIntList().length]);
|
return Ints.asList(prop.getIntList()).toArray(new Integer[prop.getIntList().length]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter.Map Str = new MapAdapter() {
|
static ITypeAdapter.Map Str = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (String)getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (String)getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (String)value, null);
|
return cfg.get(category, name, (String)value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getString();
|
return prop.getString();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static ITypeAdapter StrA = new MapAdapter() {
|
static ITypeAdapter StrA = new MapAdapter() {
|
||||||
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
public Property getProp(Configuration cfg, String category, Field field, Object instance, String comment) {
|
||||||
return cfg.get(category, field.getName(), (String[])getObject(instance, field), comment);
|
return cfg.get(category, field.getName(), (String[])getObject(instance, field), comment);
|
||||||
}
|
}
|
||||||
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
public Property getProp(Configuration cfg, String category, String name, Object value) {
|
||||||
return cfg.get(category, name, (String[])value, null);
|
return cfg.get(category, name, (String[])value, null);
|
||||||
}
|
}
|
||||||
public Object getValue(Property prop) {
|
public Object getValue(Property prop) {
|
||||||
return prop.getStringList();
|
return prop.getStringList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private static abstract class TypeAdapter implements ITypeAdapter
|
private static abstract class TypeAdapter implements ITypeAdapter
|
||||||
{
|
{
|
||||||
public static boolean getBoolean(Object instance, Field f)
|
public static boolean getBoolean(Object instance, Field f)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -457,6 +455,6 @@ class TypeAdapters
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static abstract class MapAdapter extends TypeAdapter implements ITypeAdapter.Map {}
|
private static abstract class MapAdapter extends TypeAdapter implements ITypeAdapter.Map {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,66 +9,66 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
@Mod(modid = ConfigTest.MODID, name = "ConfigTest", version = "1.0")
|
@Mod(modid = ConfigTest.MODID, name = "ConfigTest", version = "1.0")
|
||||||
public class ConfigTest
|
public class ConfigTest
|
||||||
{
|
{
|
||||||
public static final String MODID = "config_test";
|
public static final String MODID = "config_test";
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Config(modid = MODID, type = Type.INSTANCE, name = MODID + "_types")
|
@Config(modid = MODID, type = Type.INSTANCE, name = MODID + "_types")
|
||||||
public static class CONFIG_TYPES
|
public static class CONFIG_TYPES
|
||||||
{
|
{
|
||||||
public static boolean bool = false;
|
public static boolean bool = false;
|
||||||
public static boolean[] boolA = {false, true};
|
public static boolean[] boolA = {false, true};
|
||||||
public static Boolean Bool = false;
|
public static Boolean Bool = false;
|
||||||
public static Boolean[] BoolA = {false, true};
|
public static Boolean[] BoolA = {false, true};
|
||||||
public static float flt = 1.0f;
|
public static float flt = 1.0f;
|
||||||
public static float[] fltA = {1.0f, 2.0f};
|
public static float[] fltA = {1.0f, 2.0f};
|
||||||
public static Float Flt = 1.0f;
|
public static Float Flt = 1.0f;
|
||||||
public static Float[] FltA = {1.0f, 2.0f};
|
public static Float[] FltA = {1.0f, 2.0f};
|
||||||
public static double dbl = 1.0d;
|
public static double dbl = 1.0d;
|
||||||
public static double[] dblA = {1.0d, 2.0d};
|
public static double[] dblA = {1.0d, 2.0d};
|
||||||
public static Double Dbl = 1.0D;
|
public static Double Dbl = 1.0D;
|
||||||
public static Double[] DblA = {1.0D, 2.0D};
|
public static Double[] DblA = {1.0D, 2.0D};
|
||||||
public static byte byt = 1;
|
public static byte byt = 1;
|
||||||
public static byte[] bytA = {1, 2};
|
public static byte[] bytA = {1, 2};
|
||||||
public static Byte Byt = 1;
|
public static Byte Byt = 1;
|
||||||
public static Byte[] BytA = {1, 2};
|
public static Byte[] BytA = {1, 2};
|
||||||
public static char chr = 'a';
|
public static char chr = 'a';
|
||||||
public static char[] chrA = {'a', 'b'};
|
public static char[] chrA = {'a', 'b'};
|
||||||
public static Character Chr = 'A';
|
public static Character Chr = 'A';
|
||||||
public static Character[] ChrA = {'A', 'B'};
|
public static Character[] ChrA = {'A', 'B'};
|
||||||
public static short srt = 1;
|
public static short srt = 1;
|
||||||
public static short[] srtA = {1, 2};
|
public static short[] srtA = {1, 2};
|
||||||
public static Short Srt = 1;
|
public static Short Srt = 1;
|
||||||
public static Short[] SrtA = {1, 2};
|
public static Short[] SrtA = {1, 2};
|
||||||
public static int int_ = 1;
|
public static int int_ = 1;
|
||||||
public static int[] intA = {1, 2};
|
public static int[] intA = {1, 2};
|
||||||
public static Integer Int = 1;
|
public static Integer Int = 1;
|
||||||
public static Integer[] IntA = {1, 2};
|
public static Integer[] IntA = {1, 2};
|
||||||
public static String Str = "STRING!";
|
public static String Str = "STRING!";
|
||||||
public static String[] StrA = {"STR", "ING!"};
|
public static String[] StrA = {"STR", "ING!"};
|
||||||
public static TEST enu = TEST.BIG;
|
public static TEST enu = TEST.BIG;
|
||||||
public static NestedType Inner = new NestedType();
|
public static NestedType Inner = new NestedType();
|
||||||
|
|
||||||
public enum TEST { BIG, BAD, WOLF; }
|
public enum TEST { BIG, BAD, WOLF; }
|
||||||
public static class NestedType
|
public static class NestedType
|
||||||
{
|
{
|
||||||
public String HeyLook = "I'm Inside!";
|
public String HeyLook = "I'm Inside!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Config(modid = MODID)
|
@Config(modid = MODID)
|
||||||
public static class CONFIG_ANNOTATIONS
|
public static class CONFIG_ANNOTATIONS
|
||||||
{
|
{
|
||||||
@RangeDouble(min = -10.5, max = 100.5)
|
@RangeDouble(min = -10.5, max = 100.5)
|
||||||
public static double DoubleRange = 10.0;
|
public static double DoubleRange = 10.0;
|
||||||
|
|
||||||
@RangeInt(min = -10, max = 100)
|
@RangeInt(min = -10, max = 100)
|
||||||
public static double IntRange = 10;
|
public static double IntRange = 10;
|
||||||
|
|
||||||
@LangKey("this.is.not.a.good.key")
|
@LangKey("this.is.not.a.good.key")
|
||||||
@Comment({"This is a really long", "Multi-line comment"})
|
@Comment({"This is a really long", "Multi-line comment"})
|
||||||
public static String Comments = "Hi Tv!";
|
public static String Comments = "Hi Tv!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue