diff --git a/src/main/java/foxz/command/CmdConfig.java b/src/main/java/foxz/command/CmdConfig.java index 6dc4acf7e..14759fd78 100644 --- a/src/main/java/foxz/command/CmdConfig.java +++ b/src/main/java/foxz/command/CmdConfig.java @@ -3,6 +3,7 @@ package foxz.command; import java.util.Arrays; import java.util.Set; +import jdk.nashorn.internal.runtime.regexp.joni.Config; import net.minecraft.block.Block; import net.minecraft.block.BlockIce; import net.minecraft.block.BlockLeavesBase; @@ -42,7 +43,10 @@ public class CmdConfig extends ChMcLogger { } else{ ConfigMain.LeavesDecayEnabled = Boolean.parseBoolean(args[0]); - // CustomNpcs.Config.updateConfig(); + ConfigMain.LeavesDecayEnabledProperty.set(ConfigMain.LeavesDecayEnabled); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } Set names = Block.blockRegistry.getKeys(); for(String name : names){ Block block = (Block) Block.blockRegistry.getObject(name); @@ -67,7 +71,10 @@ public class CmdConfig extends ChMcLogger { } else{ ConfigMain.VineGrowthEnabled = Boolean.parseBoolean(args[0]); - // CustomNpcs.Config.updateConfig(); + ConfigMain.VineGrowthEnabledProperty.set(ConfigMain.VineGrowthEnabled); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } Set names = Block.blockRegistry.getKeys(); for(String name : names){ Block block = (Block) Block.blockRegistry.getObject(name); @@ -92,7 +99,10 @@ public class CmdConfig extends ChMcLogger { } else{ ConfigMain.IceMeltsEnabled = Boolean.parseBoolean(args[0]); - // CustomNpcs.Config.updateConfig(); + ConfigMain.IceMeltsEnabledProperty.set(ConfigMain.IceMeltsEnabled); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } Set names = Block.blockRegistry.getKeys(); for(String name : names){ Block block = (Block) Block.blockRegistry.getObject(name); @@ -117,7 +127,10 @@ public class CmdConfig extends ChMcLogger { } else{ ConfigMain.GunsEnabled = Boolean.parseBoolean(args[0]); - // CustomNpcs.Config.updateConfig(); + ConfigMain.GunsEnabledProperty.set(ConfigMain.GunsEnabled); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } sendmessage("GunsEnabled is now " + ConfigMain.GunsEnabled); } return true; @@ -158,8 +171,11 @@ public class CmdConfig extends ChMcLogger { sendmessage("Didnt get a number"); return false; } - // CustomNpcs.Config.updateConfig(); - + + ConfigMain.ChunkLoadersProperty.set(ConfigMain.ChunkLoaders); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } int size = ChunkController.instance.size(); if(size > ConfigMain.ChunkLoaders){ ChunkController.instance.unload(size - ConfigMain.ChunkLoaders); diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index fbbe732ab..ad570f9c5 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -22,6 +22,7 @@ import net.minecraftforge.common.MinecraftForge; import nikedemos.markovnames.generators.*; import noppes.npcs.config.LoadConfiguration; import noppes.npcs.config.ConfigMain; +import noppes.npcs.config.legacy.LegacyConfig; import noppes.npcs.controllers.*; import noppes.npcs.enchants.EnchantInterface; import noppes.npcs.entity.*; @@ -29,6 +30,7 @@ import noppes.npcs.entity.old.*; import noppes.npcs.scripted.NpcAPI; import java.io.File; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Set; import java.util.UUID; @@ -68,6 +70,10 @@ public class CustomNpcs { public static boolean TimerIgnore = false; public static String configPath; + public static String legacyPath; + public static boolean legacyExist; + + public static LegacyConfig legacyConfig; public CustomNpcs() { instance = this; @@ -88,7 +94,21 @@ public class CustomNpcs { Dir = new File(dir, "customnpcs"); Dir.mkdir(); - configPath = ev.getModConfigurationDirectory() + "/CustomNPCPlus/"; + configPath = ev.getModConfigurationDirectory() + File.separator + "CustomNpcPlus"; + legacyPath = ev.getModConfigurationDirectory() + "/CustomNpcs.cfg"; + + File configDir = new File(configPath); + if(!configDir.exists()){ + // Convert Legacy Config to New Config if NO Config Folder Exists + File legacyFile = new File(legacyPath); + if(legacyFile.exists()){ + System.out.println("Loading Legacy Client"); + legacyExist = true; + legacyConfig = new LegacyConfig(); + legacyConfig.init(); + } + } + configPath += File.separator; LoadConfiguration.init(configPath); EnchantInterface.load(); diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index bba5a503a..1eb243c20 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -38,6 +38,7 @@ import noppes.npcs.client.gui.util.IGuiData; import noppes.npcs.client.gui.util.IGuiError; import noppes.npcs.client.gui.util.IScrollData; import noppes.npcs.config.ConfigClient; +import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.controllers.data.RecipeCarpentry; @@ -252,7 +253,13 @@ public class PacketHandlerClient extends PacketHandlerServer{ ConfigClient.FontType = font; ConfigClient.FontSize = size; ClientProxy.Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize); - // CustomNpcs.Config.updateConfig(); + + ConfigClient.FontTypeProperty.set(ConfigClient.FontType); + ConfigClient.FontSizeProperty.set(ConfigClient.FontSize); + if(ConfigClient.config.hasChanged()){ + ConfigClient.config.save(); + } + player.addChatMessage(new ChatComponentTranslation("Font set to %s", ClientProxy.Font.getName())); } else diff --git a/src/main/java/noppes/npcs/config/ConfigClient.java b/src/main/java/noppes/npcs/config/ConfigClient.java index 4801341d2..5b72dab8f 100644 --- a/src/main/java/noppes/npcs/config/ConfigClient.java +++ b/src/main/java/noppes/npcs/config/ConfigClient.java @@ -2,6 +2,9 @@ package noppes.npcs.config; import cpw.mods.fml.common.FMLLog; import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import noppes.npcs.CustomNpcs; +import noppes.npcs.config.legacy.LegacyConfig; import org.apache.logging.log4j.Level; import java.io.File; @@ -10,20 +13,39 @@ public class ConfigClient { public static Configuration config; + public final static String VISUAL = "Visual"; + public final static String QUESTING = "Questing"; + + /** + * Visual Properties + **/ + public static Property EnableChatBubblesProperty; public static boolean EnableChatBubbles = true; + + public static Property InventoryGuiEnabledProperty; public static boolean InventoryGuiEnabled = true; + + public static Property FontTypeProperty; public static String FontType = "Default"; + + public static Property FontSizeProperty; public static int FontSize = 18; + + public static Property EntityRendererMixinProperty; public static boolean EntityRendererMixin = true; + /** + * Questing Properties + **/ + public static Property TrackingInfoAlignmentProperty; public static int TrackingInfoAlignment = 3; + + public static Property TrackingInfoXProperty; public static int TrackingInfoX = 0; + + public static Property TrackingInfoYProperty; public static int TrackingInfoY = 0; - public final static String VISUAL = "Visual"; - - public final static String QUESTING = "Questing"; - public static void init(File configFile) { config = new Configuration(configFile); @@ -31,22 +53,64 @@ public class ConfigClient try { config.load(); - EnableChatBubbles = config.get(VISUAL, "Enable Chat Bubbles", true, "Enable/Disable Chat Bubbles").getBoolean(true); - InventoryGuiEnabled = config.get(VISUAL, "Enable Inventory Tabs", true, "Enable/Disable Inventory Tabs").getBoolean(true); - FontType = config.get(VISUAL, "Font Type", "Default", "When set to Minecraft it will use minecrafts font, when Default it will use OpenSans. Can only use fonts installed on your PC").getString(); - FontSize = config.get(VISUAL, "Font Size", 18, "Font size for custom fonts (doesn't work with minecrafts font)").getInt(18); - EntityRendererMixin = config.get(VISUAL, "Entity Render Mixin", true, "Enables Overlay Mixins for Conflicts relating to Optifine or other Skin Renderers. If crashes occur, please disable.").getBoolean(true); - TrackingInfoAlignment = config.get(QUESTING, "Tracking Info Alignment", 3, "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3").getInt(3); + // Visual + EnableChatBubblesProperty = config.get(VISUAL, "Enable Chat Bubbles", true, "Enable/Disable Chat Bubbles"); + EnableChatBubbles = EnableChatBubblesProperty.getBoolean(true); + + InventoryGuiEnabledProperty = config.get(VISUAL, "Enable Inventory Tabs", true, "Enable/Disable Inventory Tabs"); + InventoryGuiEnabled = InventoryGuiEnabledProperty.getBoolean(true); + + FontTypeProperty = config.get(VISUAL, "Font Type", "Default", "When set to Minecraft it will use minecrafts font, when Default it will use OpenSans. Can only use fonts installed on your PC"); + FontType = FontTypeProperty.getString(); + + FontSizeProperty = config.get(VISUAL, "Font Size", 18, "Font size for custom fonts (doesn't work with minecrafts font)"); + FontSize = FontSizeProperty.getInt(18); + + EntityRendererMixinProperty = config.get(VISUAL, "Entity Render Mixin", true, "Enables Overlay Mixins for Conflicts relating to Optifine or other Skin Renderers. If crashes occur, please disable."); + EntityRendererMixin = EntityRendererMixinProperty.getBoolean(true); + + // Questing + TrackingInfoAlignmentProperty = config.get(QUESTING, "Tracking Info Alignment", 3, "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3"); + TrackingInfoAlignment = TrackingInfoAlignmentProperty.getInt(3); + + TrackingInfoXProperty = config.get(QUESTING, "Tracking Info X", 0, "Client sided! Offsets the tracking info GUI by this amount in the X direction."); + TrackingInfoX = TrackingInfoXProperty.getInt(0); + + TrackingInfoYProperty = config.get(QUESTING, "Tracking Info Y", 0, "Client sided! Offsets the tracking info GUI by this amount in the Y direction."); + TrackingInfoY = TrackingInfoYProperty.getInt(0); + + // Convert to Legacy + if(CustomNpcs.legacyExist){ + EnableChatBubbles = LegacyConfig.EnableChatBubbles; + EnableChatBubblesProperty.set(EnableChatBubbles); + + FontType = LegacyConfig.FontType; + FontTypeProperty.set(FontType); + + InventoryGuiEnabled = LegacyConfig.InventoryGuiEnabled; + InventoryGuiEnabledProperty.set(InventoryGuiEnabled); + + FontSize = LegacyConfig.FontSize; + FontSizeProperty.set(FontSize); + + EntityRendererMixin = LegacyConfig.EntityRendererMixin; + EntityRendererMixinProperty.set(EntityRendererMixin); + + TrackingInfoAlignment = LegacyConfig.TrackingInfoAlignment; + TrackingInfoAlignmentProperty.set(TrackingInfoAlignment); + + TrackingInfoX = LegacyConfig.TrackingInfoX; + TrackingInfoXProperty.set(TrackingInfoX); + + TrackingInfoY = LegacyConfig.TrackingInfoY; + TrackingInfoYProperty.set(TrackingInfoY); + } + if (TrackingInfoAlignment < 0) TrackingInfoAlignment = 0; if (TrackingInfoAlignment > 8) TrackingInfoAlignment = 8; - - TrackingInfoX = config.get(QUESTING, "Tracking Info X", 0, "Client sided! Offsets the tracking info GUI by this amount in the X direction.").getInt(0); - TrackingInfoY = config.get(QUESTING, "Tracking Info Y", 0, "Client sided! Offsets the tracking info GUI by this amount in the Y direction.").getInt(0); - - } catch (Exception e) { diff --git a/src/main/java/noppes/npcs/config/ConfigDebug.java b/src/main/java/noppes/npcs/config/ConfigDebug.java index fa346c48e..3ff3968e8 100644 --- a/src/main/java/noppes/npcs/config/ConfigDebug.java +++ b/src/main/java/noppes/npcs/config/ConfigDebug.java @@ -2,7 +2,9 @@ package noppes.npcs.config; import cpw.mods.fml.common.FMLLog; import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; import noppes.npcs.CustomNpcs; +import noppes.npcs.config.legacy.LegacyConfig; import noppes.npcs.constants.EnumScriptType; import org.apache.logging.log4j.Level; @@ -12,14 +14,25 @@ public class ConfigDebug { public static Configuration config; + public final static String LOGGING = "Logging"; + + /** + * Logging Properties + **/ + public static Property PlayerLoggingProperty; public static boolean PlayerLogging = false; + public static Property ScriptLoggingProperty; public static boolean ScriptLogging = false; - public static int ScriptFrequency = 20; - public static int ScriptIgnoreTime = 2000; - public static String ScriptLogIgnoreType = "TICK"; - public final static String LOGGING = "Visual"; + public static Property ScriptFrequencyProperty; + public static int ScriptFrequency = 20; + + public static Property ScriptIgnoreTimeProperty; + public static int ScriptIgnoreTime = 2000; + + public static Property ScriptLogIgnoreTypeProperty; + public static String ScriptLogIgnoreType = "TICK"; public static void init(File configFile) { @@ -28,24 +41,54 @@ public class ConfigDebug try { config.load(); - PlayerLogging = config.get(LOGGING, "Enable Player Logging", false, "Enables if Player Information (WAND-USE) should be printed to CustomNPCs Logs. IF on Server \n" + - "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3").getBoolean(false); - ScriptLogging = config.get(LOGGING, "Enable Script Logging", false, "Enables if Scripting Information should be printed to CustomNPCs Logs. IF on Server \n" + - "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3").getBoolean(false); - ScriptFrequency = config.get(LOGGING, "Script Log Frequency Limit", 20, "Amount of Messages marked as SPAM [5, 3000]. Lower Number means MORE accurate messages \n" + - "This frequency will determine if the log will print a line with [SPAM] to warn the console.").getInt(20); + // Logging + PlayerLoggingProperty = config.get(LOGGING, "Enable Player Logging", false, "Enables if Player Information (WAND-USE) should be printed to CustomNPCs Logs. IF on Server \n" + + "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3"); + PlayerLogging = PlayerLoggingProperty.getBoolean(false); + + ScriptLoggingProperty = config.get(LOGGING, "Enable Script Logging", false, "Enables if Scripting Information should be printed to CustomNPCs Logs. IF on Server \n" + + "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3"); + ScriptLogging = ScriptLoggingProperty.getBoolean(false); + + ScriptFrequencyProperty = config.get(LOGGING, "Script Log Frequency Limit", 20, "Amount of Messages marked as SPAM [5, 3000]. Lower Number means MORE accurate messages \n" + + "This frequency will determine if the log will print a line with [SPAM] to warn the console."); + ScriptFrequency = ScriptFrequencyProperty.getInt(20); + + ScriptIgnoreTimeProperty = config.get(LOGGING, "Script Ignore Time Buffer", 2000, "IN Milliseconds 1s = 1000s. If a recent LOG of the same event is SENT within this threshold it will be ignored."); + ScriptIgnoreTime = ScriptIgnoreTimeProperty.getInt(2000); + + ScriptLogIgnoreTypeProperty = config.get(LOGGING, "Script Type Ignore", "TICK", "Comma separated list of NPC Script Types that will omit these from the logs,\n" + + "INIT,TICK,INTERACT,DIALOG,DAMAGED,KILLED,ATTACK,TARGET,COLLIDE,KILLS,DIALOG_CLOSE,TIMER"); + ScriptLogIgnoreType = ScriptLogIgnoreTypeProperty.getString(); + + // Convert to Legacy + if(CustomNpcs.legacyExist) { + PlayerLogging = LegacyConfig.PlayerLogging; + PlayerLoggingProperty.set(PlayerLogging); + + ScriptLogging = LegacyConfig.ScriptLogging; + ScriptLoggingProperty.set(ScriptLogging); + + ScriptFrequency = LegacyConfig.ScriptFrequency; + ScriptFrequencyProperty.set(ScriptFrequency); + + ScriptIgnoreTime = LegacyConfig.ScriptIgnoreTime; + ScriptIgnoreTimeProperty.set(ScriptIgnoreTime); + + ScriptLogIgnoreType = LegacyConfig.ScriptLogIgnoreType; + ScriptLogIgnoreTypeProperty.set(ScriptLogIgnoreType); + } + if (ScriptFrequency < 5) ScriptFrequency = 5; + if (ScriptFrequency > 3000) ScriptFrequency = 3000; - ScriptIgnoreTime = config.get(LOGGING, "Script Ignore Time Buffer", 2000, "IN Milliseconds 1s = 1000s. If a recent LOG of the same event is SENT within this threshold it will be ignored.").getInt(2000); if (ScriptIgnoreTime < 0) ScriptIgnoreTime = 0; - ScriptLogIgnoreType = config.get(LOGGING, "Script Type Ignore", "TICK", "Comma separated list of NPC Script Types that will omit these from the logs,\n" + - "INIT,TICK,INTERACT,DIALOG,DAMAGED,KILLED,ATTACK,TARGET,COLLIDE,KILLS,DIALOG_CLOSE,TIMER").getString(); try { String[] ignoreTypes = ScriptLogIgnoreType.split(","); for (String s : ignoreTypes) { diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index 1d1ffd631..4f5d038bf 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -2,6 +2,9 @@ package noppes.npcs.config; import cpw.mods.fml.common.FMLLog; import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import noppes.npcs.CustomNpcs; +import noppes.npcs.config.legacy.LegacyConfig; import org.apache.logging.log4j.Level; import java.io.File; @@ -10,35 +13,80 @@ public class ConfigMain { public static Configuration config; - public static boolean EnableUpdateChecker = true; - - public static boolean DisableExtraBlock = false; - public static boolean DisableExtraItems = false; - public static boolean DisableEnchants = false; - public static boolean GunsEnabled = true; - public static int EnchantStartId = 100; - - public static boolean LeavesDecayEnabled = true; - public static boolean VineGrowthEnabled = true; - public static boolean IceMeltsEnabled = true; - public static boolean SoulStoneAnimals = true; - public static boolean SoulStoneVillagers = false; - public static boolean SoulStoneNPCs = false; - public static boolean SoulStoneFriendlyNPCs = false; - - public static boolean OpsOnly = false; - public static int NpcNavRange = 32; - public static int NpcSizeLimit = 100; - public static String DefaultInteractLine = "Hello @p"; - public static int ChunkLoaders = 20; - public static int DialogImageLimit = 10; - public static int SkinOverlayLimit = 10; - - public static boolean NpcUseOpCommands = false; - public final static String GENERAL = "NPC"; public final static String NPC = "NPC"; + /** + * General Main Properties + **/ + + public static Property EnableUpdateCheckerProperty; + public static boolean EnableUpdateChecker = true; + + public static Property DisableExtraBlockProperty; + public static boolean DisableExtraBlock = false; + + public static Property DisableExtraItemsProperty; + public static boolean DisableExtraItems = false; + + public static Property DisableEnchantsProperty; + public static boolean DisableEnchants = false; + + public static Property GunsEnabledProperty; + public static boolean GunsEnabled = true; + + public static Property EnchantStartIdProperty; + public static int EnchantStartId = 100; + + public static Property LeavesDecayEnabledProperty; + public static boolean LeavesDecayEnabled = true; + + public static Property VineGrowthEnabledProperty; + public static boolean VineGrowthEnabled = true; + + public static Property IceMeltsEnabledProperty; + public static boolean IceMeltsEnabled = true; + + public static Property SoulStoneAnimalsProperty; + public static boolean SoulStoneAnimals = true; + + public static Property SoulStoneVillagersProperty; + public static boolean SoulStoneVillagers = false; + + public static Property SoulStoneNPCsProperty; + public static boolean SoulStoneNPCs = false; + + public static Property SoulStoneFriendlyNPCsProperty; + public static boolean SoulStoneFriendlyNPCs = false; + + /** + * General NPC Properties + **/ + + public static Property OpsOnlyProperty; + public static boolean OpsOnly = false; + + public static Property NpcNavRangeProperty; + public static int NpcNavRange = 32; + + public static Property NpcSizeLimitProperty; + public static int NpcSizeLimit = 100; + + public static Property DefaultInteractLineProperty; + public static String DefaultInteractLine = "Hello @p"; + + public static Property ChunkLoadersProperty; + public static int ChunkLoaders = 20; + + public static Property DialogImageLimitProperty; + public static int DialogImageLimit = 10; + + public static Property SkinOverlayLimitProperty; + public static int SkinOverlayLimit = 10; + + public static Property NpcUseOpCommandsProperty; + public static boolean NpcUseOpCommands = false; + public static void init(File configFile) { config = new Configuration(configFile); @@ -46,22 +94,139 @@ public class ConfigMain try { config.load(); - EnableUpdateChecker = config.get(GENERAL, "Enables Update Checker", true).getBoolean(true); - DisableExtraBlock = config.get(GENERAL, "Disable Extra Blocks", false).getBoolean(false); - DisableExtraItems = config.get(GENERAL, "Disable Extra Items", false).getBoolean(false); - GunsEnabled = config.get(GENERAL, "Guns Enabled", true, "Set to false if you want to disable guns").getBoolean(true); - DisableEnchants = config.get(GENERAL, "Disable Enchants", false).getBoolean(false); - EnchantStartId = config.get(GENERAL, "Enchant Start ID", 100, "Start ID for enchants. IDs can only range from 0-256").getInt(100); - LeavesDecayEnabled = config.get(GENERAL, "Leaves Decay Enabled", true).getBoolean(true); - VineGrowthEnabled = config.get(GENERAL, "Vine Growth Enabled", true).getBoolean(true); - IceMeltsEnabled = config.get(GENERAL, "Ice Melt Enabled", true).getBoolean(true); - SoulStoneAnimals = config.get(GENERAL, "Normal playes can use soulstone on Animals", true).getBoolean(true); - SoulStoneVillagers = config.get(GENERAL, "Normal playes can use soulstone on Villagers", true).getBoolean(true); - SoulStoneNPCs = config.get(GENERAL, "Normal playes can use soulstone on NPCs", false).getBoolean(false); - SoulStoneFriendlyNPCs = config.get(GENERAL, "Normal playes can use soulstone on Friendly NPCs", false).getBoolean(false); + // General + EnableUpdateCheckerProperty = config.get(GENERAL, "Enables Update Checker", true); + EnableUpdateChecker = EnableUpdateCheckerProperty.getBoolean(true); + + DisableExtraBlockProperty = config.get(GENERAL, "Disable Extra Blocks", false); + DisableExtraBlock = DisableExtraBlockProperty.getBoolean(false); + + DisableExtraItemsProperty = config.get(GENERAL, "Disable Extra Items", false); + DisableExtraItems = DisableExtraItemsProperty.getBoolean(false); + + GunsEnabledProperty = config.get(GENERAL, "Guns Enabled", true, "Set to false if you want to disable guns"); + GunsEnabled = GunsEnabledProperty.getBoolean(true); + + DisableEnchantsProperty = config.get(GENERAL, "Disable Enchants", false); + DisableEnchants = DisableEnchantsProperty.getBoolean(false); + + EnchantStartIdProperty = config.get(GENERAL, "Enchant Start ID", 100, "Start ID for enchants. IDs can only range from 0-256"); + EnchantStartId = EnchantStartIdProperty.getInt(100); + + LeavesDecayEnabledProperty = config.get(GENERAL, "Leaves Decay Enabled", true); + LeavesDecayEnabled = LeavesDecayEnabledProperty.getBoolean(true); + + VineGrowthEnabledProperty = config.get(GENERAL, "Vine Growth Enabled", true); + VineGrowthEnabled = VineGrowthEnabledProperty.getBoolean(true); + + IceMeltsEnabledProperty = config.get(GENERAL, "Ice Melt Enabled", true); + IceMeltsEnabled = IceMeltsEnabledProperty.getBoolean(true); + + SoulStoneAnimalsProperty = config.get(GENERAL, "Normal playes can use soulstone on Animals", true); + SoulStoneAnimals = SoulStoneAnimalsProperty.getBoolean(true); + + SoulStoneVillagersProperty = config.get(GENERAL, "Normal playes can use soulstone on Villagers", true); + SoulStoneVillagers = SoulStoneVillagersProperty.getBoolean(true); + + SoulStoneNPCsProperty = config.get(GENERAL, "Normal playes can use soulstone on NPCs", false); + SoulStoneNPCs = SoulStoneNPCsProperty.getBoolean(false); + + SoulStoneFriendlyNPCsProperty = config.get(GENERAL, "Normal playes can use soulstone on Friendly NPCs", false); + SoulStoneFriendlyNPCs = SoulStoneFriendlyNPCsProperty.getBoolean(false); + + + // NPC + NpcNavRangeProperty = config.get(NPC, "NPC Navigation Range", 32, "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96."); + NpcNavRange = NpcNavRangeProperty.getInt(32); + + OpsOnlyProperty = config.get(NPC, "Only Ops Edit NPCs", false, "Only ops can create and edit npcs"); + OpsOnly = OpsOnlyProperty.getBoolean(false); + + NpcUseOpCommandsProperty = config.get(NPC, "NPC Use Op Commands", false, "Set to true if you want the dialog command option to be able to use op commands like tp etc"); + NpcUseOpCommands = NpcUseOpCommandsProperty.getBoolean(false); + + DefaultInteractLineProperty = config.get(NPC, "Default Interaction Line", "Hello @p", "Default interact line. Leave empty to not have one"); + DefaultInteractLine = DefaultInteractLineProperty.getString(); + + ChunkLoadersProperty = config.get(NPC, "Chunk Loader Limit", 20, "Number of chunk loading npcs that can be active at the same time"); + ChunkLoaders = ChunkLoadersProperty.getInt(20); + + DialogImageLimitProperty = config.get(NPC, "Dialog Image Limit", 10, "The maximum number of images any dialog can hold."); + DialogImageLimit = DialogImageLimitProperty.getInt(10); + + NpcSizeLimitProperty = config.get(NPC, "NPC Size Limit", 100, "Size limit for NPCs. Default 100, larger sizes may cause lag on clients and servers that can't take it!"); + NpcSizeLimit = NpcSizeLimitProperty.getInt(100); + + SkinOverlayLimitProperty = config.get(NPC, "Skin Overlay Limit", 10, "The maximum number of overlays any npc/player can hold."); + SkinOverlayLimit = SkinOverlayLimitProperty.getInt(10); + + // Convert to Legacy + if(CustomNpcs.legacyExist){ + EnableUpdateChecker = LegacyConfig.EnableUpdateChecker; + EnableUpdateCheckerProperty.set(EnableUpdateChecker); + + DisableExtraBlock = LegacyConfig.DisableExtraBlock; + DisableExtraBlockProperty.set(DisableExtraBlock); + + DisableExtraItems = LegacyConfig.DisableExtraItems; + DisableExtraItemsProperty.set(DisableExtraItems); + + DisableEnchants = LegacyConfig.DisableEnchants; + DisableEnchantsProperty.set(DisableEnchants); + + GunsEnabled = LegacyConfig.GunsEnabled; + GunsEnabledProperty.set(GunsEnabled); + + EnchantStartId = LegacyConfig.EnchantStartId; + EnchantStartIdProperty.set(EnchantStartId); + + LeavesDecayEnabled = LegacyConfig.LeavesDecayEnabled; + LeavesDecayEnabledProperty.set(LeavesDecayEnabled); + + VineGrowthEnabled = LegacyConfig.VineGrowthEnabled; + VineGrowthEnabledProperty.set(VineGrowthEnabled); + + IceMeltsEnabled = LegacyConfig.IceMeltsEnabled; + IceMeltsEnabledProperty.set(IceMeltsEnabled); + + SoulStoneAnimals = LegacyConfig.SoulStoneAnimals; + SoulStoneAnimalsProperty.set(SoulStoneAnimals); + + SoulStoneVillagers = LegacyConfig.SoulStoneVillagers; + SoulStoneVillagersProperty.set(SoulStoneVillagers); + + SoulStoneNPCs = LegacyConfig.SoulStoneNPCs; + SoulStoneNPCsProperty.set(SoulStoneNPCs); + + SoulStoneFriendlyNPCs = LegacyConfig.SoulStoneFriendlyNPCs; + SoulStoneFriendlyNPCsProperty.set(SoulStoneFriendlyNPCs); + + OpsOnly = LegacyConfig.OpsOnly; + OpsOnlyProperty.set(OpsOnly); + + NpcNavRange = LegacyConfig.NpcNavRange; + NpcNavRangeProperty.set(NpcNavRange); + + NpcSizeLimit = LegacyConfig.NpcSizeLimit; + NpcSizeLimitProperty.set(NpcSizeLimit); + + DefaultInteractLine = LegacyConfig.DefaultInteractLine; + DefaultInteractLineProperty.set(DefaultInteractLine); + + ChunkLoaders = LegacyConfig.ChunkLoaders; + ChunkLoadersProperty.set(ChunkLoaders); + + DialogImageLimit = LegacyConfig.DialogImageLimit; + DialogImageLimitProperty.set(DialogImageLimit); + + SkinOverlayLimit = LegacyConfig.SkinOverlayLimit; + SkinOverlayLimitProperty.set(SkinOverlayLimit); + + NpcUseOpCommands = LegacyConfig.NpcUseOpCommands; + NpcUseOpCommandsProperty.set(NpcUseOpCommands); + } - NpcNavRange = config.get(NPC, "NPC Navigation Range", 32, "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.").getInt(32); if (NpcNavRange < 16) { NpcNavRange = 16; } @@ -69,21 +234,14 @@ public class ConfigMain NpcNavRange = 96; } - NpcSizeLimit = config.get(NPC, "NPC Size Limit", 100, "Size limit for NPCs. Default 100, larger sizes may cause lag on clients and servers that can't take it!").getInt(100); - if(NpcSizeLimit < 1) + if(NpcSizeLimit < 1){ NpcSizeLimit = 1; + } - OpsOnly = config.get(NPC, "Only Ops Edit NPCs", false, "Only ops can create and edit npcs").getBoolean(false); - NpcUseOpCommands = config.get(NPC, "NPC Use Op Commands", false, "Set to true if you want the dialog command option to be able to use op commands like tp etc").getBoolean(false); - DefaultInteractLine = config.get(NPC, "Default Interaction Line", "Hello @p", "Default interact line. Leave empty to not have one").getString(); - ChunkLoaders = config.get(NPC, "Chunk Loader Limit", 20, "Number of chunk loading npcs that can be active at the same time").getInt(20); - - DialogImageLimit = config.get(NPC, "Dialog Image Limit", 10, "The maximum number of images any dialog can hold.").getInt(10); if (DialogImageLimit < 0) { DialogImageLimit = 0; } - SkinOverlayLimit = config.get(NPC, "Skin Overlay Limit", 10, "The maximum number of overlays any npc/player can hold.").getInt(10); if (SkinOverlayLimit < 0) { SkinOverlayLimit = 0; } diff --git a/src/main/java/noppes/npcs/config/ConfigScript.java b/src/main/java/noppes/npcs/config/ConfigScript.java index 304711726..e21488f4d 100644 --- a/src/main/java/noppes/npcs/config/ConfigScript.java +++ b/src/main/java/noppes/npcs/config/ConfigScript.java @@ -4,7 +4,9 @@ import cpw.mods.fml.common.FMLLog; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; import noppes.npcs.CustomNpcs; +import noppes.npcs.config.legacy.LegacyConfig; import org.apache.logging.log4j.Level; import java.io.File; @@ -14,18 +16,39 @@ public class ConfigScript { public static Configuration config; - public static boolean ScriptingEnabled = true; - public static boolean ScriptingECMA6 = false; - public static boolean GlobalPlayerScripts = true; - public static boolean GlobalForgeScripts = true; - public static boolean GlobalNPCScripts = false; - public static int ExpandedScriptLimit = 2; - public static boolean ScriptOpsOnly = false; - public static String ScriptDevIDs = ""; - public final static String GENERAL = "Scripting General"; public final static String CUSTOMIZATION = "Scripting Customization"; + /** + * General Properties + **/ + public static Property ScriptingEnabledProperty; + public static boolean ScriptingEnabled = true; + + public static Property ScriptOpsOnlyProperty; + public static boolean ScriptOpsOnly = false; + + public static Property GlobalPlayerScriptsProperty; + public static boolean GlobalPlayerScripts = true; + + public static Property GlobalForgeScriptsProperty; + public static boolean GlobalForgeScripts = true; + + public static Property GlobalNPCScriptsProperty; + public static boolean GlobalNPCScripts = false; + + /** + * Customization Properties + **/ + public static Property ScriptingECMA6Property; + public static boolean ScriptingECMA6 = false; + + public static Property ExpandedScriptLimitProperty; + public static int ExpandedScriptLimit = 2; + + public static Property ScriptDevIDsProperty; + public static String ScriptDevIDs = ""; + public static void init(File configFile) { config = new Configuration(configFile); @@ -33,29 +56,74 @@ public class ConfigScript try { config.load(); - ScriptingEnabled = config.get(GENERAL, "Enable Scripting", true, "Enables/Disables ALL scripting. You can still see and write code in the scripter, but these scripts won't run. True by default").getBoolean(true); - ScriptOpsOnly = config.get(GENERAL, "OPs Only", false, "Only ops can see and edit scripts").getBoolean(false); - GlobalPlayerScripts = config.get(GENERAL, "Enable Global Player Scripts", true, "Enables global player event scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. True by default.").getBoolean(true); - GlobalForgeScripts = config.get(GENERAL, "Enable Global Forge Event Scripts", true, "Enables global forge event scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. True by default.").getBoolean(true); - GlobalNPCScripts = config.get(GENERAL, "Enable Global NPC Scripts", false, "Enables global NPC scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. False by default, use with caution!").getBoolean(false); - ScriptingECMA6 = config.get(CUSTOMIZATION, "ECMA6 Scripting Language", false, + // General + ScriptingEnabledProperty = config.get(GENERAL, "Enable Scripting", true, "Enables/Disables ALL scripting. You can still see and write code in the scripter, but these scripts won't run. True by default"); + ScriptingEnabled = ScriptingEnabledProperty.getBoolean(true); + + ScriptOpsOnlyProperty = config.get(GENERAL, "OPs Only", false, "Only ops can see and edit scripts"); + ScriptOpsOnly = ScriptOpsOnlyProperty.getBoolean(false); + + GlobalPlayerScriptsProperty = config.get(GENERAL, "Enable Global Player Scripts", true, "Enables global player event scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. True by default."); + GlobalPlayerScripts = GlobalPlayerScriptsProperty.getBoolean(true); + + GlobalForgeScriptsProperty = config.get(GENERAL, "Enable Global Forge Event Scripts", true, "Enables global forge event scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. True by default."); + GlobalForgeScripts = GlobalForgeScriptsProperty.getBoolean(true); + + GlobalNPCScriptsProperty = config.get(GENERAL, "Enable Global NPC Scripts", false, "Enables global NPC scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. False by default, use with caution!"); + GlobalNPCScripts = GlobalNPCScriptsProperty.getBoolean(false); + + // Customization + ScriptingECMA6Property = config.get(CUSTOMIZATION, "ECMA6 Scripting Language", false, "Enables/Disables the use of the the ECMA6 Javascript standard instead of ECMA5.1." + "\nEnabling this adds many more features to JS in scripts. Only use if on Java 8 or higher." + - "\nNot all ECMA 6 language is supported through this functionality.").getBoolean(false); - ExpandedScriptLimit = config.get(CUSTOMIZATION, "Script Tag Limit", 2, - "If scripts are too long (>65535 characters), they normally won't be saved in NBT data.\n" + - "This config adds additional compound tags to scripts that need it, so you can store much larger scripts!\n" + - "Every additional compound tag adds 65535 more characters to your script length limit. Use incrementally, with caution.").getInt(2); - if (ExpandedScriptLimit < 0) - ExpandedScriptLimit = 0; + "\nNot all ECMA 6 language is supported through this functionality."); + ScriptingECMA6 = ScriptingECMA6Property.getBoolean(false); - ScriptDevIDs = config.get(CUSTOMIZATION, "Script Dev UUIDs", "", + ExpandedScriptLimitProperty = config.get(CUSTOMIZATION, "Script Tag Limit", 2, + "If scripts are too long (>65535 characters), they normally won't be saved in NBT data.\n" + + "This config adds additional compound tags to scripts that need it, so you can store much larger scripts!\n" + + "Every additional compound tag adds 65535 more characters to your script length limit. Use incrementally, with caution."); + ExpandedScriptLimit = ExpandedScriptLimitProperty.getInt(2); + + ScriptDevIDsProperty = config.get(CUSTOMIZATION, "Script Dev UUIDs", "", "Comma separated list of player UUIDs that can see and edit scripts. If ScriptsOpsOnly is true,\n" + "ops and players with these IDs can see and edit scripts. Example:\n" + "b876ec32-e396-476b-a115-8438d83c67d4,069a79f4-44e9-4726-a5be-fca90e38aaf5,be951074-c7ea-4f02-a725-bf017bc88650\n" + "Get a player's UUID from a site like NameMC or the API IPlayer.getUniqueID() function!\n" + - "If left empty and ScriptsOpsOnly is false, anyone can see and edit scripts with a scripter.").getString(); + "If left empty and ScriptsOpsOnly is false, anyone can see and edit scripts with a scripter."); + ScriptDevIDs = ScriptDevIDsProperty.getString(); + + // Convert to Legacy + if(CustomNpcs.legacyExist){ + ScriptingEnabled = LegacyConfig.ScriptingEnabled; + ScriptingEnabledProperty.set(ScriptingEnabled); + + ScriptOpsOnly = LegacyConfig.ScriptOpsOnly; + ScriptOpsOnlyProperty.set(ScriptOpsOnly); + + GlobalPlayerScripts = LegacyConfig.GlobalPlayerScripts; + GlobalPlayerScriptsProperty.set(GlobalPlayerScripts); + + GlobalForgeScripts = LegacyConfig.GlobalForgeScripts; + GlobalForgeScriptsProperty.set(GlobalForgeScripts); + + GlobalNPCScripts = LegacyConfig.GlobalNPCScripts; + GlobalNPCScriptsProperty.set(GlobalNPCScripts); + + ScriptingECMA6 = LegacyConfig.ScriptingECMA6; + ScriptingECMA6Property.set(ScriptingECMA6); + + ExpandedScriptLimit = LegacyConfig.ExpandedScriptLimit; + ExpandedScriptLimitProperty.set(ExpandedScriptLimit); + + ScriptDevIDs = LegacyConfig.ScriptDevIDs; + ScriptDevIDsProperty.set(ScriptDevIDs); + } + + if (ExpandedScriptLimit < 0) + ExpandedScriptLimit = 0; + try { CustomNpcs.ScriptDevs.clear(); String[] uuidStrings = ScriptDevIDs.split(","); diff --git a/src/main/java/noppes/npcs/config/LoadConfiguration.java b/src/main/java/noppes/npcs/config/LoadConfiguration.java index 5bde64099..2a946108b 100644 --- a/src/main/java/noppes/npcs/config/LoadConfiguration.java +++ b/src/main/java/noppes/npcs/config/LoadConfiguration.java @@ -1,6 +1,8 @@ package noppes.npcs.config; +import noppes.npcs.CustomNpcs; import noppes.npcs.config.legacy.ConfigProp; +import noppes.npcs.config.legacy.LegacyConfig; import java.io.BufferedWriter; import java.io.File; @@ -17,13 +19,6 @@ public class LoadConfiguration { public static void init(String configpath) { - if(!dir.exists()) - dir.mkdir(); - this.dir = dir; - configClass = clss; - configFields = new LinkedList(); - this.fileName = fileName+".cfg"; - mainConfigFile = new File(configpath + "main.cfg"); clientConfigFile = new File(configpath + "client.cfg"); scriptConfigFile = new File(configpath + "script.cfg");