Minor performance improvement in MassiveCoreEngineCommandRegistration
This commit is contained in:
parent
16c3a15cdc
commit
8dac1eeece
@ -1,5 +1,6 @@
|
||||
package com.massivecraft.massivecore;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -138,16 +139,18 @@ public class MassiveCoreEngineCommandRegistration extends EngineAbstract
|
||||
// GETTERS
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected static Field SERVER_DOT_COMMAND_MAP = ReflectionUtil.getField(Bukkit.getServer().getClass(), "commandMap");
|
||||
public static SimpleCommandMap getSimpleCommandMap()
|
||||
{
|
||||
Server server = Bukkit.getServer();
|
||||
return (SimpleCommandMap) ReflectionUtil.getField(server.getClass(), "commandMap", server);
|
||||
return (SimpleCommandMap) ReflectionUtil.getField(SERVER_DOT_COMMAND_MAP, server);
|
||||
}
|
||||
|
||||
protected static Field SIMPLE_COMMAND_MAP_DOT_KNOWN_COMMANDS = ReflectionUtil.getField(SimpleCommandMap.class, "knownCommands");
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Command> getSimpleCommandMapDotKnownCommands(SimpleCommandMap simpleCommandMap)
|
||||
{
|
||||
return (Map<String, Command>) ReflectionUtil.getField(SimpleCommandMap.class, "knownCommands", simpleCommandMap);
|
||||
return (Map<String, Command>) ReflectionUtil.getField(SIMPLE_COMMAND_MAP_DOT_KNOWN_COMMANDS, simpleCommandMap);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
@ -50,6 +50,38 @@ public class ReflectionUtil
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD GET
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Field getField(Class<?> clazz, String fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
makeAccessible(field);
|
||||
return field;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getField(Field field, Object object)
|
||||
{
|
||||
try
|
||||
{
|
||||
return field.get(object);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD SIMPLE: GET & SET & TRANSFER
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user