diff --git a/appinfo.properties b/appinfo.properties index 713fee60..f5ba9de1 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,6 +1,6 @@ -#Sat, 27 Jul 2013 16:48:23 -0400 +#Sun, 28 Jul 2013 20:48:17 -0400 program.VERSION=2.21 -program.BUILDNUM=345 -program.BUILDDATE=07/27/2013 04\:48 PM +program.BUILDNUM=355 +program.BUILDDATE=07/28/2013 08\:48 PM diff --git a/buildnumber.properties b/buildnumber.properties index 6bb47401..3d573ea1 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sat Jul 27 16:48:23 EDT 2013 -build.number=346 +#Sun Jul 28 20:48:17 EDT 2013 +build.number=356 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java index 13b6e346..ac19f281 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java @@ -1,7 +1,8 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.lang.reflect.Field; -import me.StevenLawson.TotalFreedomMod.TFM_Log; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,58 +14,98 @@ public class Command_debug extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - setStaticValue("me.StevenLawson.TotalFreedomMod.TotalFreedomMod", args[0], null); - return true; - } + if (args.length < 3) + { + return false; + } - public static void setStaticValue(final String className, final String fieldName, final Object newValue) - { try { - Class forName = Class.forName(className); - if (forName != null) + String className = args[0]; + String fieldName = args[1]; + String newValue = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " "); + + if (className.equalsIgnoreCase("_")) { - final Field field = forName.getDeclaredField(fieldName); - if (field != null) - { - Class type = field.getType(); - - TFM_Log.info("type.toString() = " + type.toString() + ", type.isPrimitive() = " + type.isPrimitive()); - -// TFM_Log.info(type.toString()); -// -// if (Boolean.class.isAssignableFrom(type)) -// { -// TFM_Log.info("boolean"); -// } -// else if (Integer.class.isAssignableFrom(type)) -// { -// TFM_Log.info("integer"); -// } -// else if (Double.class.isAssignableFrom(type)) -// { -// TFM_Log.info("double"); -// } -// else if (String.class.isAssignableFrom(type)) -// { -// TFM_Log.info("string"); -// } - -// field.setAccessible(true); -// -// final Object oldValue = field.get(Class.forName(className)); -// if (oldValue != null) -// { -// field.set(oldValue, newValue); -// } -// -// field.setAccessible(false); - } + className = "me.StevenLawson.TotalFreedomMod.TotalFreedomMod"; } + + setStaticValue(className, fieldName, newValue); + + sender.sendMessage("Debug: OK"); } catch (Exception ex) { - TFM_Log.severe(ex); + sender.sendMessage(ex.getMessage()); + } + + return true; + } + + public static void setStaticValue(final String className, final String fieldName, final String newValueString) throws Exception + { + Class forName = Class.forName(className); + if (forName != null) + { + final Field field = forName.getDeclaredField(fieldName); + if (field != null) + { + Object newValue; + + Class type = field.getType(); + if (type.isPrimitive()) + { + if (type.getName().equals("int")) + { + newValue = Integer.parseInt(newValueString); + } + else if (type.getName().equals("double")) + { + newValue = Double.parseDouble(newValueString); + } + else if (type.getName().equals("boolean")) + { + newValue = Boolean.parseBoolean(newValueString); + } + else + { + throw new Exception("Unknown primitive field type."); + } + } + else + { + if (type.isAssignableFrom(Integer.class)) + { + newValue = new Integer(newValueString); + } + else if (type.isAssignableFrom(Double.class)) + { + newValue = new Double(newValueString); + } + else if (type.isAssignableFrom(Boolean.class)) + { + newValue = Boolean.valueOf(newValueString); + } + else if (type.isAssignableFrom(String.class)) + { + newValue = newValueString; + } + else + { + throw new Exception("Unknown complex field type."); + } + } + + field.setAccessible(true); + + final Object oldValue = field.get(Class.forName(className)); + if (oldValue != null) + { + field.set(oldValue, newValue); + } + + field.setAccessible(false); + } } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 636fa21a..f7ae94d4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -221,11 +221,11 @@ public class TotalFreedomMod extends JavaPlugin } // public static boolean allowFirePlace = false; - public static Boolean allowFireSpread = false; - public static Boolean allowLavaDamage = false; + public static boolean allowFireSpread = false; + public static boolean allowLavaDamage = false; public static boolean allowLavaPlace = false; public static boolean allowWaterPlace = false; - public static Boolean allowExplosions = false; + public static boolean allowExplosions = false; public static boolean allowFliudSpread = false; public static boolean allowTntMinecarts = false; public static double explosiveRadius = 4.0D; @@ -236,9 +236,9 @@ public class TotalFreedomMod extends JavaPlugin public static int nukeMonitorCountPlace = 25; public static double nukeMonitorRange = 10.0D; public static int freecamTriggerCount = 10; - public static Boolean preprocessLogEnabled = true; - public static Boolean disableNight = true; - public static Boolean disableWeather = true; + public static boolean preprocessLogEnabled = true; + public static boolean disableNight = true; + public static boolean disableWeather = true; public static boolean landminesEnabled = false; public static boolean mp44Enabled = false; public static boolean mobLimiterEnabled = true;