|
1 | | -using PluginAPI.Core; |
2 | | -using PluginAPI.Core.Attributes; |
3 | | -using PluginAPI.Enums; |
4 | | -using FormatWith; |
5 | | - |
6 | | -namespace SB_WelcomeMessage |
7 | | -{ |
8 | | - public class Plugin |
9 | | - { |
10 | | - public static Plugin Singleton; |
11 | | - |
12 | | - [PluginConfig] public Config Config; |
13 | | - |
14 | | - public const string Version = "1.0.0"; |
15 | | - |
16 | | - [PluginPriority(LoadPriority.Highest)] |
17 | | - [PluginEntryPoint("JoinMessage-System", Version, "Shows a Broadcast Message in the top of the Screen of the joining player.", "SpaceBuddy")] |
18 | | - void LoadPlugin() |
19 | | - { |
20 | | - Singleton = this; |
21 | | - PluginAPI.Events.EventManager.RegisterEvents(this); |
22 | | - } |
23 | | - |
24 | | - [PluginEvent(ServerEventType.PlayerJoined)] |
25 | | - |
26 | | - public void OnPlayerJoin(Player player) |
27 | | - { |
28 | | - if (Config.wlcAct) |
29 | | - { |
30 | | - string JoinText = Config.JoinMessage.FormatWith(new |
31 | | - { |
32 | | - name = player.Nickname |
33 | | - }); |
34 | | - player.SendBroadcast(JoinText, (ushort)Config.JoinMessageDelay); |
35 | | - } |
36 | | - } |
37 | | - } |
38 | | -} |
| 1 | +using PluginAPI.Core; |
| 2 | +using PluginAPI.Core.Attributes; |
| 3 | +using PluginAPI.Enums; |
| 4 | +using FormatWith; |
| 5 | +using MEC; |
| 6 | + |
| 7 | +namespace SB_WelcomeMessage |
| 8 | +{ |
| 9 | + public class Plugin |
| 10 | + { |
| 11 | + public static Plugin Singleton; |
| 12 | + |
| 13 | + [PluginConfig] public Config Config; |
| 14 | + |
| 15 | + public const string Version = "1.1.0"; |
| 16 | + |
| 17 | + [PluginPriority(LoadPriority.Highest)] |
| 18 | + [PluginEntryPoint("JoinMessage-System", Version, "Shows a Broadcast Message or Hint in the top/bottom of the Screen of the joining player.", "SpaceBuddy")] |
| 19 | + void LoadPlugin() |
| 20 | + { |
| 21 | + Singleton = this; |
| 22 | + PluginAPI.Events.EventManager.RegisterEvents(this); |
| 23 | + } |
| 24 | + |
| 25 | + [PluginEvent(ServerEventType.PlayerJoined)] |
| 26 | + public void OnPlayerJoin(Player player) |
| 27 | + { |
| 28 | + if (!Config.IsEnabled || Config.JoinMessages == null || Config.JoinMessages.Count == 0) |
| 29 | + return; |
| 30 | + |
| 31 | + Timing.CallDelayed(Config.Delay, () => |
| 32 | + { |
| 33 | + // Verify player still exists and is connected |
| 34 | + if (player == null || !player.GameObject) return; |
| 35 | + |
| 36 | + string rawMessage = Config.JoinMessages[UnityEngine.Random.Range(0, Config.JoinMessages.Count)]; |
| 37 | + |
| 38 | + string joinText = rawMessage.FormatWith(new |
| 39 | + { |
| 40 | + name = player.Nickname, |
| 41 | + userId = player.UserId |
| 42 | + }); |
| 43 | + |
| 44 | + if (Config.UseHint) |
| 45 | + { |
| 46 | + player.ReceiveHint(joinText, Config.Duration); |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + player.SendBroadcast(joinText, Config.Duration); |
| 51 | + } |
| 52 | + }); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments