forked from RocketModPlugins/WebsiteCommand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebsiteCommandsPlugin.cs
44 lines (37 loc) · 1.41 KB
/
WebsiteCommandsPlugin.cs
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
using Rocket.API.Commands;
using Rocket.API.DependencyInjection;
using Rocket.API.Eventing;
using Rocket.Core.Player.Events;
using Rocket.Core.Plugins;
using Rocket.Unturned.Player;
namespace WebsiteCommand
{
public class WebsiteCommandsPlugin : Plugin<WebsiteConfig>, IEventListener<PlayerConnectedEvent>
{
public WebsiteCommandsPlugin(IDependencyContainer container) : base("WebsiteCommands", container)
{
}
protected override void OnLoad(bool isFromReload)
{
var provider = (WebsiteCommandProvider) Container.Resolve<ICommandProvider>("website_commands");
if(isFromReload)
provider.Rebuild();
EventManager.AddEventListener(this, this);
Logger.Log("WebsiteCommand has loaded!");
}
protected override void OnUnload()
{
Logger.Log("WebsiteCommand has Unloaded!");
}
public static void OpenUrl(UnturnedPlayer player, string url, string description)
{
player.NativePlayer.sendBrowserRequest(description, url);
}
public void HandleEvent(IEventEmitter emitter, PlayerConnectedEvent @event)
{
if (!ConfigurationInstance.OpenUrlOnJoin || !(@event.Player is UnturnedPlayer player))
return;
OpenUrl(player, ConfigurationInstance.JoinUrl, ConfigurationInstance.JoinDesc);
}
}
}