Skip to content

Commit af3f12a

Browse files
authored
Add files via upload
1 parent 9544606 commit af3f12a

File tree

10 files changed

+136
-113
lines changed

10 files changed

+136
-113
lines changed

Components/UserEffectDisplayer.cs

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System;
99
using System.Collections.Generic;
1010
using System.Linq;
11-
using System.Linq.Expressions;
1211
using System.Text;
1312
using UnityEngine;
1413

@@ -36,11 +35,16 @@ public bool IsEnabled
3635
{
3736
Log.Debug($"{nameof(IsEnabled)}.Set: {Enabled} -> {value}.");
3837
Enabled = value;
39-
Timing.KillCoroutines(Current);
40-
if (value)
41-
{
42-
Current = Timing.RunCoroutine(PlayerEffectShower());
43-
}
38+
if (value == false) Timing.KillCoroutines(Current);
39+
else Current = Timing.RunCoroutine(PlayerEffectShower());
40+
}
41+
}
42+
43+
public Configs cfg
44+
{
45+
get
46+
{
47+
return Plugin.Instance.Config ?? new Configs();
4448
}
4549
}
4650

@@ -49,82 +53,64 @@ private void Awake()
4953
Log.Debug($"{nameof(Awake)}: Initing component.");
5054
player = Player.Get(gameObject);
5155
Log.Debug($"{nameof(Awake)}: {player.Nickname} Awake and adding component handling.");
52-
if (player.IsAllow())
53-
{
54-
Log.Debug($"{nameof(Awake)}: Starting Corountine.");
55-
Timing.RunCoroutine(PlayerEffectShower());
56-
}
57-
else
58-
{
59-
this.IsEnabled = false;
60-
Timing.KillCoroutines(this.Current);
61-
return;
62-
}
56+
if (player.GetIsAllow()) Current = Timing.RunCoroutine(PlayerEffectShower());
57+
else Destroy(this);
58+
}
59+
60+
private string GenerateString(CustomPlayerEffects.StatusEffectBase effect)
61+
{
62+
string processingline = cfg.EffectLine[effect.Classification];
63+
if (string.IsNullOrWhiteSpace(processingline)) return string.Empty;
64+
processingline = processingline.Replace("%time%", (int)effect.Duration == 0 ? "inf" : ((int)effect.TimeLeft).ToString());
65+
processingline = processingline.Replace("%duration%", (int)effect.Duration == 0 ? "inf" : effect.Duration.ToString());
66+
processingline = processingline.Replace("%effect%", cfg.GetName(effect.GetEffectType()));
67+
processingline = processingline.Replace("%intensity%", effect.Intensity.ToString());
68+
Log.Debug($"{nameof(PlayerEffectShower)}: Line {processingline} created");
69+
return processingline;
6370
}
6471

6572
private IEnumerator<float> PlayerEffectShower()
6673
{
67-
Configs cfg = Plugin.Instance.Config;
6874
for (; ; )
6975
{
70-
if (player == null)
71-
{
72-
Log.Debug($"{nameof(PlayerEffectShower)}: Player is null break yield");
73-
yield break;
74-
}
75-
if (IsEnabled == false)
76+
if (player == null || IsEnabled == false)
7677
{
77-
Log.Debug($"{nameof(PlayerEffectShower)}: IsEnabled - {IsEnabled} disabled, break yield");
78+
Log.Debug($"{nameof(PlayerEffectShower)}: Player is null or component is disabled, break yield");
7879
yield break;
7980
}
80-
if (player.IsDead | Plugin.Instance.Config.IgnoredRoles.Contains(player.Role.Type))
81+
if (player.IsDead || Plugin.Instance.Config.IgnoredRoles.Contains(player.Role.Type))
8182
{
8283
yield return Timing.WaitForSeconds(2);
8384
continue;
8485
}
8586
if (player.ActiveEffects.Where(x => !Plugin.Instance.Config.BlackList.Contains(x.GetEffectType())).Count() == 0)
8687
{
87-
yield return Timing.WaitForSeconds(0.1f);
88+
yield return Timing.WaitForSeconds(2f);
8889
continue;
8990
}
91+
9092
StringBuilder InfoLine = new StringBuilder();
91-
foreach (var item in player.ActiveEffects)
93+
foreach (CustomPlayerEffects.StatusEffectBase item in player.ActiveEffects)
9294
{
95+
if (Plugin.Instance.Config.BlackList.Contains(item.GetEffectType())) continue;
9396
try
9497
{
95-
if (Plugin.Instance.Config.BlackList.Contains(item.GetEffectType())) continue;
96-
try
97-
{
98-
string processingline = cfg.EffectLine[item.Classification];
99-
if (string.IsNullOrWhiteSpace(processingline)) continue;
100-
processingline = processingline.Replace("%time%", (int)item.Duration == 0 ? "inf" : ((int)item.TimeLeft).ToString());
101-
processingline = processingline.Replace("%duration%", (int)item.Duration == 0 ? "inf" : item.Duration.ToString());
102-
processingline = processingline.Replace("%effect%", cfg.GetName(item.GetEffectType()));
103-
processingline = processingline.Replace("%intensity%", item.Intensity.ToString());
104-
Log.Debug($"{nameof(PlayerEffectShower)}: Line {processingline} created");
105-
InfoLine.AppendLine(processingline);
106-
}
107-
catch (Exception e)
108-
{
109-
Log.Debug($"{nameof(PlayerEffectShower)}: Exception {e.Message}");
110-
}
98+
string line = GenerateString(item);
99+
if (string.IsNullOrEmpty(line)) continue;
100+
InfoLine.AppendLine(line);
111101
}
112102
catch (Exception e)
113103
{
114104
Log.Debug($"{nameof(PlayerEffectShower)}: Exception {e.Message}");
115105
}
116106
}
107+
117108
string data = InfoLine.ToString();
118109
Log.Debug(data);
119-
try
120-
{
121-
data = $"<size={cfg.NativeHintSettings.FontSize}><align={cfg.NativeHintSettings.Aligment}>" + data + "</size></align>";
122-
player.ShowHint(data, 1f + (float)(player.Ping / 100f)); // display a message taking into account the player's ping for a smooth update
123-
}
124-
catch (Exception e)
125-
{
126-
Log.Debug($"{nameof(PlayerEffectShower)}: Exception {e.Message}");
127-
}
110+
111+
data = $"<size={cfg.NativeHintSettings.FontSize}><align={cfg.NativeHintSettings.Aligment}>" + data + "</size></align>";
112+
player?.ShowHint(data, 1f + (float)(player.Ping / 100f)); // display a message taking into account the player's ping for a smooth update
113+
128114
Log.Debug($"{nameof(PlayerEffectShower)}: Iteration {player.Nickname}: processed.");
129115
yield return Timing.WaitForSeconds(cfg.UpdateTime);
130116
}

Configs.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public class Configs: IConfig
1818
public bool IsEnabled { get; set; } = true;
1919
[Description("will information be displayed for the developer, will help when errors are detected")]
2020
public bool Debug { get; set; } = false;
21-
[Description("will merge with other Hint service providers (for example HintServiceMeow) - if they are installed, it will switch itself")]
22-
public bool ThirdParty { get; set; } = true;
2321
[Description("will a database be used")]
2422
public bool DataBaseEnabled { get; set; } = true;
2523
[Description("the time period for which information is updated")]
@@ -72,6 +70,14 @@ public class Configs: IConfig
7270
public string TwoButtonEnabled { get; set; } = "ON";
7371
[Description("Second option name")]
7472
public string TwoButtonDisabled { get; set; } = "OFF";
73+
[Description("The player sees this message if you have disabled the database or the file was not found, meaning it is not allowed to be used.")]
74+
public string MessageWnenDataBaseDisabled { get; set; } = "The specified server does not have this function.";
75+
[Description("The player sees this message when turning on the display component.")]
76+
public string MessageWhenPlayerEnabled { get; set; } = "You have <b>enabled</b> the display of active effects.";
77+
[Description("The player sees this message when turning off the display component.")]
78+
public string MessageWhenPlayerDisabled { get; set; } = "You have <b>disabled</b> the display of active effects.";
79+
[Description("The player sees this message when the server was unable to find the player component or the player himself (for example, a call from the Dedicated Server)")]
80+
public string MessageWhenErrorOccurred { get; set; } = "The player's effects display component was not found, or the player himself was not found.";
7581
/// <summary>
7682
/// Return effect name from <see cref="EffectTranslation"/> if not found return <see cref="EffectType"/> as <see cref="string"></see>
7783
/// </summary>

EffectDisplay.csproj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
5454
<DebugSymbols>true</DebugSymbols>
5555
<OutputPath>bin\x64\Debug\</OutputPath>
56-
<DefineConstants>TRACE;Meow</DefineConstants>
56+
<DefineConstants>TRACE</DefineConstants>
5757
<DebugType>full</DebugType>
5858
<PlatformTarget>x64</PlatformTarget>
5959
<LangVersion>7.3</LangVersion>
@@ -81,6 +81,24 @@
8181
<OutputPath>bin\Meow\</OutputPath>
8282
<DefineConstants>TRACE;DEBUG;Meow</DefineConstants>
8383
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'RueiBild|AnyCPU'">
85+
<DebugSymbols>true</DebugSymbols>
86+
<OutputPath>bin\RueiBild\</OutputPath>
87+
<DefineConstants>DEBUG;TRACE</DefineConstants>
88+
<DebugType>full</DebugType>
89+
<PlatformTarget>AnyCPU</PlatformTarget>
90+
<LangVersion>7.3</LangVersion>
91+
<ErrorReport>prompt</ErrorReport>
92+
</PropertyGroup>
93+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'RueiBild|x64'">
94+
<DebugSymbols>true</DebugSymbols>
95+
<OutputPath>bin\x64\RueiBild\</OutputPath>
96+
<DefineConstants>TRACE;Ruie</DefineConstants>
97+
<DebugType>full</DebugType>
98+
<PlatformTarget>x64</PlatformTarget>
99+
<LangVersion>7.3</LangVersion>
100+
<ErrorReport>prompt</ErrorReport>
101+
</PropertyGroup>
84102
<ItemGroup>
85103
<Reference Include="0Harmony">
86104
<HintPath>..\..\..\..\AppData\Roaming\EXILED\Plugins\dependencies\0Harmony.dll</HintPath>
@@ -158,7 +176,6 @@
158176
</ItemGroup>
159177
<ItemGroup>
160178
<Compile Include="commands\display.cs" />
161-
<Compile Include="commands\test.cs" />
162179
<Compile Include="Components\UserEffectDisplayer.cs" />
163180
<Compile Include="Configs.cs" />
164181
<Compile Include="EventHandler\PlayerEvent.cs" />

EventHandler/PlayerEvent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Exiled.Events.EventArgs.Player;
55
using Exiled.Events.EventArgs.Server;
66

7+
using JetBrains.Annotations;
8+
79
using MEC;
810

911
namespace EffectDisplay.EventHandler
@@ -36,8 +38,9 @@ public PlayerEvent()
3638

3739
public void OnVerefied(VerifiedEventArgs e)
3840
{
41+
if (e.Player == null) return;
3942
Log.Debug(e.Player);
40-
e.Player?.GameObject.AddComponent<UserEffectDisplayer>();
43+
e.Player.GameObject.AddComponent<UserEffectDisplayer>();
4144
Log.Debug($"{nameof(OnVerefied)}: Added {nameof(UserEffectDisplayer)} components.");
4245
}
4346

Extensions/PlayerExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public static class PlayerExtensions
99
/// Returns the Allow parameter that determines the permission to show the display
1010
/// </summary>
1111
/// <param name="player"></param>
12-
public static bool IsAllow(this Player player) => Plugin.data.IsAllow(player.UserId);
12+
public static bool GetIsAllow(this Player player) => Plugin.data.IsAllow(player.UserId);
1313
/// <summary>
1414
/// Allows you to change the value of the IsAllow parameter
1515
/// </summary>
16-
public static void IsAllow(this Player player, bool IsAllow) => Plugin.data.IsAllow(player.UserId, IsAllow);
16+
public static void SetIsAllow(this Player player, bool IsAllow) => Plugin.data.IsAllow(player.UserId, IsAllow);
1717
}
1818
}

Features/DataBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ namespace EffectDisplay.Features
77
{
88
public class DataBase: IDisposable
99
{
10+
/// <summary>
11+
/// Makes it easier to understand the existence of a database and its enabled state
12+
/// </summary>
13+
public static bool IsInitializedAndEnabled { get
14+
{
15+
bool? d =Plugin.Instance?.Config.DataBaseEnabled;
16+
return Plugin.data != null && d.HasValue ? d.Value : false;
17+
}
18+
}
19+
1020
private string Path;
1121

1222
private LiteDatabase db;

Features/GitHubUpdater.cs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,24 @@ public class GithubUpdater
1111
{
1212
public const string API_Update = "https://api.github.com/repos/{owner}/{repo}/releases/latest";
1313

14-
private string Owner { get; set; } = string.Empty;
15-
16-
private string Repository { get; set; } = string.Empty;
17-
18-
private Version LastDetected = new Version(0, 0, 0);
19-
20-
public Version Version
21-
{
22-
get
23-
{
24-
return GetLatest();
25-
}
26-
}
27-
28-
public GithubUpdater(string owner, string repository)
14+
public static Task<Version> GetLatestAsync(string owner, string repository)
2915
{
30-
Owner = owner;
31-
Repository = repository;
32-
}
33-
34-
private Version GetLatest()
35-
{
36-
using (HttpClient client = new HttpClient())
16+
return Task.Run(async () =>
3717
{
38-
try
39-
{
40-
HttpResponseMessage res = client.GetAsync(API_Update.Replace("{owner}", Owner).Replace("{repo}", Repository)).Result;
41-
JObject js = JObject.Parse(res.Content.ReadAsStringAsync().Result);
42-
return Version.Parse((string)js["tag_name"]);
43-
}
44-
catch (Exception ex)
18+
using (HttpClient client = new HttpClient())
4519
{
46-
return new Version(0, 0, 0);
20+
try
21+
{
22+
HttpResponseMessage res = await client.GetAsync(API_Update.Replace("{owner}", owner).Replace("{repo}", repository));
23+
JObject js = JObject.Parse(res.Content.ReadAsStringAsync().Result);
24+
return Version.Parse((string)js["tag_name"]);
25+
}
26+
catch (Exception ex)
27+
{
28+
return new Version(0, 0, 0);
29+
}
4730
}
48-
}
31+
});
4932
}
5033
}
51-
}
34+
}

Plugin.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,41 @@ public class Plugin : Plugin<Configs>
2626

2727
private PlayerEvent Event { get; set; }
2828

29-
private GithubUpdater iUpdater { get; set; }
30-
3129
public static bool HintServiceMeowDetected { get; private set; } = false;
3230

3331
public override void OnEnabled()
3432
{
3533
DBCondition();
3634
Instance = this;
37-
iUpdater = new GithubUpdater("NOTIF-API", "EffectDisplay");
3835
data = new DataBase();
3936
Event = new PlayerEvent();
4037
SubscribeEvents();
4138
base.OnEnabled();
42-
// Background update task.
43-
Task.Run(() =>
39+
// Background update check task.
40+
if (Config.CheckForUpdate)
4441
{
45-
Version latest = iUpdater.Version;
46-
if (latest == null || latest == new Version(0, 0, 0)) return;
47-
Log.Debug($"Current version: [{this.Version.ToString()}] latest version detected is {latest.ToString()}");
48-
if (Version >= latest) return;
49-
Log.Warn("New version of EffectDisplay plugin found");
50-
});
42+
43+
Task.Run(async () =>
44+
{
45+
Version ver = await GithubUpdater.GetLatestAsync("NOTIF-API", "EffectDisplay");
46+
if (ver == null || ver == new Version(0, 0, 0))
47+
{
48+
Log.Debug($"{nameof(OnEnabled)}[Task]: Failed to check for updates.");
49+
return;
50+
}
51+
else
52+
{
53+
if (Version < ver)
54+
{
55+
Log.Warn($"A new version of the plugin is available: {ver}. You are using version {Version}. Download it from\nhttps://github.com/NOTIF-API/EffectDisplay/releases/latest");
56+
return;
57+
}
58+
}
59+
});
60+
}
5161
}
5262
public override void OnDisabled()
5363
{
54-
iUpdater = null;
5564
UnsubscribeEvents();
5665
data.Dispose();
5766
data = null;
@@ -85,6 +94,8 @@ private void DBCondition()
8594
else
8695
{
8796
string file_path = Path.Combine(this.Config.PathToDataBase, this.Config.DatabaseName);
97+
string extension = Path.GetExtension(file_path);
98+
if (extension != ".db") file_path.Replace(extension, ".db");
8899
// if folder do not detected creating it with file
89100
if (!Directory.Exists(this.Config.PathToDataBase))
90101
{

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Можно задать все значения или принять номера сборки и редакции по умолчанию
3333
// используя "*", как показано ниже:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.7.0.0")]
36-
[assembly: AssemblyFileVersion("2.7.0.0")]
35+
[assembly: AssemblyVersion("2.8.0.0")]
36+
[assembly: AssemblyFileVersion("2.8.0.0")]

0 commit comments

Comments
 (0)