public static bool BroadCast(string pluginid, string key, Color color, params object[] parameters)
 {
     foreach (SteamPlayer sp in Provider.clients)
     {
         UnturnedPlayer         player    = UnturnedPlayer.FromSteamPlayer(sp);
         Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
         string lang = component.lang;
         string text = Instance.Configuration.Instance.PluginTranslate.Find(x => x.pluginid == pluginid).Langs.Find(x => x.LangID == lang).LangString.Find(x => x.id == key).text;
         if (string.IsNullOrEmpty(text))
         {
             return(false);
         }
         if (text.Contains("{") && text.Contains("}") && parameters != null && parameters.Length != 0)
         {
             for (int i = 0; i < parameters.Length; i++)
             {
                 if (parameters[i] == null)
                 {
                     parameters[i] = "NULL";
                 }
             }
             text = string.Format(text, parameters);
         }
         UnturnedChat.Say(player, text, color);
     }
     return(true);
 }
 public void UpdateInfo(UnturnedPlayer player, string lang)
 {
     if (Plugin.Instance.Configuration.Instance.isDB)
     {
         MySqlConnection mySqlConnection = this.createConnection();
         MySqlCommand    mySqlCommand    = mySqlConnection.CreateCommand();
         mySqlCommand.CommandText = string.Concat(new string[]
         {
             "UPDATE ",
             Plugin.Instance.Configuration.Instance.mysqltable,
             " SET Language = '",
             lang,
             "' WHERE Steam64ID = '",
             player.CSteamID.m_SteamID.ToString(),
             "';"
         });
         mySqlConnection.Open();
         mySqlCommand.ExecuteNonQuery();
         mySqlConnection.Close();
     }
     else
     {
         if (Plugin.Instance.Configuration.Instance.Users.Exists(x => x.playerid == player.CSteamID.m_SteamID))
         {
             Plugin.Instance.Configuration.Instance.Users.Find(x => x.playerid == player.CSteamID.m_SteamID).lang = lang;
             Plugin.Instance.Configuration.Save();
         }
     }
     Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
     component.lang = lang;
 }
        public static bool SendChat(UnturnedPlayer player, string pluginid, string key, Color color)
        {
            Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
            string lang = component.lang;
            string text = Instance.Configuration.Instance.PluginTranslate.Find(x => x.pluginid == pluginid).Langs.Find(x => x.LangID == lang).LangString.Find(x => x.id == key).text;

            if (string.IsNullOrEmpty(text))
            {
                UnturnedChat.Say(player, key, color);
                return(false);
            }
            UnturnedChat.Say(player, text, color);
            return(true);
        }
 public static bool BroadCast(string pluginid, string key, Color color)
 {
     foreach (SteamPlayer sp in Provider.clients)
     {
         UnturnedPlayer         player    = UnturnedPlayer.FromSteamPlayer(sp);
         Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
         string lang = component.lang;
         string text = Instance.Configuration.Instance.PluginTranslate.Find(x => x.pluginid == pluginid).Langs.Find(x => x.LangID == lang).LangString.Find(x => x.id == key).text;
         if (string.IsNullOrEmpty(text))
         {
             return(false);
         }
         UnturnedChat.Say(player, text, color);
     }
     return(true);
 }
        public static string GetTranslate(UnturnedPlayer player, string pluginid, string key, params object[] parameters)
        {
            Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
            string lang = component.lang;
            string text = Instance.Configuration.Instance.PluginTranslate.Find(x => x.pluginid == pluginid).Langs.Find(x => x.LangID == lang).LangString.Find(x => x.id == key).text;

            if (string.IsNullOrEmpty(text))
            {
                return(key);
            }
            if (text.Contains("{") && text.Contains("}") && parameters != null && parameters.Length != 0)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i] == null)
                    {
                        parameters[i] = "NULL";
                    }
                }
                text = string.Format(text, parameters);
            }
            return(text);
        }
        public void Execute(IRocketPlayer caller, string[] command)
        {
            UnturnedPlayer player = (UnturnedPlayer)caller;

            Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
            if (command.Length == 0)
            {
                string text = "";
                foreach (Config.Lang lang in Plugin.Instance.Configuration.Instance.Langs)
                {
                    if (text != "")
                    {
                        text += ", ";
                    }
                    text += lang.id + " (" + lang.name + ")";
                }
                Plugin.SDLL.MultiSay(player, Plugin.plugin, "langs", Color.yellow, text);
            }
            else
            {
                if (Plugin.Instance.Configuration.Instance.Langs.Exists(x => x.id == command[0]))
                {
                    Plugin.Instance.Database.UpdateInfo(player, command[0]);
                    Plugin.SDLL.MultiSay(player, Plugin.plugin, "success", Color.yellow, Plugin.Instance.Configuration.Instance.Langs.Find(x => x.id == command[0]).name);
                }
                else if (Plugin.Instance.Configuration.Instance.Langs.Exists(x => x.name.ToLower() == command[0].ToLower()))
                {
                    Plugin.Instance.Database.UpdateInfo(player, Plugin.Instance.Configuration.Instance.Langs.Find(x => x.name == command[0]).id);
                    Plugin.SDLL.MultiSay(player, Plugin.plugin, "success", Color.yellow, command[0]);
                }
                else
                {
                    Plugin.SDLL.MultiSay(player, Plugin.plugin, "nolang", Color.yellow);
                }
            }
        }
 public void GetInfo(UnturnedPlayer player)
 {
     if (Plugin.Instance.Configuration.Instance.isDB)
     {
         MySqlConnection mySqlConnection = this.createConnection();
         MySqlCommand    mySqlCommand    = mySqlConnection.CreateCommand();
         mySqlCommand.CommandText = string.Concat(new string[]
         {
             "SELECT * FROM ",
             Plugin.Instance.Configuration.Instance.mysqltable,
             " WHERE Steam64ID = '",
             player.CSteamID.m_SteamID.ToString(),
             "';"
         });
         mySqlConnection.Open();
         MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();
         bool            hasRows         = mySqlDataReader.HasRows;
         if (hasRows)
         {
             mySqlDataReader.Read();
             Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
             component.lang = mySqlDataReader.GetString("Language");
             mySqlDataReader.Close();
             mySqlDataReader.Dispose();
             if (!Plugin.Instance.Configuration.Instance.Langs.Exists(x => x.id == component.lang))
             {
                 component.lang = Plugin.Instance.Configuration.Instance.startlang;
                 Plugin.SDLL.MultiSay(player, Plugin.plugin, "changelang", Color.yellow, component.lang);
             }
         }
         else
         {
             mySqlDataReader.Close();
             mySqlDataReader.Dispose();
             Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
             component.lang           = Plugin.Instance.Configuration.Instance.startlang;
             mySqlCommand.CommandText = string.Concat(new string[]
             {
                 "INSERT INTO ",
                 Plugin.Instance.Configuration.Instance.mysqltable,
                 " (`Steam64ID`,`Language`) VALUES('",
                 player.CSteamID.m_SteamID.ToString(),
                 "', '",
                 component.lang,
                 "')"
             });
             mySqlCommand.ExecuteNonQuery();
         }
         mySqlConnection.Close();
     }
     else
     {
         if (Plugin.Instance.Configuration.Instance.Users.Exists(x => x.playerid == player.CSteamID.m_SteamID))
         {
             Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
             component.lang = Plugin.Instance.Configuration.Instance.Users.Find(x => x.playerid == player.CSteamID.m_SteamID).lang;
             if (!Plugin.Instance.Configuration.Instance.Langs.Exists(x => x.id == component.lang))
             {
                 component.lang = Plugin.Instance.Configuration.Instance.startlang;
                 Plugin.SDLL.MultiSay(player, Plugin.plugin, "changelang", Color.yellow, component.lang);
             }
         }
         else
         {
             Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
             component.lang = Plugin.Instance.Configuration.Instance.startlang;
             Plugin.Instance.Configuration.Instance.Users.Add(new Config.User {
                 lang = component.lang, playerid = player.CSteamID.m_SteamID
             });
             Plugin.Instance.Configuration.Save();
         }
     }
 }
 public static string GetLangName(UnturnedPlayer player)
 {
     Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
     return(Instance.Configuration.Instance.Langs.Find(x => x.id == component.lang).name);
 }
        /*[HarmonyPatch(typeof(UnturnedChat), "Say")]
         * public static class UnturnedChat_Say_Patch
         * {
         *  [HarmonyPrefix]
         *  public static bool UnturnedChat_Say_Prefix(CSteamID CSteamID, string message, Color color, bool rich)
         *  {
         *      if (CSteamID.ToString() == "0")
         *      {
         *          Rocket.Core.Logging.Logger.Log(message, ConsoleColor.Gray);
         *          return;
         *      }
         *      SteamPlayer steamPlayer = PlayerTool.getSteamPlayer(CSteamID);
         *      foreach (string text in UnturnedChat.wrapMessage(message))
         *      {
         *          ChatManager.serverSendMessage(text, color, null, steamPlayer, EChatMode.SAY, null, rich);
         *      }
         *      return true;
         *  }
         * }*/

        public static string GetLang(UnturnedPlayer player)
        {
            Plugin.PlayerComponent component = player.GetComponent <Plugin.PlayerComponent>();
            return(component.lang);
        }