From a5c9eb45e18e5d12dc45d954c2d6d355073af20d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 21 Jun 2020 13:51:48 +1000 Subject: [PATCH] Obsolete PlayerExtList.Add/AddOrReplace --- MCGalaxy/Commands/CPE/CmdEntityRot.cs | 2 +- MCGalaxy/Commands/CPE/CmdModel.cs | 4 +-- MCGalaxy/Commands/CPE/CmdReachDistance.cs | 2 +- MCGalaxy/Commands/CPE/CmdSkin.cs | 2 +- MCGalaxy/CorePlugin/ModActionHandler.cs | 8 ++--- MCGalaxy/Player/List/PlayerExtList.cs | 38 +++++++++++++---------- MCGalaxy/Player/List/PlayerMetaList.cs | 1 + 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/MCGalaxy/Commands/CPE/CmdEntityRot.cs b/MCGalaxy/Commands/CPE/CmdEntityRot.cs index 337dac73c..0f79f3f33 100644 --- a/MCGalaxy/Commands/CPE/CmdEntityRot.cs +++ b/MCGalaxy/Commands/CPE/CmdEntityRot.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.CPE { protected override void SetPlayerData(Player p, Player who, string args) { if (!ParseArgs(p, args, who)) return; - Server.rotations.AddOrReplace(who.name, who.Rot.RotX + " " + who.Rot.RotZ); + Server.rotations.Update(who.name, who.Rot.RotX + " " + who.Rot.RotZ); Server.rotations.Save(); } diff --git a/MCGalaxy/Commands/CPE/CmdModel.cs b/MCGalaxy/Commands/CPE/CmdModel.cs index 1640abcaf..1dd447ad3 100644 --- a/MCGalaxy/Commands/CPE/CmdModel.cs +++ b/MCGalaxy/Commands/CPE/CmdModel.cs @@ -62,7 +62,7 @@ namespace MCGalaxy.Commands.CPE { } if (!model.CaselessEq("humanoid")) { - Server.models.AddOrReplace(who.name, model); + Server.models.Update(who.name, model); } else { Server.models.Remove(who.name); } @@ -70,7 +70,7 @@ namespace MCGalaxy.Commands.CPE { if (!changedAxisScale) return; if (who.ScaleX != 0 || who.ScaleY != 0 || who.ScaleZ != 0) { - Server.modelScales.AddOrReplace(who.name, who.ScaleX + " " + who.ScaleY + " " + who.ScaleZ); + Server.modelScales.Update(who.name, who.ScaleX + " " + who.ScaleY + " " + who.ScaleZ); } else { Server.modelScales.Remove(who.name); } diff --git a/MCGalaxy/Commands/CPE/CmdReachDistance.cs b/MCGalaxy/Commands/CPE/CmdReachDistance.cs index 0a8af588b..bf36c5d8b 100644 --- a/MCGalaxy/Commands/CPE/CmdReachDistance.cs +++ b/MCGalaxy/Commands/CPE/CmdReachDistance.cs @@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.CPE { p.Send(Packet.ClickDistance((short)packedDist)); p.ReachDistance = dist; p.Message("Set your reach distance to {0} blocks.", dist); - Server.reach.AddOrReplace(p.name, packedDist.ToString()); + Server.reach.Update(p.name, packedDist.ToString()); Server.reach.Save(); } } diff --git a/MCGalaxy/Commands/CPE/CmdSkin.cs b/MCGalaxy/Commands/CPE/CmdSkin.cs index 65a07aa0d..ac360a73e 100644 --- a/MCGalaxy/Commands/CPE/CmdSkin.cs +++ b/MCGalaxy/Commands/CPE/CmdSkin.cs @@ -69,7 +69,7 @@ namespace MCGalaxy.Commands.CPE { if (skin == who.truename) { Server.skins.Remove(who.name); } else { - Server.skins.AddOrReplace(who.name, skin); + Server.skins.Update(who.name, skin); } Server.skins.Save(); } diff --git a/MCGalaxy/CorePlugin/ModActionHandler.cs b/MCGalaxy/CorePlugin/ModActionHandler.cs index 7fc671e52..110018e1c 100644 --- a/MCGalaxy/CorePlugin/ModActionHandler.cs +++ b/MCGalaxy/CorePlugin/ModActionHandler.cs @@ -63,7 +63,7 @@ namespace MCGalaxy.Core { if (who != null) who.frozen = true; LogAction(e, who, "&bfrozen"); - Server.frozen.AddOrReplace(e.Target, FormatModTaskData(e)); + Server.frozen.Update(e.Target, FormatModTaskData(e)); ModerationTasks.FreezeCalcNextRun(); Server.frozen.Save(); } @@ -84,7 +84,7 @@ namespace MCGalaxy.Core { if (who != null) who.muted = true; LogAction(e, who, "&8muted"); - Server.muted.AddOrReplace(e.Target, FormatModTaskData(e)); + Server.muted.Update(e.Target, FormatModTaskData(e)); ModerationTasks.MuteCalcNextRun(); Server.muted.Save(); } @@ -107,7 +107,7 @@ namespace MCGalaxy.Core { if (e.Duration.Ticks != 0) { string banner = e.Actor.truename; DateTime end = DateTime.UtcNow.Add(e.Duration); - Server.tempBans.AddOrReplace(e.Target, Ban.PackTempBanData(e.Reason, banner, end)); + Server.tempBans.Update(e.Target, Ban.PackTempBanData(e.Reason, banner, end)); Server.tempBans.Save(); if (who != null) who.Kick("Banned for " + e.Duration.Shorten(true) + "." + e.ReasonSuffixed); @@ -224,7 +224,7 @@ namespace MCGalaxy.Core { static void AddTempRank(ModAction e, Group newRank) { string data = FormatModTaskData(e) + " " + e.TargetGroup.Name + " " + newRank.Name; - Server.tempRanks.AddOrReplace(e.Target, data); + Server.tempRanks.Update(e.Target, data); ModerationTasks.TemprankCalcNextRun(); Server.tempRanks.Save(); } diff --git a/MCGalaxy/Player/List/PlayerExtList.cs b/MCGalaxy/Player/List/PlayerExtList.cs index b7b42c555..f3693a27f 100644 --- a/MCGalaxy/Player/List/PlayerExtList.cs +++ b/MCGalaxy/Player/List/PlayerExtList.cs @@ -40,14 +40,22 @@ namespace MCGalaxy { lock (locker) return new List(lines); } + /// Returns number of names that are in this list. public int Count { get { lock (locker) return names.Count; } } - public void Add(string name, string data) { + /// Sets the data associated with the given name. + public void Update(string name, string data) { lock (locker) { - names.Add(name); lines.Add(name + Separator + data); + int idx = names.CaselessIndexOf(name); + if (idx == -1) { + names.Add(name); lines.Add(name + Separator + data); + } else { + lines[idx] = name + Separator + data; + } } } + /// Returns whether the given name was removed from this list. public bool Remove(string name) { lock (locker) { int idx = names.CaselessIndexOf(name); @@ -59,22 +67,13 @@ namespace MCGalaxy { } } + /// Returns whether the given name is in this list. public bool Contains(string name) { - lock (locker) - return names.CaselessContains(name); - } - - public void AddOrReplace(string name, string data) { - lock (locker) { - int idx = names.CaselessIndexOf(name); - if (idx == -1) { - names.Add(name); lines.Add(name + Separator + data); - } else { - lines[idx] = name + Separator + data; - } - } + lock (locker) return names.CaselessContains(name); } + /// Retrieves the data associated with the given name. + /// Returns null if there is no data associated. public string FindData(string name) { lock (locker) { int idx = names.CaselessIndexOf(name); @@ -85,6 +84,13 @@ namespace MCGalaxy { return idx == -1 ? null : line.Substring(idx + 1); } } + + + [Obsolete("Use Update instead")] + public void Add(string name, string data) { Update(name, data); } + + [Obsolete("Use Update instead")] + public void AddOrReplace(string name, string data) { Update(name, data); } public void Save() { Save(true); } @@ -118,7 +124,7 @@ namespace MCGalaxy { while ((line = r.ReadLine()) != null) { list.lines.Add(line); int sepIndex = line.IndexOf(separator); - string name = sepIndex >= 0 ? line.Substring(0, sepIndex) : line; + string name = sepIndex >= 0 ? line.Substring(0, sepIndex) : line; list.names.Add(name); } } diff --git a/MCGalaxy/Player/List/PlayerMetaList.cs b/MCGalaxy/Player/List/PlayerMetaList.cs index 6c97d934e..a7713a98c 100644 --- a/MCGalaxy/Player/List/PlayerMetaList.cs +++ b/MCGalaxy/Player/List/PlayerMetaList.cs @@ -22,6 +22,7 @@ using System.IO; namespace MCGalaxy { /// Represents a list of metadata about players. (such as rank info, ban info, notes). + /// Unlike other player lists, this list is NOT kept in memory. public sealed class PlayerMetaList { public readonly string file;