Skip to content

Commit a8ee094

Browse files
authored
Add files via upload
1 parent 0c3b99d commit a8ee094

File tree

10 files changed

+245
-9
lines changed

10 files changed

+245
-9
lines changed

EffectDisplay/API/Features.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using EffectDisplay.Features;
2+
using Exiled.API.Features;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace EffectDisplay.API
10+
{
11+
public class Features
12+
{
13+
/// <summary>
14+
/// Does it allow the player to see the status of effects?
15+
/// </summary>
16+
/// <param name="userid">user id</param>
17+
/// <returns>true if allow</returns>
18+
public static bool IsEffectShowAllow(string userid)
19+
{
20+
bool IsEnabled = !Main.Instance.DataBaseManager.GetMemberChose(userid);
21+
return IsEnabled;
22+
}
23+
/// <summary>
24+
/// Does it allow the player to see the status of effects?
25+
/// </summary>
26+
/// <param name="player"><see cref="Player"/> object</param>
27+
/// <returns></returns>
28+
public static bool IsEffectShowAllow(Player player)
29+
{
30+
if (player == null) return true;
31+
else
32+
{
33+
bool IsEnabled = !Main.Instance.DataBaseManager.GetMemberChose(player.UserId);
34+
return IsEnabled;
35+
}
36+
}
37+
/// <summary>
38+
/// Allows you to save a player in the database with a preset argument; if there is a user, then simply changes it
39+
/// </summary>
40+
/// <param name="player">The <see cref="Player"/> for which the action is applied</param>
41+
/// <param name="IsShow">The <see cref="bool"/> value for set</param>
42+
public static void SaveMemberWithArg(Player player, bool IsShow) => Main.Instance.DataBaseManager.SaveState(!IsShow, player.UserId);
43+
}
44+
}

EffectDisplay/Commands/EfParent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class EfParent : ParentCommand
1515

1616
public override void LoadGeneratedCommands()
1717
{
18-
RegisterCommand(new Turn());
18+
RegisterCommand(new display());
1919
RegisterCommand(new Check());
20-
RegisterCommand(new Total());
20+
RegisterCommand(new display());
2121
}
2222

2323
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)

EffectDisplay/Commands/display.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using CommandSystem;
2+
using EffectDisplay.Extension;
3+
using Exiled.API.Features;
4+
using EffectDisplay.Features;
5+
using EffectDisplay.Features.Serelization;
6+
using System;
7+
8+
namespace EffectDisplay.Commands
9+
{
10+
[CommandHandler(typeof(ClientCommandHandler))]
11+
[CommandHandler(typeof(RemoteAdminCommandHandler))]
12+
public class display : ICommand
13+
{
14+
public string Command { get; set; } = "display";
15+
16+
public string[] Aliases { get; set; } = Array.Empty<string>();
17+
18+
public string Description { get; set; } = "turn on or turn off display during the round";
19+
20+
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
21+
{
22+
Player player = Player.Get(sender);
23+
if (player == null)
24+
{
25+
response = "";
26+
return false;
27+
}
28+
else
29+
{
30+
try
31+
{
32+
bool toset = !Main.Instance.DataBaseManager.GetMemberChose(player.UserId);
33+
Main.Instance.DataBaseManager.SaveState(toset, player.UserId);
34+
response = "done";
35+
return true;
36+
}
37+
catch (Exception ex)
38+
{
39+
response = $"error: unkown error detected";
40+
Log.Debug($"[EffectDisplay] {ex.Message}");
41+
return false;
42+
}
43+
}
44+
}
45+
}
46+
}

EffectDisplay/EffectDisplay.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,15 @@
9696
</Reference>
9797
</ItemGroup>
9898
<ItemGroup>
99+
<Compile Include="API\Features.cs" />
99100
<Compile Include="Commands\Check.cs" />
100101
<Compile Include="Commands\EfParent.cs" />
101102
<Compile Include="Commands\Total.cs" />
102-
<Compile Include="Commands\Turn.cs" />
103+
<Compile Include="Commands\display.cs" />
103104
<Compile Include="Config.cs" />
104105
<Compile Include="EventHandler\RoundEvent.cs" />
106+
<Compile Include="Extension\LobbyChecker.cs" />
107+
<Compile Include="Extension\RueIHints.cs" />
105108
<Compile Include="Features\DataBaseManager.cs" />
106109
<Compile Include="Features\Serelization\UserData.cs" />
107110
<Compile Include="Main.cs" />

EffectDisplay/Extension/EffectReader.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ private IEnumerator<float> EffectListener()
7070
{
7171
break;
7272
}
73-
if (this.IsEnabled & !this._Player.IsDead)
73+
74+
if (this.IsEnabled & !this._Player.IsDead & LobbyChecker.IsLobby == false)
7475
{
7576
StringBuilder ShowningText = new StringBuilder();
7677
ShowningText.AppendLine("\n\n\n");
@@ -100,7 +101,14 @@ private IEnumerator<float> EffectListener()
100101

101102
}
102103
}
103-
_Player.ShowHint($"{ShowningText.ToString()}", 1);
104+
if (RueIHints.IsEnabled)
105+
{
106+
RueIHints.ShowHint(_Player, ShowningText.ToString(), TimeSpan.FromSeconds(1f));
107+
}
108+
else
109+
{
110+
_Player.ShowHint($"{ShowningText.ToString()}", 1);
111+
}
104112
}
105113
yield return Timing.WaitForSeconds(Main.Instance.Config.TextUpdateTime);
106114
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Exiled.API.Interfaces;
2+
using Exiled.Loader;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Reflection;
6+
7+
namespace EffectDisplay.Extension
8+
{
9+
// Lobby plugin conflict with EffectDisplay, added for remove it
10+
public class LobbyChecker
11+
{
12+
public const string Name = "Lobby";
13+
14+
public const string EventHandlers = "Lobby.EventHandlers";
15+
16+
public const string Parametr = "IsLobby";
17+
18+
/// <summary>
19+
/// Read only
20+
/// </summary>
21+
public static bool IsLobby
22+
{
23+
get
24+
{
25+
if (lobby == null) return false;
26+
else
27+
{
28+
try
29+
{
30+
Type eventhandler = lobby.GetType(EventHandlers);
31+
return (bool)eventhandler.GetField(Parametr).GetValue(null);
32+
}
33+
catch (Exception ex)
34+
{
35+
return false;
36+
}
37+
}
38+
}
39+
}
40+
41+
internal static Assembly lobby { get; private set; } = null;
42+
43+
public static bool LoadOrRefresh()
44+
{
45+
foreach (IPlugin<IConfig> plugin in Loader.Plugins)
46+
{
47+
if (plugin.Name == Name)
48+
{
49+
lobby = plugin.Assembly;
50+
break;
51+
}
52+
}
53+
if (lobby == null) return false;
54+
else
55+
{
56+
return true;
57+
}
58+
}
59+
}
60+
}

EffectDisplay/Extension/RueIHints.cs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Exiled.API.Features;
6+
using Exiled.Loader;
7+
8+
namespace EffectDisplay.Extension
9+
{
10+
public class RueIHints
11+
{
12+
public static bool IsEnabled { get; private set; } = false;
13+
14+
public static void ShowHint(ReferenceHub hub, string content, TimeSpan duration, float position = 0)
15+
{
16+
if (IsEnabled) { _shower(hub, content, position, duration); }
17+
else
18+
{
19+
Log.Debug("RueI not inited");
20+
return;
21+
}
22+
}
23+
public static void ShowHint(Player player, string content, TimeSpan duration, float position = 0)
24+
{
25+
if (IsEnabled) { _shower(player.ReferenceHub, content, position, duration); }
26+
else
27+
{
28+
Log.Debug("RueI not inited");
29+
return;
30+
}
31+
}
32+
33+
public static void InitRue()
34+
{
35+
IsEnabled = false;
36+
_shower = null;
37+
Assembly ruei = Loader.Dependencies.FirstOrDefault(x => x.GetName().Name == "RueI");
38+
if (ruei == null) { Log.Debug("RueI not found in dependencies"); return; }
39+
else
40+
{
41+
MethodInfo els = ruei.GetType("RueI.Extensions.ReflectionHelpers").GetMethod("GetElementShower");
42+
object action = els.Invoke(null, new object[] { });
43+
if (action is Action<ReferenceHub, string, float, TimeSpan> elst)
44+
{
45+
MethodInfo init = ruei.GetType("RueI.RueIMain").GetMethod("EnsureInit");
46+
if (init == null) return;
47+
else
48+
{
49+
init.Invoke(null, new object[] { });
50+
_shower = elst;
51+
IsEnabled = true;
52+
}
53+
}
54+
else
55+
{
56+
return;
57+
}
58+
}
59+
}
60+
private static Action<ReferenceHub, string, float, TimeSpan> _shower;
61+
}
62+
}

EffectDisplay/Features/Serelization/UserData.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ public class UserData
66
{
77
[BsonId]
88
public string UserId { get; set; }
9-
9+
/// <summary>
10+
/// if true, then the user is against the plugin’s action being visible on the screen
11+
/// </summary>
1012
public bool IsUsing { get; set; }
1113
}
1214
}

EffectDisplay/Main.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using EffectDisplay.Extension;
77
using MEC;
88
using System;
9+
using Exiled.Loader;
10+
using System.Linq;
911

1012
namespace EffectDisplay
1113
{
@@ -30,7 +32,16 @@ public class Main: Plugin<Config>
3032
public override void OnEnabled()
3133
{
3234
Instance = this;
33-
35+
/*
36+
if (Loader.Dependencies.FirstOrDefault(x => x.GetName().Name == "RueI") != null)
37+
{
38+
Log.Debug("RueI detected and try to init");
39+
RueIHints.InitRue();
40+
}*/
41+
if (LobbyChecker.LoadOrRefresh())
42+
{
43+
Log.Debug("Detected plugin Lobby");
44+
}
3445
if (!Directory.Exists(Paths.Configs + "/EffectDisplay"))
3546
{
3647
Log.Warn("The path to the file with the database was not found, we are creating");

EffectDisplay/Properties/AssemblyInfo.cs

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

0 commit comments

Comments
 (0)