Fix 1_16_R2 bukkit config reload error
- Refactored VersionParam to include patch version specification - Added ConstructorParam to cache constructors & get the default constructor.
This commit is contained in:
parent
f268b098a3
commit
e2a9fb1dc3
9 changed files with 146 additions and 25 deletions
|
|
@ -23,6 +23,7 @@ public class BukkitReflection extends ReflectionUtils {
|
|||
|
||||
@Override
|
||||
public boolean isCompatible(VersionParam versionParam) {
|
||||
return versionParam.min <= MINOR && MINOR <= versionParam.max;
|
||||
return versionParam.min.minor <= MINOR && versionParam.min.patch <= PATCH
|
||||
&& MINOR <= versionParam.max.minor && PATCH <= versionParam.max.patch;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ 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.exact;
|
||||
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;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -53,7 +53,7 @@ public class RCraftServer {
|
|||
fieldOf("console"),
|
||||
fieldOf("commandsConfiguration"),
|
||||
fieldOf("overrideAllCommandBlockCommands"),
|
||||
fieldOf("unrestrictedAdvancements", versionOf(12)),
|
||||
fieldOf("unrestrictedAdvancements", exact(12)),
|
||||
fieldOf("ignoreVanillaPermissions", min(13)),
|
||||
fieldOf("monsterSpawn"),
|
||||
fieldOf("animalSpawn"),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package net.frankheijden.serverutils.bukkit.reflection;
|
||||
|
||||
import static net.frankheijden.serverutils.bukkit.entities.BukkitReflection.MINOR;
|
||||
import static net.frankheijden.serverutils.bukkit.entities.BukkitReflection.PATCH;
|
||||
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
|
||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get;
|
||||
|
|
@ -9,6 +10,7 @@ import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get
|
|||
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.between;
|
||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.exact;
|
||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.max;
|
||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.min;
|
||||
|
||||
|
|
@ -18,6 +20,7 @@ import java.lang.reflect.Method;
|
|||
import java.util.Map;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||
import net.frankheijden.serverutils.common.reflection.VersionParam;
|
||||
|
||||
public class RDedicatedServer {
|
||||
|
||||
|
|
@ -50,8 +53,10 @@ public class RDedicatedServer {
|
|||
methodOf("setForceGamemode", boolean.class),
|
||||
methodOf("n", between(13, 15), boolean.class),
|
||||
methodOf("aZ", max(15)),
|
||||
methodOf("aZ", min(new VersionParam.Version(16, 2))),
|
||||
methodOf("i", min(16), boolean.class),
|
||||
methodOf("aY", min(16)));
|
||||
methodOf("aY", exact(new VersionParam.Version(16, 1))),
|
||||
methodOf("getCustomRegistry", min(new VersionParam.Version(16, 2))));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
|
@ -70,7 +75,14 @@ public class RDedicatedServer {
|
|||
Object options = get(fields, console, "options");
|
||||
|
||||
if (MINOR >= 13) {
|
||||
Object propertyManager = RDedicatedServerSettings.newInstance(options);
|
||||
Object propertyManager;
|
||||
if (MINOR >= 16 && PATCH >= 2) {
|
||||
propertyManager = RDedicatedServerSettings.newInstance(invoke(methods, console, "getCustomRegistry"),
|
||||
options);
|
||||
} else {
|
||||
propertyManager = RDedicatedServerSettings.newInstance(options);
|
||||
}
|
||||
|
||||
set(fields, console, "propertyManager", propertyManager);
|
||||
Object config = invoke(RDedicatedServerSettings.getMethods(), propertyManager, "getProperties");
|
||||
invoke(methods, console, "setPVP", getConfigValue(config, "pvp"));
|
||||
|
|
@ -78,16 +90,20 @@ public class RDedicatedServer {
|
|||
invoke(methods, console, "setMotd", getConfigValue(config, "motd"));
|
||||
invoke(methods, console, "setForceGamemode", getConfigValue(config, "forceGamemode"));
|
||||
|
||||
Object resourcePackHash;
|
||||
if (MINOR <= 15 || (MINOR == 16 && PATCH == 1)) {
|
||||
resourcePackHash = invoke(methods, console, "aZ");
|
||||
} else {
|
||||
resourcePackHash = invoke(methods, console, "aY");
|
||||
}
|
||||
invoke(methods, console, "setResourcePack", getConfigValue(config, "resourcePack"), resourcePackHash);
|
||||
|
||||
if (MINOR <= 15) {
|
||||
invoke(methods, console, "setSpawnAnimals", getConfigValue(config, "spawnAnimals"));
|
||||
invoke(methods, console, "setSpawnNPCs", getConfigValue(config, "spawnNpcs"));
|
||||
invoke(methods, console, "setResourcePack", getConfigValue(config, "resourcePack"),
|
||||
invoke(methods, console, "aZ"));
|
||||
invoke(methods, console, "n", getConfigValue(config, "enforceWhitelist"));
|
||||
set(fields, console, "o", getConfigValue(config, "gamemode"));
|
||||
} else {
|
||||
invoke(methods, console, "setResourcePack", getConfigValue(config, "resourcePack"),
|
||||
invoke(methods, console, "aY"));
|
||||
invoke(methods, console, "i", getConfigValue(config, "enforceWhitelist"));
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package net.frankheijden.serverutils.bukkit.reflection;
|
||||
|
||||
import static net.frankheijden.serverutils.common.reflection.ConstructorParam.constructorOf;
|
||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllConstructors;
|
||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||
|
|
@ -12,6 +16,7 @@ public class RDedicatedServerSettings {
|
|||
|
||||
private static Class<?> serverSettingsClass;
|
||||
private static Map<String, Method> methods;
|
||||
private static List<Constructor<?>> constructors;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -19,13 +24,32 @@ public class RDedicatedServerSettings {
|
|||
BukkitReflection.NMS));
|
||||
methods = getAllMethods(serverSettingsClass,
|
||||
methodOf("getProperties"));
|
||||
constructors = getAllConstructors(serverSettingsClass,
|
||||
constructorOf(Class.forName("joptsimple.OptionSet")),
|
||||
constructorOf(Class.forName(String.format("net.minecraft.server.%s.IRegistryCustom",
|
||||
BukkitReflection.NMS)), Class.forName("joptsimple.OptionSet")));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object newInstance(Object options)throws ReflectiveOperationException {
|
||||
return serverSettingsClass.getDeclaredConstructor(Class.forName("joptsimple.OptionSet")).newInstance(options);
|
||||
/**
|
||||
* Retrieves the default constructor.
|
||||
* @return The default constructor of DedicatedServerSettings.
|
||||
* @throws NoSuchMethodException If no constructor was found.
|
||||
*/
|
||||
public static Constructor<?> getConstructor() throws NoSuchMethodException {
|
||||
if (constructors.size() == 0) throw new NoSuchMethodException("No constructor found for "
|
||||
+ serverSettingsClass.getName());
|
||||
return constructors.get(0);
|
||||
}
|
||||
|
||||
public static Object newInstance(Object options) throws ReflectiveOperationException {
|
||||
return getConstructor().newInstance(options);
|
||||
}
|
||||
|
||||
public static Object newInstance(Object registry, Object options) throws ReflectiveOperationException {
|
||||
return getConstructor().newInstance(registry, options);
|
||||
}
|
||||
|
||||
public static Map<String, Method> getMethods() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue