Fix partial server.properties reloading on MC <= 13

This commit is contained in:
Frank van der Heijden 2021-01-29 23:16:17 +01:00
parent 2dcc4f36ee
commit ab12728063
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
2 changed files with 15 additions and 11 deletions

View file

@ -3,10 +3,10 @@ package net.frankheijden.serverutils.bukkit.reflection;
import dev.frankheijden.minecraftreflection.ClassObject; import dev.frankheijden.minecraftreflection.ClassObject;
import dev.frankheijden.minecraftreflection.MinecraftReflection; import dev.frankheijden.minecraftreflection.MinecraftReflection;
import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion; import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Path;
import java.util.Properties; import java.util.Properties;
public class RDedicatedServer { public class RDedicatedServer {
@ -80,12 +80,19 @@ public class RDedicatedServer {
*/ */
public static void reloadServerProperties() { public static void reloadServerProperties() {
Object console = RCraftServer.getConsole(); Object console = RCraftServer.getConsole();
Object playerList = RMinecraftServer.getReflection().get(console, "playerList"); Object playerList = RMinecraftServer.getReflection().get(console, MinecraftReflectionVersion.MINOR >= 13
? "playerList"
: "v");
Object propertyManager = reflection.get(console, "propertyManager"); Object propertyManager = reflection.get(console, "propertyManager");
Path path = RDedicatedServerSettings.getServerPropertiesPath(propertyManager); File file;
if (MinecraftReflectionVersion.MINOR >= 14) {
file = RDedicatedServerSettings.getServerPropertiesPath(propertyManager).toFile();
} else {
file = RPropertyManager.getReflection().get(propertyManager, "file");
}
Properties properties = new Properties(); Properties properties = new Properties();
try (InputStream in = new FileInputStream(path.toFile())) { try (InputStream in = new FileInputStream(file)) {
properties.load(in); properties.load(in);
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException("Unable to load server.properties", ex); throw new RuntimeException("Unable to load server.properties", ex);
@ -95,7 +102,10 @@ public class RDedicatedServer {
RPlayerList.getReflection().set(playerList, "maxPlayers", maxPlayers); RPlayerList.getReflection().set(playerList, "maxPlayers", maxPlayers);
int viewDistance = Integer.parseInt(properties.getProperty("view-distance")); int viewDistance = Integer.parseInt(properties.getProperty("view-distance"));
RPlayerList.setViewDistance(playerList, viewDistance); if (MinecraftReflectionVersion.MINOR >= 14) {
RPlayerList.getReflection().set(playerList, "viewDistance", viewDistance);
}
RPlayerList.getReflection().invoke(playerList, "a", ClassObject.of(int.class, viewDistance));
} }
public static Object getConfigValue(Object config, String key) { public static Object getConfigValue(Object config, String key) {

View file

@ -1,6 +1,5 @@
package net.frankheijden.serverutils.bukkit.reflection; package net.frankheijden.serverutils.bukkit.reflection;
import dev.frankheijden.minecraftreflection.ClassObject;
import dev.frankheijden.minecraftreflection.MinecraftReflection; import dev.frankheijden.minecraftreflection.MinecraftReflection;
public class RPlayerList { public class RPlayerList {
@ -11,9 +10,4 @@ public class RPlayerList {
public static MinecraftReflection getReflection() { public static MinecraftReflection getReflection() {
return reflection; return reflection;
} }
public static void setViewDistance(Object instance, int viewDistance) {
reflection.set(instance, "viewDistance", viewDistance);
reflection.invoke(instance, "a", ClassObject.of(int.class, viewDistance));
}
} }