Exemplo n.º 1
0
 private void Reload_Config(CommandArgs args)
 {
     if (LexiconPlugin.ReadConfig())
     {
         args.Player.SendMessage("LexiconPlugin config reloaded sucessfully.", Color.Green);
     }
 }
Exemplo n.º 2
0
 public override void Initialize()
 {
     Commands.ChatCommands.Add(new Command("wordreplacement.lexiconify", new CommandDelegate(this.Lexiconify), new string[]
     {
         "lexiconify, lex"
     }));
     Commands.ChatCommands.Add(new Command("wordreplacement.reload", new CommandDelegate(this.Reload_Config), new string[]
     {
         "lexreload"
     }));
     ServerApi.Hooks.ServerChat.Register(this, new HookHandler <ServerChatEventArgs>(this.OnChat));
     LexiconPlugin.ReadConfig();
 }
Exemplo n.º 3
0
        private static bool ReadConfig()
        {
            string path = Path.Combine(TShock.SavePath, "LexiconConfig.json");
            bool   result;

            try
            {
                if (File.Exists(path))
                {
                    using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (StreamReader streamReader = new StreamReader(fileStream))
                        {
                            string text = streamReader.ReadToEnd();
                            LexiconPlugin.config = JsonConvert.DeserializeObject <LexiconPlugin.Config>(text);
                            LexiconPlugin.config.HurrDurrChancePercentage      = (int)MathHelper.Clamp((float)LexiconPlugin.config.HurrDurrChancePercentage, 0f, 100f);
                            LexiconPlugin.config.RandomPhrasesChancePercentage = (int)MathHelper.Clamp((float)LexiconPlugin.config.RandomPhrasesChancePercentage, 0f, 100f);
                            LexiconPlugin.config.TypoChancePercentage          = (int)MathHelper.Clamp((float)LexiconPlugin.config.TypoChancePercentage, 0f, 100f);
                        }
                        fileStream.Close();
                    }
                    result = true;
                    return(result);
                }
                Log.ConsoleError("LexiconPlugin config not found. Creating new one...");
                LexiconPlugin.CreateConfig();
                result = false;
                return(result);
            }
            catch (Exception ex)
            {
                Log.ConsoleError(ex.Message);
            }
            result = false;
            return(result);
        }