mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-12-27 20:27:37 +00:00
Add /debug command. What can possibly go wrong.
This commit is contained in:
parent
6a4a11a2f4
commit
6b7a5d8d70
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user