-
Notifications
You must be signed in to change notification settings - Fork 0
/
Announcer.cs
92 lines (81 loc) · 2.79 KB
/
Announcer.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Cysharp.Threading.Tasks;
using OpenMod.Unturned.Plugins;
using OpenMod.API.Plugins;
using SDG.Unturned;
using System.Linq;
using System.Threading.Tasks;
using OpenMod.Core.Helpers;
[assembly: PluginMetadata("F.Announcer", DisplayName = "Announcer")]
namespace Announcer
{
public class Announcer : OpenModUnturnedPlugin
{
private readonly IConfiguration m_Configuration;
private readonly ILogger<Announcer> m_Logger;
private bool Load = false;
private int message = 0;
public Announcer(
IConfiguration configuration,
ILogger<Announcer> logger,
IServiceProvider serviceProvider) : base(serviceProvider)
{
m_Configuration = configuration;
m_Logger = logger;
}
#pragma warning disable 1998
protected override async UniTask OnLoadAsync()
#pragma warning restore 1998
{
m_Logger.LogInformation("Announcer Loaded");
m_Logger.LogInformation("FPlugins Discord: https://discord.gg/RuWChce");
Level.onLevelLoaded += OnLevelLoaded;
Load = true;
}
private void OnLevelLoaded(int level)
{
level++;
if(level == 2)
{
AsyncHelper.Schedule("Announcement Start", () => Announcement().AsTask());
}
}
#pragma warning disable 1998
protected override async UniTask OnUnloadAsync()
#pragma warning restore 1998
{
m_Logger.LogInformation("Announcer Unloaded");
Load = false;
}
private async UniTask Announcement()
{
await UniTask.SwitchToMainThread();
while(Load)
{
await Task.Delay(m_Configuration.Get<Config>().miliseconds);
var announces = m_Configuration.Get<Config>().announces;
if (message >= announces.Count())
{
message = 0;
}
var selected = announces[message];
ChatManager.serverSendMessage(selected.message.Replace("{", "<").Replace("}", ">"), UnityEngine.Color.white, null, null, EChatMode.GLOBAL, selected.url, selected.isrich);
message++;
}
}
}
public class Config
{
public List<Announce> announces { get; set; }
public int miliseconds { get; set; }
}
public class Announce
{
public string url { get; set; }
public string message { get; set; }
public bool isrich { get; set; }
}
}