Obsolete PlayerList.AddUnique

This commit is contained in:
UnknownShadow200 2020-06-21 13:30:19 +10:00
parent aac7b7c99b
commit fb4745e8fc
10 changed files with 36 additions and 37 deletions

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Chatting {
p.parseEmotes = !p.parseEmotes; p.parseEmotes = !p.parseEmotes;
bool addToList = p.parseEmotes != Server.Config.ParseEmotes; bool addToList = p.parseEmotes != Server.Config.ParseEmotes;
if (!addToList) Server.noEmotes.Remove(p.name); if (!addToList) Server.noEmotes.Remove(p.name);
else Server.noEmotes.AddUnique(p.name); else Server.noEmotes.Add(p.name);
Server.noEmotes.Save(); Server.noEmotes.Save();
p.Message("Emote parsing is {0}.", p.parseEmotes ? "enabled" : "disabled"); p.Message("Emote parsing is {0}.", p.parseEmotes ? "enabled" : "disabled");
} }

View File

@ -59,7 +59,7 @@ namespace MCGalaxy.Commands.Info {
if (!Server.Config.AgreeToRulesOnEntry) { p.Message("agree-to-rules-on-entry is not enabled."); return; } if (!Server.Config.AgreeToRulesOnEntry) { p.Message("agree-to-rules-on-entry is not enabled."); return; }
if (!p.hasreadrules) { p.Message("&9You must read %T/Rules &9before agreeing."); return; } if (!p.hasreadrules) { p.Message("&9You must read %T/Rules &9before agreeing."); return; }
if (!Server.agreed.AddUnique(p.name)) { if (!Server.agreed.Add(p.name)) {
p.Message("You have already agreed to the rules."); p.Message("You have already agreed to the rules.");
} else { } else {
p.agreed = true; p.agreed = true;

View File

@ -61,7 +61,7 @@ namespace MCGalaxy.Commands.Moderation {
} }
if (!p.opchat) opchat.Use(p, "", data); if (!p.opchat) opchat.Use(p, "", data);
Server.hidden.AddUnique(p.name); Server.hidden.Add(p.name);
} else { } else {
AnnounceOps(p, "To Ops -λNICK%S- is now &fvisible"); AnnounceOps(p, "To Ops -λNICK%S- is now &fvisible");
p.hideRank = LevelPermission.Banned; p.hideRank = LevelPermission.Banned;

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.Moderation {
case "add": case "add":
if (parts.Length < 2) { p.Message("You need to provide a name to add."); return; } if (parts.Length < 2) { p.Message("You need to provide a name to add."); return; }
if (!Server.ircControllers.AddUnique(parts[1])) { if (!Server.ircControllers.Add(parts[1])) {
p.Message(parts[1] + " is already an IRC controller."); p.Message(parts[1] + " is already an IRC controller.");
} else { } else {
Server.ircControllers.Save(); Server.ircControllers.Save();

View File

@ -48,7 +48,7 @@ namespace MCGalaxy.Commands.Moderation {
name = PlayerInfo.FindMatchesPreferOnline(p, name); name = PlayerInfo.FindMatchesPreferOnline(p, name);
if (name == null) return; if (name == null) return;
if (!Server.vip.AddUnique(name)) { if (!Server.vip.Add(name)) {
p.Message(PlayerInfo.GetColoredName(p, name) + " %Sis already a VIP."); p.Message(PlayerInfo.GetColoredName(p, name) + " %Sis already a VIP.");
} else { } else {
Server.vip.Save(); Server.vip.Save();

View File

@ -47,7 +47,7 @@ namespace MCGalaxy.Commands.Moderation {
} }
static void Add(Player p, string player) { static void Add(Player p, string player) {
if (!Server.whiteList.AddUnique(player)) { if (!Server.whiteList.Add(player)) {
p.Message(player + " %Sis already on the whitelist!"); return; p.Message(player + " %Sis already on the whitelist!"); return;
} else { } else {
Chat.MessageFromOps(p, "λNICK %Sadded &f" + player + " %Sto the whitelist."); Chat.MessageFromOps(p, "λNICK %Sadded &f" + player + " %Sto the whitelist.");

View File

@ -36,15 +36,12 @@ namespace MCGalaxy.Commands.World {
map = Matcher.FindMaps(p, map); map = Matcher.FindMaps(p, map);
if (map == null) return; if (map == null) return;
bool unlocking = Server.lockdown.Contains(map); if (Server.lockdown.Remove(map)) {
string action = unlocking ? "unlocked" : "locked"; Chat.MessageGlobal("Map " + map + " was unlocked");
Chat.MessageGlobal("Map " + map + " was " + action);
if (unlocking) {
Server.lockdown.Remove(map);
Chat.MessageFromOps(p, "Map " + map + " unlocked by: λNICK"); Chat.MessageFromOps(p, "Map " + map + " unlocked by: λNICK");
} else { } else {
Server.lockdown.AddUnique(map); Server.lockdown.Add(map);
Chat.MessageGlobal("Map " + map + " was locked");
Chat.MessageFromOps(p, "Map " + map + " locked by: λNICK"); Chat.MessageFromOps(p, "Map " + map + " locked by: λNICK");
} }
Server.lockdown.Save(); Server.lockdown.Save();

View File

@ -56,7 +56,7 @@ namespace MCGalaxy.DB {
/// <summary> Returns a non-database ID for the given name </summary> /// <summary> Returns a non-database ID for the given name </summary>
public static int InvalidNameID(string name) { public static int InvalidNameID(string name) {
bool added = Server.invalidIds.AddUnique(name); bool added = Server.invalidIds.Add(name);
if (added) Server.invalidIds.Save(); if (added) Server.invalidIds.Save();
int index = Server.invalidIds.IndexOf(name); int index = Server.invalidIds.IndexOf(name);

View File

@ -23,7 +23,7 @@ using System.Text;
namespace MCGalaxy { namespace MCGalaxy {
/// <summary> Represents a list of player names and simple associated data. Case insensitive. Thread safe. </summary> /// <summary> Represents a list of player names and simple associated data. Case insensitive. Thread safe. </summary>
public sealed class PlayerExtList { public class PlayerExtList {
public char Separator = ' '; public char Separator = ' ';
public string Path; public string Path;

View File

@ -23,7 +23,7 @@ using System.Text;
namespace MCGalaxy { namespace MCGalaxy {
/// <summary> Represents a list of player names. Case insensitive. Thread safe. </summary> /// <summary> Represents a list of player names. Case insensitive. Thread safe. </summary>
public sealed class PlayerList { public class PlayerList {
public string Path; public string Path;
List<string> names = new List<string>(); List<string> names = new List<string>();
@ -37,27 +37,11 @@ namespace MCGalaxy {
lock (locker) return new List<string>(names); lock (locker) return new List<string>(names);
} }
/// <summary> Returns number of names that are in this list. </summary>
public int Count { get { lock (locker) return names.Count; } } public int Count { get { lock (locker) return names.Count; } }
public void Add(string name) { /// <summary> Returns whether the given name was actually added to this list. </summary>
lock (locker) names.Add(name); public bool Add(string name) {
}
public bool Remove(string name) {
lock (locker) return names.CaselessRemove(name);
}
/// <summary> Returns whether the given name is caselessly in this list. </summary>
public bool Contains(string name) {
lock (locker) return names.CaselessContains(name);
}
/// <summary> Removes all names from this list. </summary>
public void Clear() {
lock (locker) names.Clear();
}
public bool AddUnique(string name) {
lock (locker) { lock (locker) {
int idx = names.CaselessIndexOf(name); int idx = names.CaselessIndexOf(name);
if (idx >= 0) return false; if (idx >= 0) return false;
@ -67,7 +51,25 @@ namespace MCGalaxy {
return true; return true;
} }
// only used for NameConverter /// <summary> Returns whether the given name was removed from this list. </summary>
public bool Remove(string name) {
lock (locker) return names.CaselessRemove(name);
}
/// <summary> Returns whether the given name is in this list. </summary>
public bool Contains(string name) {
lock (locker) return names.CaselessContains(name);
}
/// <summary> Removes all names from this list. </summary>
public void Clear() {
lock (locker) names.Clear();
}
[Obsolete("Use Add instead")]
public bool AddUnique(string name) { return Add(name); }
internal int IndexOf(string name) { internal int IndexOf(string name) {
lock (locker) return names.CaselessIndexOf(name); lock (locker) return names.CaselessIndexOf(name);
} }