Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rid of redundant calculation and add option to make MOTDUrl just for …
…new players.
  • Loading branch information
N1Ran committed Mar 26, 2019
commit 2263cf2aa2a618165a94dd4f9d316d78ee193068
11 changes: 4 additions & 7 deletions Essentials/AutoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NLog;
using Torch;
using Torch.API;
using Torch.Server.ViewModels;
using Sandbox.Game.World;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.Entities;
Expand All @@ -16,6 +17,8 @@ namespace Essentials
{
public class AutoCommands : IDisposable
{
protected EntityTreeViewModel Tree { get; }

private static AutoCommands _instance;
public static AutoCommands Instance => _instance ?? (_instance = new AutoCommands());
private static readonly Logger Log = LogManager.GetLogger("Essentials");
Expand Down Expand Up @@ -48,13 +51,7 @@ private bool CanRun(AutoCommand command)
case Trigger.Scheduled:
return true;
case Trigger.GridCount:
var gridCount = 0;
foreach (var e in MyEntities.GetEntities())
{
if (e is IMyCubeGrid)
gridCount++;
}
return gridCount >= command.TriggerCount;
return Tree.Grids.Count >= command.TriggerCount;
case Trigger.PlayerCount:
return MySession.Static.Players.GetOnlinePlayerCount() >= command.TriggerCount;
case Trigger.SimSpeed:
Expand Down
5 changes: 5 additions & 0 deletions Essentials/EssentialsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ public EssentialsConfig()
[Display(Name = "MotdURL", Description = "Sets a URL to show to players when they connect. Opens in the steam overlay, if enabled.")]
public string MotdUrl { get => _motdUrl; set => SetValue(ref _motdUrl, value); }

private bool _newUserMotdUrl;
[Display(Name = "Url for New Users Only", Description = "MOTD URL for new users only")]
public bool NewUserMotdUrl{get => _newUserMotdUrl;set => SetValue(ref _newUserMotdUrl, value);}

private bool _stopShips;
[Display(Name = "Stop entities on start", Description = "Stop all entities in the world when the server starts.")]
public bool StopShipsOnStart { get => _stopShips; set => SetValue(ref _stopShips, value); }


private bool _utilityShowPosition;

[Display(Name = "Grid list show position",Description = "Show users the position of all grids they own in the grids list command.")]
Expand Down
11 changes: 10 additions & 1 deletion Essentials/EssentialsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ private void MotdOnce(IPlayer player)
public void SendMotd(MyPlayer player)
{
long playerId = player.Identity.IdentityId;
if (!string.IsNullOrEmpty(Config.MotdUrl))

if (!string.IsNullOrEmpty(Config.MotdUrl) && !Config.NewUserMotdUrl)
{
if (MyGuiSandbox.IsUrlWhitelisted(Config.MotdUrl))
MyVisualScriptLogicProvider.OpenSteamOverlay(Config.MotdUrl, playerId);
Expand All @@ -233,10 +234,18 @@ public void SendMotd(MyPlayer player)
bool newUser = !Config.KnownSteamIds.Contains(id);
if (newUser)
Config.KnownSteamIds.Add(id);
if (!string.IsNullOrEmpty(Config.MotdUrl) && newUser && Config.NewUserMotdUrl)
{
if (MyGuiSandbox.IsUrlWhitelisted(Config.MotdUrl))
MyVisualScriptLogicProvider.OpenSteamOverlay(Config.MotdUrl, playerId);
else
MyVisualScriptLogicProvider.OpenSteamOverlay($"https://steamcommunity.com/linkfilter/?url={Config.MotdUrl}", playerId);
}

if (newUser && !string.IsNullOrEmpty(Config.NewUserMotd))
{
ModCommunication.SendMessageTo(new DialogMessage(MySession.Static.Name, "New User Message Of The Day", Config.NewUserMotd.Replace("%player%", name)), id);

}
else if (!string.IsNullOrEmpty(Config.Motd))
{
Expand Down