Don't repatrol players who were patrolled within last 15 seconds. Fixes #363.

This commit is contained in:
UnknownShadow200 2017-09-21 13:27:03 +10:00
parent 3caa6bde36
commit ff534860ec
4 changed files with 8 additions and 10 deletions

View File

@ -36,12 +36,10 @@ namespace MCGalaxy.Commands.Moderation {
List<Player> candidates = GetPatrolCandidates(p);
if (candidates.Count == 0) {
LevelPermission perm = CommandExtraPerms.MinPerm(name);
Player.Message(p, "No {0}players ranked {1} %Sor below are online.",
p.Rank <= perm ? "other " : "", // in case we can patrol ourselves
Group.GetColoredName(perm));
Player.Message(p, "&cNo players to patrol.");
} else {
Player target = candidates[new Random().Next(candidates.Count)];
target.LastPatrol = DateTime.UtcNow;
Command.all.FindByName("TP").Use(p, target.name);
Player.Message(p, "Now visiting " + target.ColoredName + "%S.");
}
@ -51,9 +49,11 @@ namespace MCGalaxy.Commands.Moderation {
List<Player> candidates = new List<Player>();
LevelPermission perm = CommandExtraPerms.MinPerm(name);
Player[] online = PlayerInfo.Online.Items;
DateTime cutoff = DateTime.UtcNow.AddSeconds(-15);
foreach (Player target in online) {
if (target.Rank > perm || target == p || !Entities.CanSee(p, target)) continue;
if (target.LastPatrol > cutoff) continue;
candidates.Add(target);
}
return candidates;
@ -62,8 +62,8 @@ namespace MCGalaxy.Commands.Moderation {
public override void Help(Player p) {
Player.Message(p, "%T/Patrol");
LevelPermission perm = CommandExtraPerms.MinPerm(name);
Player.Message(p, "%HTeleports you to a random {0} %Sor lower",
Group.GetColoredName(perm));
Player.Message(p, "%HTeleports you to a random {0} %Hor lower", Group.GetColoredName(perm));
Player.Message(p, "%HPlayers patrolled within the last 15 seconds are ignored");
}
}
}

View File

@ -64,7 +64,7 @@ namespace MCGalaxy.Commands.Misc {
public override void Use(Player p, string message) {
if (message.Length > 0) { Help(p); return; }
int code = p.random.Next(int.MinValue, int.MaxValue);
int code = new Random().Next(int.MinValue, int.MaxValue);
p.Leave("Server crash! Error code 0x" + Convert.ToString(code, 16).ToUpper());
}

View File

@ -84,7 +84,6 @@ namespace MCGalaxy {
pl.SendMapMotd();
} else {
LevelActions.ReloadMap(p, pl, false);
if (pl.HasCpeExt(CpeExt.HackControl)) pl.Send(Hacks.MakeHackControl(pl));
}
}
}

View File

@ -230,8 +230,7 @@ namespace MCGalaxy {
public DateTime lastchatroomglobal;
public WarpList Waypoints = new WarpList();
public Random random = new Random();
public DateTime LastPatrol;
public LevelPermission Rank { get { return group.Permission; } }
public bool loggedIn;