Add /debug command. What can possibly go wrong.

This commit is contained in:
Steven Lawson 2013-07-28 20:50:57 -04:00
parent 6a4a11a2f4
commit 6b7a5d8d70
4 changed files with 97 additions and 56 deletions

View File

@ -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.VERSION=2.21
program.BUILDNUM=345 program.BUILDNUM=355
program.BUILDDATE=07/27/2013 04\:48 PM program.BUILDDATE=07/28/2013 08\:48 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sat Jul 27 16:48:23 EDT 2013 #Sun Jul 28 20:48:17 EDT 2013
build.number=346 build.number=356

View File

@ -1,7 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.lang.reflect.Field; 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -13,58 +14,98 @@ public class Command_debug extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
setStaticValue("me.StevenLawson.TotalFreedomMod.TotalFreedomMod", args[0], null); if (args.length < 3)
return true; {
} return false;
}
public static void setStaticValue(final String className, final String fieldName, final Object newValue)
{
try try
{ {
Class<?> forName = Class.forName(className); String className = args[0];
if (forName != null) String fieldName = args[1];
String newValue = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
if (className.equalsIgnoreCase("_"))
{ {
final Field field = forName.getDeclaredField(fieldName); className = "me.StevenLawson.TotalFreedomMod.TotalFreedomMod";
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);
}
} }
setStaticValue(className, fieldName, newValue);
sender.sendMessage("Debug: OK");
} }
catch (Exception ex) 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);
}
} }
} }
} }

View File

@ -221,11 +221,11 @@ public class TotalFreedomMod extends JavaPlugin
} }
// //
public static boolean allowFirePlace = false; public static boolean allowFirePlace = false;
public static Boolean allowFireSpread = false; public static boolean allowFireSpread = false;
public static Boolean allowLavaDamage = false; public static boolean allowLavaDamage = false;
public static boolean allowLavaPlace = false; public static boolean allowLavaPlace = false;
public static boolean allowWaterPlace = false; public static boolean allowWaterPlace = false;
public static Boolean allowExplosions = false; public static boolean allowExplosions = false;
public static boolean allowFliudSpread = false; public static boolean allowFliudSpread = false;
public static boolean allowTntMinecarts = false; public static boolean allowTntMinecarts = false;
public static double explosiveRadius = 4.0D; public static double explosiveRadius = 4.0D;
@ -236,9 +236,9 @@ public class TotalFreedomMod extends JavaPlugin
public static int nukeMonitorCountPlace = 25; public static int nukeMonitorCountPlace = 25;
public static double nukeMonitorRange = 10.0D; public static double nukeMonitorRange = 10.0D;
public static int freecamTriggerCount = 10; public static int freecamTriggerCount = 10;
public static Boolean preprocessLogEnabled = true; public static boolean preprocessLogEnabled = true;
public static Boolean disableNight = true; public static boolean disableNight = true;
public static Boolean disableWeather = true; public static boolean disableWeather = true;
public static boolean landminesEnabled = false; public static boolean landminesEnabled = false;
public static boolean mp44Enabled = false; public static boolean mp44Enabled = false;
public static boolean mobLimiterEnabled = true; public static boolean mobLimiterEnabled = true;