Make the various Line printer methods in OnlineStat/OfflineStat public so plugins can use (and abuse) them

This commit is contained in:
UnknownShadow200 2020-08-16 23:02:54 +10:00
parent 687dd02aa0
commit 952ba94c5b
3 changed files with 34 additions and 30 deletions

View File

@ -22,10 +22,10 @@ namespace MCGalaxy.DB {
public delegate void OfflineStatPrinter(Player p, PlayerData who);
/// <summary> Prints stats for an offline player in /whois. </summary>
/// <summary> Prints stats for an offline player in /info. </summary>
public static class OfflineStat {
/// <summary> List of stats that can be output to /whois. </summary>
/// <summary> List of stats that can be output to /info. </summary>
public static List<OfflineStatPrinter> Stats = new List<OfflineStatPrinter>() {
OfflineCoreLine,
(p, who) => OnlineStat.MiscLine(p, who.Name, who.Deaths, who.Money),
@ -39,7 +39,7 @@ namespace MCGalaxy.DB {
(p, who) => OnlineStat.IPLine(p, who.Name, who.IP),
};
static void OfflineCoreLine(Player p, PlayerData data) {
public static void OfflineCoreLine(Player p, PlayerData data) {
Group group = Group.GroupIn(data.Name);
string color = data.Color.Length == 0 ? group.Color : data.Color;
string prefix = data.Title.Length == 0 ? "" : color + "[" + data.TitleColor + data.Title + color + "] ";
@ -47,15 +47,15 @@ namespace MCGalaxy.DB {
OnlineStat.CoreLine(p, fullName, data.Name, group, data.Messages);
}
static void BlocksModifiedLine(Player p, PlayerData who) {
public static void BlocksModifiedLine(Player p, PlayerData who) {
p.Message(" Modified &a{0} %Sblocks", who.TotalModified);
}
static void TimeSpentLine(Player p, PlayerData who) {
public static void TimeSpentLine(Player p, PlayerData who) {
p.Message(" Spent &a{0} %Son the server", who.TotalTime.Shorten());
}
static void LoginLine(Player p, PlayerData who) {
public static void LoginLine(Player p, PlayerData who) {
p.Message(" First login &a{0}%S, last login &a{1}",
who.FirstLogin.ToString("yyyy-MM-dd"), who.LastLogin.ToString("yyyy-MM-dd"));
}

View File

@ -24,10 +24,10 @@ namespace MCGalaxy.DB {
public delegate void OnlineStatPrinter(Player p, Player who);
/// <summary> Prints stats for an online player in /whois. </summary>
/// <summary> Prints stats for an online player in /info. </summary>
public static class OnlineStat {
/// <summary> List of stats that can be output to /whois. </summary>
/// <summary> List of stats that can be output to /info. </summary>
public static List<OnlineStatPrinter> Stats = new List<OnlineStatPrinter>() {
OnlineCoreLine,
(p, who) => MiscLine(p, who.name, who.TimesDied, who.money),
@ -43,7 +43,7 @@ namespace MCGalaxy.DB {
EntityLine,
};
static void OnlineCoreLine(Player p, Player who) {
public static void OnlineCoreLine(Player p, Player who) {
string prefix = who.title.Length == 0 ? "" : who.MakeTitle(who.title, who.titlecolor);
string fullName = prefix + who.ColoredName;
CoreLine(p, fullName, who.name, who.group, who.TotalMessagesSent);
@ -64,31 +64,31 @@ namespace MCGalaxy.DB {
}
}
static void BlocksModifiedLine(Player p, Player who) {
public static void BlocksModifiedLine(Player p, Player who) {
p.Message(" Modified &a{0} %Sblocks, &a{1} %Ssince login", who.TotalModified, who.SessionModified);
}
internal static void BlockStatsLine(Player p, long placed, long deleted, long drawn) {
public static void BlockStatsLine(Player p, long placed, long deleted, long drawn) {
p.Message(" &a{0} %Splaced, &a{1} %Sdeleted, &a{2} %Sdrawn",
placed, deleted, drawn);
}
static void TimeSpentLine(Player p, Player who) {
public static void TimeSpentLine(Player p, Player who) {
TimeSpan timeOnline = DateTime.UtcNow - who.SessionStartTime;
p.Message(" Spent &a{0} %Son the server, &a{1} %Sthis session",
who.TotalTime.Shorten(), timeOnline.Shorten());
}
static void LoginLine(Player p, Player who) {
public static void LoginLine(Player p, Player who) {
p.Message(" First login &a{0}%S, and is currently &aonline",
who.FirstLogin.ToString("yyyy-MM-dd"));
}
internal static void LoginsLine(Player p, int logins, int kicks) {
public static void LoginsLine(Player p, int logins, int kicks) {
p.Message(" Logged in &a{0} %Stimes, &c{1} %Sof which ended in a kick", logins, kicks);
}
internal static void BanLine(Player p, string name) {
public static void BanLine(Player p, string name) {
if (!Group.BannedRank.Players.Contains(name)) return;
string banner, reason, prevRank;
DateTime time;
@ -102,7 +102,7 @@ namespace MCGalaxy.DB {
}
}
internal static void SpecialGroupLine(Player p, string name) {
public static void SpecialGroupLine(Player p, string name) {
if (Server.Devs.CaselessContains(name.RemoveLastPlus()))
p.Message(" Player is an &9{0} Developer", Server.SoftwareName);
if (Server.Mods.CaselessContains(name.RemoveLastPlus()))
@ -111,7 +111,7 @@ namespace MCGalaxy.DB {
p.Message(" Player is the &cServer owner");
}
internal static void IPLine(Player p, string name, string ip) {
public static void IPLine(Player p, string name, string ip) {
ItemPerms seeIpPerms = CommandExtraPerms.Find("WhoIs", 1);
if (!seeIpPerms.UsableBy(p.Rank)) return;
@ -123,7 +123,7 @@ namespace MCGalaxy.DB {
p.Message(" Player is &fWhitelisted");
}
static void IdleLine(Player p, Player who) {
public static void IdleLine(Player p, Player who) {
TimeSpan idleTime = DateTime.UtcNow - who.LastAction;
if (who.afkMessage != null) {
p.Message(" Idle for {0} (AFK {1}%S)", idleTime.Shorten(), who.afkMessage);
@ -132,7 +132,7 @@ namespace MCGalaxy.DB {
}
}
static void EntityLine(Player p, Player who) {
public static void EntityLine(Player p, Player who) {
bool hasSkin = !who.SkinName.CaselessEq(who.truename);
bool hasModel = !(who.Model.CaselessEq("humanoid") || who.Model.CaselessEq("human"));

View File

@ -44,6 +44,10 @@ namespace MCGalaxy {
public sealed partial class Level : IDisposable {
public Level(string name, ushort width, ushort height, ushort length) {
Init(name, width, height, length);
}
void Init(string name, ushort width, ushort height, ushort length) {
if (width < 1) width = 1;
if (height < 1) height = 1;
if (length < 1) length = 1;
@ -62,21 +66,21 @@ namespace MCGalaxy {
this.name = name; MapName = name.ToLower();
BlockDB = new BlockDB(this);
blocks = new byte[Width * Height * Length];
ChunksX = Utils.CeilDiv16(Width);
ChunksY = Utils.CeilDiv16(Height);
ChunksZ = Utils.CeilDiv16(Length);
blocks = new byte[width * height * length];
ChunksX = Utils.CeilDiv16(width);
ChunksY = Utils.CeilDiv16(height);
ChunksZ = Utils.CeilDiv16(length);
CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][];
spawnx = (ushort)(Width / 2);
spawny = (ushort)(Height * 0.75f);
spawnz = (ushort)(Length / 2);
spawnx = (ushort)(width / 2);
spawny = (ushort)(height * 0.75f);
spawnz = (ushort)(length / 2);
rotx = 0; roty = 0;
VisitAccess = new LevelAccessController(Config, name, true);
BuildAccess = new LevelAccessController(Config, name, false);
listCheckExists = new SparseBitSet(Width, Height, Length);
listUpdateExists = new SparseBitSet(Width, Height, Length);
listCheckExists = new SparseBitSet(width, height, length);
listUpdateExists = new SparseBitSet(width, height, length);
}
public List<Player> players { get { return getPlayers(); } }
@ -132,8 +136,8 @@ namespace MCGalaxy {
/// <summary> Attempts to automatically unload this map. </summary>
public bool AutoUnload() {
bool can = IsMuseum || (Server.Config.AutoLoadMaps && Config.AutoUnload && !HasPlayers());
return can && Unload(true);
bool can = IsMuseum || (Server.Config.AutoLoadMaps && Config.AutoUnload && !HasPlayers());
return can && Unload(true);
}
public bool Unload(bool silent = false, bool save = true) {