Skip to content

Commit a00c1ed

Browse files
add contributor ranks
1 parent 93f4805 commit a00c1ed

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

Code/Plugin/Config.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
namespace SER.Code.Plugin;
1+
using System.ComponentModel;
2+
3+
namespace SER.Code.Plugin;
24

35
public class Config
46
{
57
public bool IsEnabled { get; set; } = true;
68

7-
public bool SerMethodsAsCommands { get; set; } = false;
9+
[Description("If true, SER will add a > prefix to all consoles (like >Print \"Hello\") instead of using the longer command.")]
10+
public bool MethodCommandPrefix { get; set; } = false;
811

9-
public bool SendHelpMessageOnServerInitialization { get; set; } = true;
12+
[Description("If true, SER will send a message to the server console when the plugin is enabled.")]
13+
public bool SendInitMessage { get; set; } = true;
14+
15+
[Description("If true, SER will slow down scripts in order to prevent them from crashing the server.")]
16+
public bool SafeScripts { get; set; } = false;
17+
18+
[Description("If you wish to remove ranks from players mentioned in the credits, message the developer.")]
19+
public int RankRemovalKey { get; set; } = 0;
1020
}

Code/Plugin/MainPlugin.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using JetBrains.Annotations;
2+
using LabApi.Events.Arguments.PlayerEvents;
23
using LabApi.Features;
34
using LabApi.Features.Console;
5+
using LabApi.Features.Wrappers;
46
using MEC;
57
using SER.Code.FlagSystem.Flags;
68
using SER.Code.Helpers;
@@ -30,7 +32,7 @@ public class MainPlugin : LabApi.Loader.Features.Plugins.Plugin<Config>
3032
public static string HelpCommandName => "serhelp";
3133
public static MainPlugin Instance { get; private set; } = null!;
3234

33-
public record struct Contributor(string Name, Contribution Contribution);
35+
public record Contributor(string Name, Contribution Contribution, string? Id = null);
3436

3537
[Flags]
3638
public enum Contribution
@@ -47,7 +49,7 @@ public enum Contribution
4749

4850
public static Contributor[] Contributors =>
4951
[
50-
new(Instance.Author, Contribution.LeadDeveloper),
52+
new(Instance.Author, Contribution.LeadDeveloper, "76561198361176072@steam"),
5153
new("Whitty985playz", Contribution.QualityAssurance | Contribution.EarlyAdopter),
5254
new("Tosoks67", Contribution.Developer | Contribution.Betatester),
5355
new("Krzysiu Wojownik", Contribution.QualityAssurance | Contribution.Developer),
@@ -79,6 +81,11 @@ public override void Enable()
7981
Events.ServerEvents.WaitingForPlayers += OnServerFullyInit;
8082
Events.ServerEvents.RoundRestarted += Disable;
8183

84+
if (Config?.RankRemovalKey is not { } key || Server.IpAddress.GetHashCode() != key)
85+
{
86+
Events.PlayerEvents.Joined += OnJoined;
87+
}
88+
8289
Timing.CallDelayed(1.5f, FileSystem.FileSystem.Initialize);
8390
}
8491

@@ -90,7 +97,7 @@ public override void Disable()
9097

9198
private void OnServerFullyInit()
9299
{
93-
if (Config?.SendHelpMessageOnServerInitialization is false) return;
100+
if (Config?.SendInitMessage is false) return;
94101

95102
Logger.Raw(
96103
$"""
@@ -135,4 +142,24 @@ private static void SendLogo()
135142
ConsoleColor.Cyan
136143
);
137144
}
145+
146+
private static void OnJoined(PlayerJoinedEventArgs ev)
147+
{
148+
if (ev.Player is not { } plr) return;
149+
150+
Timing.CallDelayed(3f, () =>
151+
{
152+
if (plr.UserGroup is not null) return;
153+
if (Contributors.FirstOrDefault(c => c.Id == plr.UserId && c.Id is not null) is not { } info) return;
154+
155+
plr.GroupColor = "aqua";
156+
plr.GroupName = $"* SER {info
157+
.Contribution
158+
.GetFlags()
159+
.OrderByDescending(f => f)
160+
.First()
161+
.ToString()
162+
.Spaceify()} *";
163+
});
164+
}
138165
}

0 commit comments

Comments
 (0)