diff --git a/GUI/PropertyWindow.cs b/GUI/PropertyWindow.cs
index 224fe3003..9a20f33af 100644
--- a/GUI/PropertyWindow.cs
+++ b/GUI/PropertyWindow.cs
@@ -785,7 +785,7 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
Command cmd = Command.all.Find(listCommandsExtraCmdPerms.SelectedItem.ToString());
oldcmd = cmd;
skipExtraPermChanges = true;
- extracmdpermnumber.Maximum = CommandExtraPerms.GetMaxNumber(cmd);
+ extracmdpermnumber.Maximum = MaxExtraPermissionNumber(cmd);
extracmdpermnumber.ReadOnly = extracmdpermnumber.Maximum == 1;
extracmdpermnumber.Value = 1;
skipExtraPermChanges = false;
@@ -793,6 +793,16 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
ExtraPermSetDescriptions(cmd, 1);
oldnumber = (int)extracmdpermnumber.Value;
}
+
+ private int MaxExtraPermissionNumber(Command cmd) {
+ var all = CommandExtraPerms.FindAll(cmd.name);
+ int maxNum = 0;
+
+ foreach (CommandExtraPerms.ExtraPerms perms in all) {
+ maxNum = Math.Max(maxNum, perms.Number);
+ }
+ return maxNum;
+ }
private void SaveOldExtraCustomCmdChanges() {
if (oldcmd == null || skipExtraPermChanges) return;
diff --git a/MCGalaxy/Commands/Permissions/CommandExtraPerms.cs b/MCGalaxy/Commands/Permissions/CommandExtraPerms.cs
index dda6e0858..3a60eb70d 100644
--- a/MCGalaxy/Commands/Permissions/CommandExtraPerms.cs
+++ b/MCGalaxy/Commands/Permissions/CommandExtraPerms.cs
@@ -63,6 +63,16 @@ namespace MCGalaxy {
/// Returns the lowest rank that has the nth extra permission for a given command.
public static LevelPermission MinPerm(string cmd, int num = 1) { return Find(cmd, num).MinRank; }
+ /// Finds all extra permissions for a given command.
+ /// list is empty when no extra permissions are found, not null.
+ public static List FindAll(string cmd) {
+ List allPerms = new List();
+ foreach (ExtraPerms perms in list) {
+ if (perms.Command.CaselessEq(cmd)) allPerms.Add(perms);
+ }
+ return allPerms;
+ }
+
/// Sets the nth extra permission for a given command.
public static void Set(string cmd, LevelPermission perm, string desc, int num = 1) {
@@ -80,20 +90,13 @@ namespace MCGalaxy {
perms.Description = desc;
perms.Number = num;
}
-
- /// Returns the highest number/identifier of an extra permission for the given command.
- public static int GetMaxNumber(Command cmd) {
- for (int i = 1; ; i++) {
- if (Find(cmd.name, i) == null) return (i - 1);
- }
- }
- static readonly object saveLock = new object();
+ static readonly object ioLock = new object();
/// Saves the list of all extra permissions.
public static void Save() {
- lock (saveLock) {
+ lock (ioLock) {
try {
SaveCore();
} catch (Exception ex) {
@@ -115,15 +118,21 @@ namespace MCGalaxy {
w.WriteLine("#");
foreach (ExtraPerms perms in list) {
- w.WriteLine(perms.Command + ":" + perms.Number + ":" + (int)perms.MinRank + ":" + perms.Description);
+ w.WriteLine(perms.Command + ":" + perms.Number + ":" + (int)perms.MinRank + ":" + perms.Description);
}
}
}
/// Loads the list of all extra permissions.
public static void Load() {
- if (!File.Exists(file)) Save();
-
+ lock (ioLock) {
+ if (!File.Exists(file)) Save();
+
+ LoadCore();
+ }
+ }
+
+ static void LoadCore() {
using (StreamReader r = new StreamReader(file)) {
string line;
while ((line = r.ReadLine()) != null) {
diff --git a/MCGalaxy/util/Formatting/Formatter.cs b/MCGalaxy/util/Formatting/Formatter.cs
index 4a9f32b1c..bfa13066d 100644
--- a/MCGalaxy/util/Formatting/Formatter.cs
+++ b/MCGalaxy/util/Formatting/Formatter.cs
@@ -52,14 +52,13 @@ namespace MCGalaxy {
Player.Message(p, builder.ToString());
PrintAliases(p, cmd);
- CommandPerm[] addPerms = cmd.ExtraPerms;
- if (addPerms == null) return;
+ List extraPerms = CommandExtraPerms.FindAll(cmd.name);
+ if (extraPerms.Count == 0) return;
Player.Message(p, "%TExtra permissions:");
- for (int i = 0; i < addPerms.Length; i++) {
- CommandExtraPerms.ExtraPerms extra = CommandExtraPerms.Find(cmd.name, i + 1);
- Player.Message(p, "{0}) {1}%S{2}", i + 1,
- Group.GetColoredName(extra.MinRank), extra.Description);
+ foreach (CommandExtraPerms.ExtraPerms extra in extraPerms) {
+ Player.Message(p, "{0}) {1}%S{2}", extra.Number,
+ Group.GetColoredName(extra.MinRank), extra.Description);
}
}