-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathWebsitePlugin.cs
More file actions
71 lines (60 loc) · 2.18 KB
/
WebsitePlugin.cs
File metadata and controls
71 lines (60 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rocket.API;
using Rocket.Core.Plugins;
using Rocket.Core;
using Rocket.Unturned;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System.Threading;
using UnityEngine;
using Logger = Rocket.Core.Logging.Logger;
namespace WebsiteCommand
{
public class WebsitePlugin : RocketPlugin<WebsiteConfig>
{
public static WebsitePlugin Instance;
protected override void Load()
{
Instance = this;
U.Events.OnPlayerConnected += Events_OnPlayerConnected;
Logger.Log("WebsiteCommand has loaded!");
if (Configuration != null && Configuration.Instance.WebsiteCommands.Count != 0)
{
foreach (var command in Configuration.Instance.WebsiteCommands)
{
RocketWebsiteCommand cmd = new RocketWebsiteCommand(command.CommandName, command.Desc, command.Url, command.Help);
R.Commands.Register(cmd);
}
}
}
protected override void Unload()
{
Logger.Log("WebsiteCommand has Unloaded!");
U.Events.OnPlayerConnected -= Events_OnPlayerConnected;
foreach (var command in Configuration.Instance.WebsiteCommands)
{
R.Commands.DeregisterFromAssembly(this.Assembly);
}
}
void Events_OnPlayerConnected(UnturnedPlayer player)
{
if (player != null && Configuration.Instance.OpenUrlOnJoin)
{
StartCoroutine(StartDelayedUrlRequest(player));
}
}
public static void OpenUrl(UnturnedPlayer player, string url, string desc)
{
//player.Player.channel.send("askBrowserRequest", player.CSteamID, ESteamPacket.UPDATE_RELIABLE_BUFFER, desc, url);
player.Player.sendBrowserRequest(desc, url);
}
IEnumerator<WaitForSeconds> StartDelayedUrlRequest(UnturnedPlayer player)
{
yield return new WaitForSeconds(1.5f);
OpenUrl(player, Configuration.Instance.JoinUrl, Configuration.Instance.JoinDesc);
}
}
}