From 952ba94c5bfbdddcdf0f2a0e4894a9ab6c6dec65 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 16 Aug 2020 23:02:54 +1000 Subject: [PATCH] Make the various Line printer methods in OnlineStat/OfflineStat public so plugins can use (and abuse) them --- MCGalaxy/Database/Stats/OfflineStat.cs | 12 ++++++------ MCGalaxy/Database/Stats/OnlineStat.cs | 26 +++++++++++++------------- MCGalaxy/Levels/Level.cs | 26 +++++++++++++++----------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/MCGalaxy/Database/Stats/OfflineStat.cs b/MCGalaxy/Database/Stats/OfflineStat.cs index 4769e8663..739369df3 100644 --- a/MCGalaxy/Database/Stats/OfflineStat.cs +++ b/MCGalaxy/Database/Stats/OfflineStat.cs @@ -22,10 +22,10 @@ namespace MCGalaxy.DB { public delegate void OfflineStatPrinter(Player p, PlayerData who); - /// Prints stats for an offline player in /whois. + /// Prints stats for an offline player in /info. public static class OfflineStat { - /// List of stats that can be output to /whois. + /// List of stats that can be output to /info. public static List Stats = new List() { 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")); } diff --git a/MCGalaxy/Database/Stats/OnlineStat.cs b/MCGalaxy/Database/Stats/OnlineStat.cs index 4aac1f4fb..003ed50e7 100644 --- a/MCGalaxy/Database/Stats/OnlineStat.cs +++ b/MCGalaxy/Database/Stats/OnlineStat.cs @@ -24,10 +24,10 @@ namespace MCGalaxy.DB { public delegate void OnlineStatPrinter(Player p, Player who); - /// Prints stats for an online player in /whois. + /// Prints stats for an online player in /info. public static class OnlineStat { - /// List of stats that can be output to /whois. + /// List of stats that can be output to /info. public static List Stats = new List() { 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")); diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index acc4ea173..129701931 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -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 players { get { return getPlayers(); } } @@ -132,8 +136,8 @@ namespace MCGalaxy { /// Attempts to automatically unload this map. 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) {