Skip to content

Commit

Permalink
Add JoinLink option
Browse files Browse the repository at this point in the history
  • Loading branch information
RestoreMonarchy committed Nov 29, 2024
1 parent 918ab2a commit 5cabc33
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ Message announcer, text and web commands with rich text options and icons.
<WebCommand>
<Name>website</Name>
<Url>https://restoremonarchy.com</Url>
<Description>Restore Monarchy Website</Description>
<Description>Platform for Unturned server owners, players and developers.</Description>
</WebCommand>
</WebsiteCommands>
<EnableWelcomeMessage>true</EnableWelcomeMessage>
<WelcomeMessage Text="{size=18}Welcome to the server!{/size}{br}Rules: {color=#e74c3c}Be respectful{/color} • {color=#2ecc71}No cheating{/color} • {color=#f1c40f}Have fun!{/color}{br}{color=#3498db}Type /commands for commands{/color}" IconUrl="https://i.imgur.com/tLPIfuf.png" Color="white" />
<EnableJoinLink>false</EnableJoinLink>
<JoinLinkUrl>https://restoremonarchy.com</JoinLinkUrl>
<JoinLinkMessage>Platform for Unturned server owners, players and developers.</JoinLinkMessage>
</RichMessageAnnouncerConfiguration>
```

Expand Down
2 changes: 1 addition & 1 deletion RichMessageAnnouncer/RichMessageAnnouncer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>RestoreMonarchy.RichMessageAnnouncer</RootNamespace>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion RichMessageAnnouncer/RichMessageAnnouncerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class RichMessageAnnouncerConfiguration : IRocketPluginConfiguration
public List<WebsiteCommand> WebsiteCommands { get; set; }
public bool EnableWelcomeMessage { get; set; }
public Message WelcomeMessage { get; set; }
public bool EnableJoinLink { get; set; } = false;
public string JoinLinkUrl { get; set; } = "https://restoremonarchy.com";
public string JoinLinkMessage { get; set; } = "Platform for Unturned server owners, players and developers.";

public void LoadDefaults()
{
Expand All @@ -37,10 +40,13 @@ public void LoadDefaults()
];
WebsiteCommands =
[
new("website", null, "https://restoremonarchy.com", "Restore Monarchy Website")
new("website", null, "https://restoremonarchy.com", "Platform for Unturned server owners, players and developers.")
];
EnableWelcomeMessage = true;
WelcomeMessage = new Message("{size=18}Welcome to the server!{/size}{br}Rules: {color=#e74c3c}Be respectful{/color} • {color=#2ecc71}No cheating{/color} • {color=#f1c40f}Have fun!{/color}{br}{color=#3498db}Type /commands for commands{/color}", "https://i.imgur.com/tLPIfuf.png", "white");
EnableJoinLink = false;
JoinLinkUrl = "https://restoremonarchy.com";
JoinLinkMessage = "Platform for Unturned server owners, players and developers.";
}
}
}
34 changes: 20 additions & 14 deletions RichMessageAnnouncer/RichMessageAnnouncerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,31 @@ private void SendMessage(object sender, ElapsedEventArgs e)

private void OnPlayerConnected(UnturnedPlayer player)
{
if (!Configuration.Instance.EnableWelcomeMessage)
if (Configuration.Instance.EnableWelcomeMessage)
{
return;
}

Message msg = Configuration.Instance.WelcomeMessage;
Message msg = Configuration.Instance.WelcomeMessage;

Color color;
if (!string.IsNullOrEmpty(msg.Color))
{
color = UnturnedChat.GetColorFromName(msg.Color, MessageColor);
Color color;
if (!string.IsNullOrEmpty(msg.Color))
{
color = UnturnedChat.GetColorFromName(msg.Color, MessageColor);
}
else
{
color = MessageColor;
}
string iconUrl = msg.IconUrl ?? Configuration.Instance.MessageIconUrl;
string text = msg.Text.Replace('{', '<').Replace('}', '>');
ChatManager.serverSendMessage(text, color, null, player.SteamPlayer(), EChatMode.SAY, iconUrl, true);
}
else

if (Configuration.Instance.EnableJoinLink)
{
color = MessageColor;
string url = Configuration.Instance.JoinLinkUrl;
string message = Configuration.Instance.JoinLinkMessage;

player.Player.sendBrowserRequest(message, url);
}
string iconUrl = msg.IconUrl ?? Configuration.Instance.MessageIconUrl;
string text = msg.Text.Replace('{', '<').Replace('}', '>');
ChatManager.serverSendMessage(text, color, null, player.SteamPlayer(), EChatMode.SAY, iconUrl, true);
}

internal void SendMessageToPlayer(IRocketPlayer player, string translationKey, object[] placeholder = null, string iconUrl = null, string color = null)
Expand Down

0 comments on commit 5cabc33

Please sign in to comment.