Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. using Rocket.API;
  2. using System.Collections;
  3. using Rocket.API.Collections;
  4. using Rocket.Core.Logging;
  5. using Rocket.Core.Plugins;
  6. using Rocket.Unturned;
  7. using Rocket.Unturned.Chat;
  8. using Rocket.Unturned.Player;
  9. using UnityEngine;
  10. using System;
  11.  
  12. namespace SilK.MOTD
  13. {
  14.     public class MOTD : RocketPlugin<MOTDConfiguration>
  15.     {
  16.         public static MOTD Instance;
  17.         protected override void Load()
  18.         {
  19.             Instance = this;
  20.             U.Events.OnPlayerConnected += Events_OnPlayerConnected;
  21.         }
  22.         protected override void Unload()
  23.         {
  24.             U.Events.OnPlayerConnected -= Events_OnPlayerConnected;
  25.         }
  26.  
  27.         private void Events_OnPlayerConnected(UnturnedPlayer player)
  28.         {
  29.             bool Votemessage = true;
  30.             var url = String.Format("https://unturned-servers.net/api/?object=votes&element=claim&key={0}&steamid={1}", Configuration.Instance.VoteAPI, player.CSteamID);
  31.  
  32.             if (Configuration.Instance.Enabled)
  33.             {
  34.                 WWW www = new WWW(url);
  35.                 StartCoroutine(WaitForRequest(www));
  36.  
  37.                 if (www.text == "0")
  38.                 {
  39.                     Votemessage = true;
  40.                 }
  41.                 else
  42.                 {
  43.                     Votemessage = false;
  44.                 }
  45.             }
  46.  
  47.             if (Configuration.Instance.Enabled && Configuration.Instance.ShowOnConnect && Votemessage && player.HasPermission("motd"))
  48.             {
  49.                 StartCoroutine(ExecuteAfterTime(player, 6));
  50.             }
  51.         }
  52.  
  53.         IEnumerator WaitForRequest(WWW www)
  54.         {
  55.             yield return www;
  56.         }
  57.  
  58.             IEnumerator ExecuteAfterTime(UnturnedPlayer player, float time)
  59.  
  60.         {
  61.             yield return new WaitForSeconds(time);
  62.  
  63.             UnturnedChat.Say(player, Translate("show_motd"));
  64.             player.Player.sendBrowserRequest(Configuration.Instance.Message, Configuration.Instance.Link);
  65.             Rocket.Core.Logging.Logger.Log(Translate("show_motd_log", player.DisplayName));
  66.         }
  67.  
  68.         public override TranslationList DefaultTranslations
  69.         {
  70.             get
  71.             {
  72.                 return new TranslationList
  73.                 {
  74.                     {
  75.                         "show_motd",
  76.                         "Showing the Message Of The Day."
  77.                     },
  78.                     {
  79.                         "show_motd_log",
  80.                         "Showing \"{0}\" the Message Of The Day."
  81.                     },
  82.                     {
  83.                         "plugin_disabled",
  84.                         "Plugin Disabled."
  85.                     },
  86.                     {
  87.                         "invalid_parameters",
  88.                         "Invalid Parameters."
  89.                     }
  90.                 };
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement