diff --git a/src/main/java/net/minecraft/network/rcon/RConThreadMain.java b/src/main/java/net/minecraft/network/rcon/RConThreadMain.java index 46c011a..0ca5e94 100644 --- a/src/main/java/net/minecraft/network/rcon/RConThreadMain.java +++ b/src/main/java/net/minecraft/network/rcon/RConThreadMain.java @@ -39,6 +39,7 @@ this.rconPort = this.serverPort + 10; this.logInfo("Setting default rcon port to " + this.rconPort); ConfigurationHandler.getServerConfig().vanilla.rconPort = rconPort; + par1IServer.saveProperties(); } if (0 == this.hostname.length()) diff --git a/src/main/java/net/minecraft/network/rcon/RConThreadQuery.java b/src/main/java/net/minecraft/network/rcon/RConThreadQuery.java index c1d37e9..4f9af56 100644 --- a/src/main/java/net/minecraft/network/rcon/RConThreadQuery.java +++ b/src/main/java/net/minecraft/network/rcon/RConThreadQuery.java @@ -80,6 +80,8 @@ this.queryPort = this.serverPort; this.logInfo("Setting default query port to " + this.queryPort); ConfigurationHandler.getServerConfig().vanilla.queryPort = queryPort; + par1IServer.setProperty("debug", Boolean.valueOf(false)); + par1IServer.saveProperties(); } this.field_72644_p = new HashMap(); diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java index ad681ec..712232d 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java @@ -58,6 +58,7 @@ { super.setWhiteListEnabled(par1); ConfigurationHandler.getServerConfig().vanilla.whiteList = par1; + this.getServerInstance().saveProperties(); } public void addOp(String par1Str) diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java index c304bc6..e2bf2e9 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java @@ -38,6 +38,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.UltramineServerConfig; import org.ultramine.server.UltramineServerConfig.VanillaConfig; @SideOnly(Side.SERVER) @@ -47,7 +48,7 @@ public final List pendingCommandList = Collections.synchronizedList(new ArrayList()); private RConThreadQuery theRConThreadQuery; private RConThreadMain theRConThreadMain; - private PropertyManager settings; + private VanillaConfig settings; private boolean canSpawnStructures; private WorldSettings.GameType gameType; private boolean guiIsEnabled; @@ -119,8 +120,7 @@ FMLCommonHandler.instance().onServerStart(this); field_155771_h.info("Loading properties"); - //this.settings = new PropertyManager(new File(ConfigurationHandler.getSettingDir(), "server.properties")); - VanillaConfig vconfig = ConfigurationHandler.getServerConfig().vanilla; + settings = ConfigurationHandler.getServerConfig().vanilla; if (this.isSinglePlayer()) { @@ -128,30 +128,30 @@ } else { - this.setOnlineMode(vconfig.onlineMode); - this.setHostname(vconfig.serverIp); + this.setOnlineMode(settings.onlineMode); + this.setHostname(settings.serverIp); } - this.setCanSpawnAnimals(vconfig.spawnAnimals); - this.setCanSpawnNPCs(vconfig.spawnNPCs); - this.setAllowPvp(vconfig.pvp); - this.setAllowFlight(vconfig.allowFlight); - this.func_155759_m(vconfig.resourcePack); - this.setMOTD(vconfig.motd); - this.setForceGamemode(vconfig.forceGamemode); - this.func_143006_e(vconfig.playerIdleTimeout); + this.setCanSpawnAnimals(settings.spawnAnimals); + this.setCanSpawnNPCs(settings.spawnNPCs); + this.setAllowPvp(settings.pvp); + this.setAllowFlight(settings.allowFlight); + this.func_155759_m(settings.resourcePack); + this.setMOTD(settings.motd); + this.setForceGamemode(settings.forceGamemode); + this.func_143006_e(settings.playerIdleTimeout); - if (vconfig.difficulty < 0) + if (settings.difficulty < 0) { - vconfig.difficulty = 0; + settings.difficulty = 0; } - else if (vconfig.difficulty > 3) + else if (settings.difficulty > 3) { - vconfig.difficulty = 3; + settings.difficulty = 3; } - this.canSpawnStructures = vconfig.generateStructures; - int i = vconfig.gamemode; + this.canSpawnStructures = settings.generateStructures; + int i = settings.gamemode; this.gameType = WorldSettings.getGameTypeById(i); field_155771_h.info("Default game type: " + this.gameType); InetAddress inetaddress = null; @@ -163,7 +163,7 @@ if (this.getServerPort() < 0) { - this.setServerPort(vconfig.serverPort); + this.setServerPort(settings.serverPort); } field_155771_h.info("Generating keypair"); @@ -197,12 +197,12 @@ if (this.getFolderName() == null) { - this.setFolderName(vconfig.levelName); + this.setFolderName(settings.levelName); } - String s = vconfig.levelSeed; - String s1 = vconfig.levelType; - String s2 = vconfig.generatorSettings; + String s = settings.levelSeed; + String s1 = settings.levelType; + String s2 = settings.generatorSettings; long k = (new Random()).nextLong(); if (s.length() > 0) @@ -233,10 +233,10 @@ this.isCommandBlockEnabled(); this.getOpPermissionLevel(); this.isSnooperEnabled(); - this.setBuildLimit(vconfig.maxBuildHeight); + this.setBuildLimit(settings.maxBuildHeight); this.setBuildLimit((this.getBuildLimit() + 8) / 16 * 16); this.setBuildLimit(MathHelper.clamp_int(this.getBuildLimit(), 64, 256)); - vconfig.maxBuildHeight = this.getBuildLimit(); + settings.maxBuildHeight = this.getBuildLimit(); if (!FMLCommonHandler.instance().handleServerAboutToStart(this)) { return false; } field_155771_h.info("Preparing level \"" + this.getFolderName() + "\""); this.loadAllWorlds(this.getFolderName(), this.getFolderName(), k, worldtype, s2); @@ -244,14 +244,14 @@ String s3 = String.format("%.3fs", new Object[] {Double.valueOf((double)i1 / 1.0E9D)}); field_155771_h.info("Done (" + s3 + ")! For help, type \"help\" or \"?\""); - if (vconfig.enableQuery) + if (settings.enableQuery) { field_155771_h.info("Starting GS4 status listener"); this.theRConThreadQuery = new RConThreadQuery(this); this.theRConThreadQuery.startThread(); } - if (vconfig.enableRcon) + if (settings.enableRcon) { field_155771_h.info("Starting remote control listener"); this.theRConThreadMain = new RConThreadMain(this); @@ -274,12 +274,12 @@ public EnumDifficulty func_147135_j() { - return EnumDifficulty.getDifficultyEnum(ConfigurationHandler.getServerConfig().vanilla.difficulty); + return EnumDifficulty.getDifficultyEnum(settings.difficulty); } public boolean isHardcore() { - return ConfigurationHandler.getServerConfig().vanilla.hardcore; + return settings.hardcore; } protected void finalTick(CrashReport par1CrashReport) @@ -335,12 +335,12 @@ public boolean getAllowNether() { - return ConfigurationHandler.getServerConfig().vanilla.allowNether; + return settings.allowNether; } public boolean allowSpawnMonsters() { - return ConfigurationHandler.getServerConfig().vanilla.spawnMonsters; + return settings.spawnMonsters; } public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper) @@ -352,7 +352,7 @@ public boolean isSnooperEnabled() { - return ConfigurationHandler.getServerConfig().vanilla.snooperEnabled; + return settings.snooperEnabled; } public void addPendingCommand(String par1Str, ICommandSender par2ICommandSender) @@ -381,28 +381,31 @@ public int getIntProperty(String par1Str, int par2) { - return this.settings.getIntProperty(par1Str, par2); + ConfigurationHandler.log.info("Unresolved server config parameter", new Throwable()); + return settings.unresolved.containsKey(par1Str) ? (Integer)settings.unresolved.get(par1Str) : par2; } public String getStringProperty(String par1Str, String par2Str) { - return this.settings.getStringProperty(par1Str, par2Str); + ConfigurationHandler.log.info("Unresolved server config parameter", new Throwable()); + return settings.unresolved.containsKey(par1Str) ? (String)settings.unresolved.get(par1Str) : par2Str; } public boolean getBooleanProperty(String par1Str, boolean par2) { - return this.settings.getBooleanProperty(par1Str, par2); + ConfigurationHandler.log.info("Unresolved server config parameter", new Throwable()); + return settings.unresolved.containsKey(par1Str) ? (Boolean)settings.unresolved.get(par1Str) : par2; } public void setProperty(String par1Str, Object par2Obj) { - this.settings.setProperty(par1Str, par2Obj); + ConfigurationHandler.log.info("Unresolved server config parameter", new Throwable()); + settings.unresolved.put(par1Str, par2Obj); } public void saveProperties() { ConfigurationHandler.saveServerConfig(); - //this.settings.saveProperties(); } public String getSettingsFilename() @@ -428,12 +431,12 @@ public boolean isCommandBlockEnabled() { - return ConfigurationHandler.getServerConfig().vanilla.enableCommandBlock; + return settings.enableCommandBlock; } public int getSpawnProtectionSize() { - return 0; + return getIntProperty("spawn-protection", super.getSpawnProtectionSize()); } public boolean isBlockProtected(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) @@ -466,18 +469,18 @@ public int getOpPermissionLevel() { - return 4; + return getIntProperty("op-permission-level", 4); } public void func_143006_e(int par1) { - ConfigurationHandler.getServerConfig().vanilla.playerIdleTimeout = par1; super.func_143006_e(par1); - //this.saveProperties(); + settings.playerIdleTimeout = par1; + this.saveProperties(); } public boolean func_147136_ar() { - return ConfigurationHandler.getServerConfig().vanilla.announcePlayerAchievements; + return settings.announcePlayerAchievements; } } \ No newline at end of file diff --git a/src/main/java/org/ultramine/server/ConfigurationHandler.java b/src/main/java/org/ultramine/server/ConfigurationHandler.java index 76d305e..68ae906 100644 --- a/src/main/java/org/ultramine/server/ConfigurationHandler.java +++ b/src/main/java/org/ultramine/server/ConfigurationHandler.java @@ -5,12 +5,16 @@ import java.io.FileWriter; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.yaml.snakeyaml.Yaml; import cpw.mods.fml.relauncher.FMLLaunchHandler; public class ConfigurationHandler { + public static Logger log = LogManager.getLogger(); + private static final Yaml YAML = new Yaml(); private static File settingsDir = new File(FMLLaunchHandler.getMinecraftHome(), "settings"); @@ -49,9 +53,7 @@ { saveConfig(serverConfigFile, serverConfig); } - - - + private static T getOrCreateConfig(File configFile, Class clazz) { T ret; @@ -61,11 +63,12 @@ try { ret = clazz.newInstance(); - } catch (Exception e) + } + catch (Exception e) { throw new RuntimeException("impossible exception", e); } - + saveConfig(configFile, ret); } else @@ -75,7 +78,8 @@ { reader = new FileReader(configFile); ret = YAML.loadAs(reader, clazz); - } catch (IOException e) + } + catch (IOException e) { throw new RuntimeException("Failed to read config: " + configFile.getPath(), e); } @@ -93,25 +97,23 @@ private static void saveConfig(File configFile, Object o) { - if(!configFile.exists()) + FileWriter writer = null; + try { - FileWriter writer = null; + configFile.createNewFile(); + writer = new FileWriter(configFile); + writer.write(YAML.dumpAsMap(o)); + } + catch (IOException e) + { + throw new RuntimeException("Failed to save default config: " + configFile.getPath(), e); + } + finally + { try { - configFile.createNewFile(); - writer = new FileWriter(configFile); - writer.write(YAML.dumpAsMap(0)); - } catch (IOException e) - { - throw new RuntimeException("Failed to save default config: " + configFile.getPath(), e); - } - finally - { - try - { - writer.close(); - } catch (IOException ignored) {} - } + writer.close(); + } catch (IOException ignored) {} } } } diff --git a/src/main/java/org/ultramine/server/UltramineServerConfig.java b/src/main/java/org/ultramine/server/UltramineServerConfig.java index b23626b..4c7d5ee 100644 --- a/src/main/java/org/ultramine/server/UltramineServerConfig.java +++ b/src/main/java/org/ultramine/server/UltramineServerConfig.java @@ -1,11 +1,13 @@ package org.ultramine.server; +import java.util.LinkedHashMap; +import java.util.Map; + public class UltramineServerConfig { public WatchdogThreadConfig watchdogThread = new WatchdogThreadConfig(); public VanillaConfig vanilla = new VanillaConfig(); - - + public static class WatchdogThreadConfig { public int timeout = 120; @@ -48,5 +50,7 @@ public int viewDistance = 10; public boolean generateStructures = true; public String motd = "A Minecraft Server"; + + public Map unresolved = new LinkedHashMap(); } }