Skip to content

Commit 07f4bf8

Browse files
committed
Incomplete - /debug command
1 parent 1ab74da commit 07f4bf8

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package me.StevenLawson.TotalFreedomMod.Commands;
2+
3+
import java.lang.reflect.Field;
4+
import me.StevenLawson.TotalFreedomMod.TFM_Log;
5+
import org.bukkit.command.Command;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.entity.Player;
8+
9+
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
10+
@CommandParameters(description = "For developers only - debug things via reflection.", usage = "/<command>")
11+
public class Command_debug extends TFM_Command
12+
{
13+
@Override
14+
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
15+
{
16+
setStaticValue("me.StevenLawson.TotalFreedomMod.TotalFreedomMod", args[0], null);
17+
return true;
18+
}
19+
20+
public static void setStaticValue(final String className, final String fieldName, final Object newValue)
21+
{
22+
try
23+
{
24+
Class<?> forName = Class.forName(className);
25+
if (forName != null)
26+
{
27+
final Field field = forName.getDeclaredField(fieldName);
28+
if (field != null)
29+
{
30+
Class<?> type = field.getType();
31+
32+
TFM_Log.info("type.toString() = " + type.toString() + ", type.isPrimitive() = " + type.isPrimitive());
33+
34+
// TFM_Log.info(type.toString());
35+
//
36+
// if (Boolean.class.isAssignableFrom(type))
37+
// {
38+
// TFM_Log.info("boolean");
39+
// }
40+
// else if (Integer.class.isAssignableFrom(type))
41+
// {
42+
// TFM_Log.info("integer");
43+
// }
44+
// else if (Double.class.isAssignableFrom(type))
45+
// {
46+
// TFM_Log.info("double");
47+
// }
48+
// else if (String.class.isAssignableFrom(type))
49+
// {
50+
// TFM_Log.info("string");
51+
// }
52+
53+
// field.setAccessible(true);
54+
//
55+
// final Object oldValue = field.get(Class.forName(className));
56+
// if (oldValue != null)
57+
// {
58+
// field.set(oldValue, newValue);
59+
// }
60+
//
61+
// field.setAccessible(false);
62+
}
63+
}
64+
}
65+
catch (Exception ex)
66+
{
67+
TFM_Log.severe(ex);
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)