Advertisement
Guest User

PlayerCount

a guest
Apr 3rd, 2020
2,304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Oxide.Core;
  5. using Oxide.Core.Libraries.Covalence;
  6.  
  7. namespace Oxide.Plugins
  8. {
  9.     [Info("PlayerCount", "Wulf/lukespragg", "0.3.2", ResourceId = 2126)]
  10.     [Description("Shows a list and count of all online, non-hidden players")]
  11.  
  12.     class PlayerList : CovalencePlugin
  13.     {
  14.         #region Initialization
  15.  
  16.         const string permAllow = "playerlist.allow";
  17.         const string permHide = "playerlist.hide";
  18.  
  19.         bool adminSeparate;
  20.         string adminColor;
  21.         string test2;
  22.  
  23.         protected override void LoadDefaultConfig()
  24.         {
  25.             Config["Admin List Separate (true/false)"] = adminSeparate = GetConfig("Admin List Separate (true/false)", false);
  26.             Config["Admin Color (Hex Format or Name)"] = adminColor = GetConfig("Admin Color (Hex Format or Name)", "e68c17");
  27.             Config["Test command"] = test2 = GetConfig("Test command", "xxxd");
  28.  
  29.             SaveConfig();
  30.         }
  31.  
  32.         void Init()
  33.         {
  34.             LoadDefaultConfig();
  35.             LoadDefaultMessages();
  36.             permission.RegisterPermission(permAllow, this);
  37.             permission.RegisterPermission(permHide, this);
  38.         }
  39.  
  40.         #endregion
  41.  
  42.         #region Localization
  43.  
  44.         void LoadDefaultMessages()
  45.         {
  46.             // English
  47.             lang.RegisterMessages(new Dictionary<string, string>
  48.             {
  49.                 ["AdminCount"] = "{0} admin online",
  50.                 ["AdminList"] = "Admin online ({0}): {1}",
  51.                 ["NobodyOnline"] = "No players are currently online",
  52.                 ["NotAllowed"] = "You are not allowed to use the '{0}' command",
  53.                 ["OnlyYou"] = "You are the only one online!",
  54.                 ["PlayerCount"] = "{0} player(s) online",
  55.                 ["PlayerList"] = "Players online ({0}): {1}"
  56.             }, this);
  57.  
  58.             // French
  59.             lang.RegisterMessages(new Dictionary<string, string>
  60.             {
  61.                 ["AdminCount"] = "{0} administrateurs en ligne",
  62.                 ["AdminList"] = "Administrateurs en ligne ({0}) : {1}",
  63.                 ["NobodyOnline"] = "Aucuns joueurs ne sont actuellement en ligne",
  64.                 ["NotAllowed"] = "Vous n’êtes pas autorisé à utiliser la commande « {0} »",
  65.                 ["OnlyYou"] = "Vous êtes la seule personne en ligne !",
  66.                 ["PlayerCount"] = "{0} joueur(s) en ligne",
  67.                 ["PlayerList"] = "Joueurs en ligne ({0}) : {1}"
  68.             }, this, "fr");
  69.  
  70.             // German
  71.             lang.RegisterMessages(new Dictionary<string, string>
  72.             {
  73.                 ["AdminCount"] = "{0} Administratoren online",
  74.                 ["AdminList"] = "Administratoren online ({0}): {1}",
  75.                 ["NobodyOnline"] = "Keine Spieler sind gerade online",
  76.                 ["NotAllowed"] = "Sie sind nicht berechtigt, verwenden Sie den Befehl '{0}'",
  77.                 ["OnlyYou"] = "Du bist der einzige Online!",
  78.                 ["PlayerCount"] = "{0} Spieler online",
  79.                 ["PlayerList"] = "Spieler online ({0}): {1}"
  80.             }, this, "de");
  81.  
  82.             // Russian
  83.             lang.RegisterMessages(new Dictionary<string, string>
  84.             {
  85.                 ["AdminCount"] = "{0} администраторы онлайн",
  86.                 ["AdminList"] = "Администраторы онлайн ({0}): {1}",
  87.                 ["NobodyOnline"] = "Ни один из игроков онлайн",
  88.                 ["NotAllowed"] = "Нельзя использовать команду «{0}»",
  89.                 ["OnlyYou"] = "Вы являетесь единственным онлайн!",
  90.                 ["PlayerCount"] = "{0} игрока (ов) онлайн",
  91.                 ["PlayerList"] = "Игроков онлайн ({0}): {1}"
  92.             }, this, "ru");
  93.  
  94.             // Spanish
  95.             lang.RegisterMessages(new Dictionary<string, string>
  96.             {
  97.                 ["AdminCount"] = "{0} administradores en línea",
  98.                 ["AdminList"] = "Los administradores en línea ({0}): {1}",
  99.                 ["NobodyOnline"] = "No hay jugadores están actualmente en línea",
  100.                 ["NotAllowed"] = "No se permite utilizar el comando '{0}'",
  101.                 ["OnlyYou"] = "Usted es el único en línea!",
  102.                 ["PlayerCount"] = "{0} jugadores en línea",
  103.                 ["PlayerList"] = "Jugadores en línea ({0}): {1}"
  104.             }, this, "es");
  105.         }
  106.  
  107.         #endregion
  108.  
  109.         #region Commands
  110.  
  111.         [Command("online", "players", "pop", test2)]
  112.         void OnlineCommand(IPlayer player, string command, string[] args)
  113.         {
  114.             if (!player.HasPermission(permAllow))
  115.             {
  116.                 player.Reply(Lang("NotAllowed", player.Id, command));
  117.                 return;
  118.             }
  119.  
  120.             var adminCount = players.Connected.Count(p => p.IsAdmin && !p.HasPermission(permHide));
  121.             var playerCount = players.Connected.Count(p => !p.IsAdmin && !p.HasPermission(permHide));
  122.  
  123.             player.Reply($"{Lang("AdminCount", player.Id, adminCount)}, {Lang("PlayerCount", player.Id, playerCount)}");
  124.         }
  125.         #endregion
  126.  
  127.         #region Helpers
  128.  
  129.         T GetConfig<T>(string name, T value) => Config[name] == null ? value : (T)Convert.ChangeType(Config[name], typeof(T));
  130.  
  131.         string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
  132.  
  133.         #endregion
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement