From 1304c11381a4d76884b21a1541deff11fb876d44 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sun, 17 Jan 2021 14:41:21 +0000 Subject: [PATCH] People don't listen to me, so let's spell it out to them --- .../java/electroblob/wizardry/Settings.java | 48 +++++++++++++++++++ .../client/gui/config/GuiConfigWizardry.java | 7 ++- .../assets/ebwizardry/lang/en_gb.lang | 2 + .../assets/ebwizardry/lang/en_us.lang | 2 + 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/main/java/electroblob/wizardry/Settings.java b/src/main/java/electroblob/wizardry/Settings.java index e015c61e..c1aacb55 100644 --- a/src/main/java/electroblob/wizardry/Settings.java +++ b/src/main/java/electroblob/wizardry/Settings.java @@ -93,6 +93,8 @@ public final class Settings { /** The wizardry config file. */ private Configuration config; + private List redundantKeys = new ArrayList<>(); + // Server-only settings. These only affect server-side code and hence are not synced. Changing these locally only // has an effect if the local game is the host, i.e. a dedicated server, a LAN host or a singleplayer world. @@ -446,6 +448,8 @@ public final class Settings { */ void initConfig(FMLPreInitializationEvent event){ + redundantKeys.clear(); + config = new Configuration(new File(Wizardry.configDirectory, Wizardry.MODID + ".cfg")); config.load(); @@ -484,6 +488,8 @@ public final class Settings { /** Called to save changes to the config file after it has been edited in game from the menus. */ void saveConfigChanges(){ + redundantKeys.clear(); + Wizardry.logger.info("Saving in-game config changes"); setupGameplayConfig(); @@ -500,6 +506,32 @@ public final class Settings { config.save(); } + void checkForRedundantOptions(String categoryName, Collection validKeys){ + + ConfigCategory category = config.getCategory(categoryName); + boolean redundantKeysFound = false; + + for(String key : category.keySet()){ + if(!validKeys.contains(key)){ + redundantKeys.add(key); + if(!redundantKeysFound){ + redundantKeysFound = true; + Wizardry.logger.info("Config category {} contains redundant options:", categoryName); + } + Wizardry.logger.info(key); + } + } + + if(redundantKeysFound){ + Wizardry.logger.info("These options will have no effect (they are probably left over from an older version of wizardry). It is recommended to either remove them manually, or delete ebwizardry.cfg and allow a fresh config to be generated."); + } + } + + /** Returns true if the config file contains keys that are not valid options (usually because of updates). */ + public boolean hasRedundantKeys(){ + return !redundantKeys.isEmpty(); + } + /** Sends a packet to the specified player's client containing all the synchronised settings. */ public void sync(EntityPlayerMP player){ Wizardry.logger.info("Synchronising config settings for " + player.getName()); @@ -518,7 +550,10 @@ public final class Settings { Property property; + List keys = new ArrayList<>(); + for(Spell spell : Spell.getAllSpells()){ + keys.add(spell.getRegistryName().toString()); property = config.get(SPELLS_CATEGORY, spell.getRegistryName().toString(), true, "Set to false to disable this spell"); // Uses the same config key as the spell name, because - well, that's what it's called! @@ -527,6 +562,7 @@ public final class Settings { spell.setEnabled(property.getBoolean(true)); } + checkForRedundantOptions(SPELLS_CATEGORY, keys); } private void setupArtefactsConfig(){ @@ -536,8 +572,11 @@ public final class Settings { Property property; + List keys = new ArrayList<>(); + for(Item item : Item.REGISTRY){ if(item instanceof ItemArtefact){ + keys.add(item.getRegistryName().toString()); property = config.get(ARTEFACTS_CATEGORY, item.getRegistryName().toString(), true, "Set to false to disable this item"); // Uses the same config key as the item name, because - well, that's what it's called! @@ -547,6 +586,7 @@ public final class Settings { } } + checkForRedundantOptions(ARTEFACTS_CATEGORY, keys); } private void setupGameplayConfig(){ @@ -623,6 +663,7 @@ public final class Settings { bonemealGrowsCrystalFlowers = property.getBoolean(); propOrder.add(property.getName()); + checkForRedundantOptions(GAMEPLAY_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(GAMEPLAY_CATEGORY, propOrder); } @@ -730,6 +771,7 @@ public final class Settings { lightningWraithSpawnRate = property.getInt(); propOrder.add(property.getName()); + checkForRedundantOptions(DIFFICULTY_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(DIFFICULTY_CATEGORY, propOrder); } @@ -872,6 +914,7 @@ public final class Settings { } } + checkForRedundantOptions(TWEAKS_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(TWEAKS_CATEGORY, propOrder); } @@ -1019,6 +1062,7 @@ public final class Settings { lootInjectionLocations = getResourceLocationList(property); propOrder.add(property.getName()); + checkForRedundantOptions(WORLDGEN_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(WORLDGEN_CATEGORY, propOrder); } @@ -1120,6 +1164,7 @@ public final class Settings { donationPerkElement = Element.fromName(property.getString(), null); // Fallback to null for no element propOrder.add(property.getName()); + checkForRedundantOptions(CLIENT_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(CLIENT_CATEGORY, propOrder); } @@ -1166,6 +1211,7 @@ public final class Settings { alliesCommandName = property.getString(); propOrder.add(property.getName()); + checkForRedundantOptions(COMMANDS_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(COMMANDS_CATEGORY, propOrder); } @@ -1243,6 +1289,7 @@ public final class Settings { } propOrder.add(property.getName()); + checkForRedundantOptions(RESISTANCES_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(RESISTANCES_CATEGORY, propOrder); } @@ -1332,6 +1379,7 @@ public final class Settings { autoUndergroundLibraryMarkers = property.getBoolean(); propOrder.add(property.getName()); + checkForRedundantOptions(COMPATIBILITY_CATEGORY, propOrder); // Must be before the order is set! config.setCategoryPropertyOrder(COMPATIBILITY_CATEGORY, propOrder); } diff --git a/src/main/java/electroblob/wizardry/client/gui/config/GuiConfigWizardry.java b/src/main/java/electroblob/wizardry/client/gui/config/GuiConfigWizardry.java index 1597d08d..6174ed79 100644 --- a/src/main/java/electroblob/wizardry/client/gui/config/GuiConfigWizardry.java +++ b/src/main/java/electroblob/wizardry/client/gui/config/GuiConfigWizardry.java @@ -1,5 +1,6 @@ package electroblob.wizardry.client.gui.config; +import com.mojang.realmsclient.gui.ChatFormatting; import electroblob.wizardry.Settings; import electroblob.wizardry.Wizardry; import net.minecraft.client.gui.GuiScreen; @@ -18,9 +19,13 @@ import java.util.List; public class GuiConfigWizardry extends GuiConfig { public GuiConfigWizardry(GuiScreen parent){ + super(parent, getConfigEntries(), Wizardry.MODID, false, false, Wizardry.NAME + " - " + I18n.format("config." + Wizardry.MODID + ".title.general")); - // this.titleLine2 = "File location: " + Wizardry.config.getConfigFile().getAbsolutePath(); + + if(Wizardry.settings.hasRedundantKeys()){ + this.titleLine2 = ChatFormatting.GOLD.toString() + I18n.format("config." + Wizardry.MODID + ".redundant_keys"); + } } private static List getConfigEntries(){ diff --git a/src/main/resources/assets/ebwizardry/lang/en_gb.lang b/src/main/resources/assets/ebwizardry/lang/en_gb.lang index a605c57d..88e9f180 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_gb.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_gb.lang @@ -1474,6 +1474,8 @@ commands.ebwizardry\:discoverspell.removespell=Removed %1$s from %2$s's spell di config.ebwizardry.title.general=Mod Options +config.ebwizardry.redundant_keys=Your config file contains redundant options, these will not do anything! [See log for details] + config.ebwizardry.generic.true=Enabled config.ebwizardry.generic.false=Disabled diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang index b315babb..7a123df4 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_us.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang @@ -1474,6 +1474,8 @@ commands.ebwizardry\:discoverspell.removespell=Removed %1$s from %2$s's spell di config.ebwizardry.title.general=Mod Options +config.ebwizardry.redundant_keys=Your config file contains redundant options, these will not do anything! [See log for details] + config.ebwizardry.generic.true=Enabled config.ebwizardry.generic.false=Disabled