Cleanup reflection parameters

This commit is contained in:
Frank van der Heijden 2020-07-06 12:05:18 +02:00
parent 578f4e1b9e
commit e5038fce31
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
20 changed files with 73 additions and 131 deletions

View file

@ -9,7 +9,6 @@ import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getDeclaredMethod;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.invoke;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.set;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import static net.frankheijden.serverutils.common.reflection.VersionParam.max;
import static net.frankheijden.serverutils.common.reflection.VersionParam.min;
import static net.frankheijden.serverutils.common.reflection.VersionParam.versionOf;
@ -50,24 +49,24 @@ public class RCraftServer {
commandMap = (SimpleCommandMap) getDeclaredField(craftServerClass, "commandMap").get(Bukkit.getServer());
fields = getAllFields(craftServerClass,
fieldOf("configuration", ALL_VERSIONS),
fieldOf("console", ALL_VERSIONS),
fieldOf("commandsConfiguration", ALL_VERSIONS),
fieldOf("overrideAllCommandBlockCommands", ALL_VERSIONS),
fieldOf("configuration"),
fieldOf("console"),
fieldOf("commandsConfiguration"),
fieldOf("overrideAllCommandBlockCommands"),
fieldOf("unrestrictedAdvancements", versionOf(12)),
fieldOf("ignoreVanillaPermissions", min(13)),
fieldOf("monsterSpawn", ALL_VERSIONS),
fieldOf("animalSpawn", ALL_VERSIONS),
fieldOf("waterAnimalSpawn", ALL_VERSIONS),
fieldOf("ambientSpawn", ALL_VERSIONS),
fieldOf("warningState", ALL_VERSIONS),
fieldOf("monsterSpawn"),
fieldOf("animalSpawn"),
fieldOf("waterAnimalSpawn"),
fieldOf("ambientSpawn"),
fieldOf("warningState"),
fieldOf("minimumAPI", min(14)),
fieldOf("printSaveWarning", ALL_VERSIONS),
fieldOf("printSaveWarning"),
fieldOf("chunkGCPeriod", max(12)),
fieldOf("chunkGCLoadThresh", max(12)),
fieldOf("playerList", ALL_VERSIONS));
fieldOf("playerList"));
methods = getAllMethods(craftServerClass,
methodOf("loadIcon", ALL_VERSIONS));
methodOf("loadIcon"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -8,7 +8,6 @@ import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.invoke;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.set;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import static net.frankheijden.serverutils.common.reflection.VersionParam.min;
import java.lang.reflect.Field;
@ -30,23 +29,23 @@ public class RDedicatedServer {
BukkitReflection.NMS));
fields = getAllFields(dedicatedServerClass,
fieldOf("propertyManager", ALL_VERSIONS),
fieldOf("options", ALL_VERSIONS),
fieldOf("autosavePeriod", ALL_VERSIONS),
fieldOf("propertyManager"),
fieldOf("options"),
fieldOf("autosavePeriod"),
fieldOf("o", min(13)));
methods = getAllMethods(dedicatedServerClass,
methodOf("setSpawnAnimals", ALL_VERSIONS, boolean.class),
methodOf("getSpawnAnimals", ALL_VERSIONS),
methodOf("setPVP", ALL_VERSIONS, boolean.class),
methodOf("getPVP", ALL_VERSIONS),
methodOf("setAllowFlight", ALL_VERSIONS, boolean.class),
methodOf("getAllowFlight", ALL_VERSIONS),
methodOf("setMotd", ALL_VERSIONS, String.class),
methodOf("getMotd", ALL_VERSIONS),
methodOf("setSpawnNPCs", ALL_VERSIONS, boolean.class),
methodOf("setAllowFlight", ALL_VERSIONS, boolean.class),
methodOf("setResourcePack", ALL_VERSIONS, String.class, String.class),
methodOf("setForceGamemode", ALL_VERSIONS, boolean.class),
methodOf("setSpawnAnimals", boolean.class),
methodOf("getSpawnAnimals"),
methodOf("setPVP", boolean.class),
methodOf("getPVP"),
methodOf("setAllowFlight", boolean.class),
methodOf("getAllowFlight"),
methodOf("setMotd", String.class),
methodOf("getMotd"),
methodOf("setSpawnNPCs", boolean.class),
methodOf("setAllowFlight", boolean.class),
methodOf("setResourcePack", String.class, String.class),
methodOf("setForceGamemode", boolean.class),
methodOf("n", min(13), boolean.class));
} catch (Exception ex) {
ex.printStackTrace();

View file

@ -2,7 +2,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Field;
import java.util.Map;
@ -19,15 +18,15 @@ public class RDedicatedServerProperties {
serverPropertiesClass = Class.forName(String.format("net.minecraft.server.%s.DedicatedServerProperties",
BukkitReflection.NMS));
fields = getAllFields(serverPropertiesClass,
fieldOf("spawnAnimals", ALL_VERSIONS),
fieldOf("spawnNpcs", ALL_VERSIONS),
fieldOf("pvp", ALL_VERSIONS),
fieldOf("allowFlight", ALL_VERSIONS),
fieldOf("resourcePack", ALL_VERSIONS),
fieldOf("motd", ALL_VERSIONS),
fieldOf("forceGamemode", ALL_VERSIONS),
fieldOf("enforceWhitelist", ALL_VERSIONS),
fieldOf("gamemode", ALL_VERSIONS));
fieldOf("spawnAnimals"),
fieldOf("spawnNpcs"),
fieldOf("pvp"),
fieldOf("allowFlight"),
fieldOf("resourcePack"),
fieldOf("motd"),
fieldOf("forceGamemode"),
fieldOf("enforceWhitelist"),
fieldOf("gamemode"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -2,7 +2,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Method;
import java.util.Map;
@ -19,7 +18,7 @@ public class RDedicatedServerSettings {
serverSettingsClass = Class.forName(String.format("net.minecraft.server.%s.DedicatedServerSettings",
BukkitReflection.NMS));
methods = getAllMethods(serverSettingsClass,
methodOf("getProperties", ALL_VERSIONS));
methodOf("getProperties"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.invoke;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
@ -21,8 +20,8 @@ public class RJavaPlugin {
try {
javaPluginClass = JavaPlugin.class;
methods = getAllMethods(javaPluginClass,
methodOf("getClassLoader", ALL_VERSIONS),
methodOf("getFile", ALL_VERSIONS));
methodOf("getClassLoader"),
methodOf("getFile"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.invoke;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -20,7 +19,7 @@ public class RJsonList {
try {
jsonListClass = Class.forName(String.format("net.minecraft.server.%s.JsonList", BukkitReflection.NMS));
methods = getAllMethods(jsonListClass,
methodOf("load", ALL_VERSIONS));
methodOf("load"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -2,7 +2,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Method;
import java.util.Map;
@ -19,8 +18,8 @@ public class RMinecraftServer {
minecraftServerClass = Class.forName(String.format("net.minecraft.server.%s.MinecraftServer",
BukkitReflection.NMS));
methods = getAllMethods(minecraftServerClass,
methodOf("getServer", ALL_VERSIONS),
methodOf("getCraftingManager", ALL_VERSIONS));
methodOf("getServer"),
methodOf("getCraftingManager"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -2,7 +2,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Method;
import java.util.Map;
@ -16,7 +15,7 @@ public class ROptionSet {
try {
optionSetClass = Class.forName("joptsimple.OptionSet");
methods = getAllMethods(optionSetClass,
methodOf("valueOf", ALL_VERSIONS, String.class));
methodOf("valueOf", String.class));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -2,7 +2,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Method;
import java.util.Map;
@ -18,8 +17,8 @@ public class RPlayerList {
try {
playerListClass = Class.forName(String.format("net.minecraft.server.%s.PlayerList", BukkitReflection.NMS));
methods = getAllMethods(playerListClass,
methodOf("getIPBans", ALL_VERSIONS),
methodOf("getProfileBans", ALL_VERSIONS));
methodOf("getIPBans"),
methodOf("getProfileBans"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -1,27 +0,0 @@
package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getDeclaredMethod;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class RPlugin {
private static Method getFile;
static {
try {
getFile = getDeclaredMethod(JavaPlugin.class, "getFile");
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static File getPluginFile(Plugin plugin) throws InvocationTargetException, IllegalAccessException {
return (File) getFile.invoke(plugin);
}
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.set;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.io.Closeable;
import java.lang.reflect.Field;
@ -18,8 +17,8 @@ public class RPluginClassLoader {
try {
pluginClassLoaderClass = Class.forName("org.bukkit.plugin.java.PluginClassLoader");
fields = getAllFields(pluginClassLoaderClass,
fieldOf("plugin", ALL_VERSIONS),
fieldOf("pluginInit", ALL_VERSIONS));
fieldOf("plugin"),
fieldOf("pluginInit"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -2,7 +2,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Method;
import java.util.Map;
@ -19,8 +18,8 @@ public class RPropertyManager {
propertyManagerClass = Class.forName(String.format("net.minecraft.server.%s.PropertyManager",
BukkitReflection.NMS));
methods = getAllMethods(propertyManagerClass,
methodOf("getBoolean", ALL_VERSIONS, String.class, boolean.class),
methodOf("getString", ALL_VERSIONS, String.class, String.class));
methodOf("getBoolean", String.class, boolean.class),
methodOf("getString", String.class, String.class));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Field;
import java.util.Map;
@ -24,7 +23,7 @@ public class RRegistryMaterials {
registryMaterialsClass = Class.forName(String.format("net.minecraft.server.%s.RegistryMaterials",
BukkitReflection.NMS));
fields = getAllFields(registryMaterialsClass,
fieldOf("b", ALL_VERSIONS));
fieldOf("b"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Field;
import java.util.Map;
@ -23,7 +22,7 @@ public class RRegistrySimple {
registrySimpleClass = Class.forName(String.format("net.minecraft.server.%s.RegistrySimple",
BukkitReflection.NMS));
fields = getAllFields(registrySimpleClass,
fieldOf("c", ALL_VERSIONS));
fieldOf("c"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bukkit.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Field;
import java.util.List;
@ -24,9 +23,9 @@ public class RSimplePluginManager {
try {
simplePluginManagerClass = SimplePluginManager.class;
fields = getAllFields(simplePluginManagerClass,
fieldOf("plugins", ALL_VERSIONS),
fieldOf("lookupNames", ALL_VERSIONS),
fieldOf("fileAssociations", ALL_VERSIONS));
fieldOf("plugins"),
fieldOf("lookupNames"),
fieldOf("fileAssociations"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -1,27 +0,0 @@
package net.frankheijden.serverutils.bungee.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Field;
import java.util.Map;
public class RPlugin {
private static Class<?> pluginClass;
private static Map<String, Field> fields;
static {
try {
pluginClass = Class.forName("net.md_5.bungee.api.plugin.Plugin");
fields = getAllFields(pluginClass,
fieldOf("plugins", ALL_VERSIONS),
fieldOf("toLoad", ALL_VERSIONS),
fieldOf("commandsByPlugin", ALL_VERSIONS),
fieldOf("listenersByPlugin", ALL_VERSIONS));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bungee.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@ -27,8 +26,8 @@ public class RPluginClassLoader {
constructor = loaderClass.getDeclaredConstructor(ProxyServer.class, PluginDescription.class, URL[].class);
constructor.setAccessible(true);
fields = getAllFields(loaderClass,
fieldOf("allLoaders", ALL_VERSIONS),
fieldOf("plugin", ALL_VERSIONS));
fieldOf("allLoaders"),
fieldOf("plugin"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.bungee.reflection;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import com.google.common.collect.Multimap;
@ -24,11 +23,11 @@ public class RPluginManager {
try {
pluginManagerClass = Class.forName("net.md_5.bungee.api.plugin.PluginManager");
fields = getAllFields(pluginManagerClass,
fieldOf("yaml", ALL_VERSIONS),
fieldOf("plugins", ALL_VERSIONS),
fieldOf("commandMap", ALL_VERSIONS),
fieldOf("toLoad", ALL_VERSIONS),
fieldOf("commandsByPlugin", ALL_VERSIONS));
fieldOf("yaml"),
fieldOf("plugins"),
fieldOf("commandMap"),
fieldOf("toLoad"),
fieldOf("commandsByPlugin"));
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -1,5 +1,7 @@
package net.frankheijden.serverutils.common.reflection;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
public class FieldParam {
public String field;
public VersionParam versionParam;
@ -12,4 +14,8 @@ public class FieldParam {
public static FieldParam fieldOf(String field, VersionParam versionParam) {
return new FieldParam(field, versionParam);
}
public static FieldParam fieldOf(String field) {
return fieldOf(field, ALL_VERSIONS);
}
}

View file

@ -1,5 +1,7 @@
package net.frankheijden.serverutils.common.reflection;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
public class MethodParam {
public String method;
@ -15,4 +17,8 @@ public class MethodParam {
public static MethodParam methodOf(String method, VersionParam versionParam, Class<?>... params) {
return new MethodParam(method, versionParam, params);
}
public static MethodParam methodOf(String method, Class<?>... params) {
return methodOf(method, ALL_VERSIONS, params);
}
}