Skip to content

Commit de8d35d

Browse files
retardation
1 parent 46d94c1 commit de8d35d

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

NWAPI-WelcomeMessage/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class Config
66
{
77
[Description("The message to display to players when they join the server.")]
88
public string WelcomeMessage { get; set; } = "Welcome %playername%!";
9+
public float Delay { get; set; } = 3f;
910
[Description("The duration of the message in seconds.")]
1011
public ushort Duration { get; set; } = 5;
1112
[Description("Whether or not to use broacasts. If false, hints will be used instead")]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace NWAPI_WelcomeMessage
2+
{
3+
using MEC;
4+
using PluginAPI.Core;
5+
using PluginAPI.Core.Attributes;
6+
using PluginAPI.Enums;
7+
8+
public class EventHandler
9+
{
10+
[PluginEvent(ServerEventType.PlayerJoined)]
11+
public void OnPlayerJoin(Player player)
12+
{
13+
Timing.CallDelayed(1f, () =>
14+
{
15+
player.GameObject.AddComponent<WelcomeMessageComponent>();
16+
});
17+
}
18+
}
19+
}

NWAPI-WelcomeMessage/NWAPI-WelcomeMessage.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<AssemblyName>moddedmcplayer_NWAPI-WelcomeMessage</AssemblyName>
1212
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<LangVersion>9</LangVersion>
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,16 +34,19 @@
3334
</PropertyGroup>
3435
<ItemGroup>
3536
<Reference Include="Assembly-CSharp">
36-
<HintPath>..\..\..\..\..\Steam\steamapps\common\SCP Secret Laboratory Dedi PBeta\SCPSL_Data\Managed\Assembly-CSharp-Publicized.dll</HintPath>
37+
<HintPath>$(EXILED_REFERENCES)\Assembly-CSharp-Publicized.dll</HintPath>
3738
</Reference>
3839
<Reference Include="Assembly-CSharp-firstpass">
3940
<HintPath>$(EXILED_REFERENCES)\Assembly-CSharp-firstpass.dll</HintPath>
4041
</Reference>
42+
<Reference Include="CommandSystem.Core">
43+
<HintPath>$(EXILED_REFERENCES)\CommandSystem.Core.dll</HintPath>
44+
</Reference>
4145
<Reference Include="Mirror">
42-
<HintPath>..\..\..\..\..\Steam\steamapps\common\SCP Secret Laboratory Dedi PBeta\SCPSL_Data\Managed\Mirror.dll</HintPath>
46+
<HintPath>$(EXILED_REFERENCES)\Mirror.dll</HintPath>
4347
</Reference>
44-
<Reference Include="PluginAPI, Version=12.0.0.0, Culture=neutral, processorArchitecture=Amd64">
45-
<HintPath>..\packages\Northwood.PluginAPI.12.0.0-rc.1\lib\net48\PluginAPI.dll</HintPath>
48+
<Reference Include="PluginAPI, Version=13.1.0.0, Culture=neutral, processorArchitecture=Amd64">
49+
<HintPath>..\packages\Northwood.PluginAPI.13.1.0\lib\net48\PluginAPI.dll</HintPath>
4650
</Reference>
4751
<Reference Include="System" />
4852
<Reference Include="System.Core" />
@@ -57,8 +61,10 @@
5761
</ItemGroup>
5862
<ItemGroup>
5963
<Compile Include="Config.cs" />
64+
<Compile Include="EventHandler.cs" />
6065
<Compile Include="Plugin.cs" />
6166
<Compile Include="Properties\AssemblyInfo.cs" />
67+
<Compile Include="WelcomeMessageComponent.cs" />
6268
</ItemGroup>
6369
<ItemGroup>
6470
<None Include="packages.config" />

NWAPI-WelcomeMessage/Plugin.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
namespace NWAPI_WelcomeMessage
22
{
3-
using Hints;
4-
using MEC;
5-
using PluginAPI.Core;
63
using PluginAPI.Core.Attributes;
7-
using PluginAPI.Enums;
84
using PluginAPI.Events;
95

106
public class Plugin
117
{
12-
[PluginEntryPoint("WelcomeMessage", "1.1.1", "Displays a welcome message when users join.", "moddedmcplayer")]
13-
void Enabled()
8+
public static Plugin Singleton;
9+
10+
[PluginEntryPoint("WelcomeMessage", "1.1.2", "Displays a welcome message when users join.", "moddedmcplayer")]
11+
public void Enabled()
1412
{
15-
EventManager.RegisterEvents(this);
13+
Singleton = this;
14+
EventManager.RegisterEvents(this, new EventHandler());
1615
}
1716

18-
[PluginEvent(ServerEventType.PlayerJoined)]
19-
void OnPlayerJoin(Player player)
17+
[PluginUnload]
18+
public void Disabled()
2019
{
21-
Timing.CallDelayed(4f, () =>
22-
{
23-
if(Config.UseBroadcasts)
24-
Broadcast.Singleton.TargetAddElement(player.ReferenceHub.characterClassManager.connectionToClient, Config.WelcomeMessage.Replace("%playername%", player.Nickname), Config.Duration, Broadcast.BroadcastFlags.Normal);
25-
else
26-
player.ReceiveHint(Config.WelcomeMessage.Replace("%playername%", player.Nickname), Config.Duration);
27-
});
20+
EventManager.UnregisterEvents<EventHandler>(this);
2821
}
2922

3023
[PluginConfig]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace NWAPI_WelcomeMessage
2+
{
3+
using PluginAPI.Core;
4+
using UnityEngine;
5+
6+
public class WelcomeMessageComponent : MonoBehaviour
7+
{
8+
private Player player;
9+
private float ticks;
10+
private bool ready = false;
11+
private void Awake()
12+
{
13+
player = Player.Get(GetComponent<ReferenceHub>());
14+
ticks = Plugin.Singleton.Config.Delay;
15+
ready = true;
16+
}
17+
18+
private void FixedUpdate()
19+
{
20+
if (!ready)
21+
return;
22+
if (ticks > 0)
23+
{
24+
ticks -= Time.fixedDeltaTime;
25+
return;
26+
}
27+
28+
if(Plugin.Singleton.Config.UseBroadcasts)
29+
Broadcast.Singleton
30+
.TargetAddElement(player.ReferenceHub.characterClassManager.connectionToClient,
31+
Plugin.Singleton.Config.WelcomeMessage.Replace("%playername%", player.Nickname),
32+
Plugin.Singleton.Config.Duration, Broadcast.BroadcastFlags.Normal);
33+
else
34+
player.ReceiveHint(Plugin.Singleton.Config.WelcomeMessage.Replace("%playername%", player.Nickname), Plugin.Singleton.Config.Duration);
35+
Destroy(this);
36+
}
37+
}
38+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Northwood.PluginAPI" version="12.0.0-rc.1" targetFramework="net48" />
43
<package id="YamlDotNet" version="11.0.1" targetFramework="net48" />
54
</packages>

0 commit comments

Comments
 (0)