/// <summary> /// Register this event /// </summary> /// <param name="method">This is the delegate that will get called when this event occurs</param> /// <param name="priority">The priority (imporantce) of this call</param> /// <param name="plugin">The plugin object that is registering the event</param> /// <param name="bypass">Register more than one of the same event</param> public static void Register(Group.GroupSave method, Priority priority, Plugin plugin, bool bypass = false) { if (Find(plugin) != null) if (!bypass) throw new Exception("The user tried to register 2 of the same event!"); events.Add(new OnGroupSaveEvent(method, priority, plugin)); Organize(); }
public static void Call(Group g) { events.ForEach(delegate(OnGroupLoadedEvent p1) { try { p1.method(g); } catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); } }); }
public static void Call(Player p, Group newrank) { events.ForEach(delegate(OnPlayerRankSetEvent p1) { try { p1.method(p, newrank); } catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); } }); }
public static PlayerList Load(string path, Group groupName) { if (!Directory.Exists("ranks")) { Directory.CreateDirectory("ranks"); } path = "ranks/" + path; PlayerList list = new PlayerList(); list.group = groupName; if (File.Exists(path)) { foreach (string line in File.ReadAllLines(path)) { list.Add(line); } } else { File.Create(path).Close(); Server.s.Log("CREATED NEW: " + path); } return list; }
//Move along...nothing to see here... internal static void because(Player p, Group newrank) { if (OnPlayerRankSet != null) { OnPlayerRankSet(p, newrank); } OnPlayerRankSetEvent.Call(p, newrank); }
/// <summary> /// Load up all server groups /// </summary> public static void InitAll() { GroupList = new List<Group>(); if (File.Exists("properties/ranks.properties")) { string[] lines = File.ReadAllLines("properties/ranks.properties"); Group thisGroup = new Group(); int gots = 0, version = 1; if (lines.Length > 0 && lines[0].StartsWith("#Version ")) { try { version = int.Parse(lines[0].Remove(0, 9)); } catch { Server.s.Log("The ranks.properties version header is invalid! Ranks may fail to load!"); } } foreach (string s in lines) { try { if (s == "" || s[0] == '#') continue; if (s.Split('=').Length == 2) { string property = s.Split('=')[0].Trim(); string value = s.Split('=')[1].Trim(); if (thisGroup.name == "" && property.ToLower() != "rankname") { Server.s.Log("Hitting an error at " + s + " of ranks.properties"); } else { switch (property.ToLower()) { case "rankname": gots = 0; thisGroup = new Group(); if (value.ToLower() == "adv" || value.ToLower() == "op" || value.ToLower() == "super" || value.ToLower() == "nobody" || value.ToLower() == "noone") Server.s.Log("Cannot have a rank named \"" + value.ToLower() + "\", this rank is hard-coded."); else if (GroupList.Find(grp => grp.name == value.ToLower()) == null) thisGroup.trueName = value; else Server.s.Log("Cannot add the rank " + value + " twice"); break; case "permission": int foundPermission; try { foundPermission = int.Parse(value); } catch { Server.s.Log("Invalid permission on " + s); break; } if (thisGroup.Permission != LevelPermission.Null) { Server.s.Log("Setting permission again on " + s); gots--; } bool allowed = GroupList.Find(grp => grp.Permission == (LevelPermission)foundPermission) == null; if (foundPermission > 119 || foundPermission < -50) { Server.s.Log("Permission must be between -50 and 119 for ranks"); break; } if (allowed) { gots++; thisGroup.Permission = (LevelPermission)foundPermission; } else { Server.s.Log("Cannot have 2 ranks set at permission level " + value); } break; case "limit": int foundLimit; try { foundLimit = int.Parse(value); } catch { Server.s.Log("Invalid limit on " + s); break; } gots++; thisGroup.maxBlocks = foundLimit; break; case "maxundo": int foundMax; try { foundMax = int.Parse(value); } catch { Server.s.Log("Invalid maximum on " + s); break; } gots++; thisGroup.maxUndo = foundMax; break; case "color": char foundChar; try { foundChar = char.Parse(value); } catch { Server.s.Log("Incorrect color on " + s); break; } if ((foundChar >= '0' && foundChar <= '9') || (foundChar >= 'a' && foundChar <= 'f')) { gots++; thisGroup.color = foundChar.ToString(CultureInfo.InvariantCulture); } else { Server.s.Log("Invalid color code at " + s); } break; case "filename": if (value.Contains("\\") || value.Contains("/")) { Server.s.Log("Invalid filename on " + s); break; } gots++; thisGroup.fileName = value; break; case "motd": if (!String.IsNullOrEmpty(value)) thisGroup.MOTD = value; gots++; break; case "osmaps": byte osmaps; if(byte.TryParse(value, out osmaps) == false) { osmaps = 2; } gots++; thisGroup.OverseerMaps = osmaps; break; } if ((gots >= 4 && version < 2) || (gots >= 5 && version < 3) || gots >= 6) { if (version < 2) { if ((int)thisGroup.Permission >= 100) thisGroup.maxUndo = int.MaxValue; else if ((int)thisGroup.Permission >= 80) thisGroup.maxUndo = 5400; } GroupList.Add(new Group(thisGroup.Permission, thisGroup.maxBlocks, thisGroup.maxUndo, thisGroup.trueName, thisGroup.color[0], thisGroup.MOTD, thisGroup.fileName, thisGroup.OverseerMaps)); } } } else { Server.s.Log("In ranks.properties, the line " + s + " is wrongly formatted"); } } catch (Exception e) { Server.s.Log("Encountered an error at line \"" + s + "\" in ranks.properties"); Server.ErrorLog(e); } } } if (GroupList.Find(grp => grp.Permission == LevelPermission.Banned) == null) GroupList.Add(new Group(LevelPermission.Banned, 1, 1, "Banned", '8', String.Empty, "banned.txt")); if (GroupList.Find(grp => grp.Permission == LevelPermission.Guest) == null) GroupList.Add(new Group(LevelPermission.Guest, 1, 120, "Guest", '7', String.Empty, "guest.txt")); if (GroupList.Find(grp => grp.Permission == LevelPermission.Builder) == null) GroupList.Add(new Group(LevelPermission.Builder, 400, 300, "Builder", '2', String.Empty, "builders.txt")); if (GroupList.Find(grp => grp.Permission == LevelPermission.AdvBuilder) == null) GroupList.Add(new Group(LevelPermission.AdvBuilder, 1200, 900, "AdvBuilder", '3', String.Empty, "advbuilders.txt")); if (GroupList.Find(grp => grp.Permission == LevelPermission.Operator) == null) GroupList.Add(new Group(LevelPermission.Operator, 2500, 5400, "Operator", 'c', String.Empty, "operators.txt")); if (GroupList.Find(grp => grp.Permission == LevelPermission.Admin) == null) GroupList.Add(new Group(LevelPermission.Admin, 65536, int.MaxValue, "SuperOP", 'e', String.Empty, "uberOps.txt")); GroupList.Add(new Group(LevelPermission.Nobody, 65536, -1, "Nobody", '0', String.Empty, "nobody.txt")); bool swap = true; Group storedGroup; while (swap) { swap = false; for (int i = 0; i < GroupList.Count - 1; i++) if (GroupList[i].Permission > GroupList[i + 1].Permission) { swap = true; storedGroup = GroupList[i]; GroupList[i] = GroupList[i + 1]; GroupList[i + 1] = storedGroup; } } if (Group.Find(Server.defaultRank) != null) standard = Group.Find(Server.defaultRank); else standard = Group.findPerm(LevelPermission.Guest); foreach (Player pl in Player.players) { pl.group = GroupList.Find(g => g.name == pl.group.name); } if (OnGroupLoad != null) OnGroupLoad(); OnGroupLoadEvent.Call(); saveGroups(GroupList); }
internal OnGroupSaveEvent(Group.GroupSave method, Priority priority, Plugin plugin) { this.plugin = plugin; this.priority = priority; this.method = method; }
public static void MessageNeedMinPerm(Player p, string action, LevelPermission perm) { p.Message("Only {0}%S{1}", Group.GetColoredName(perm), action); }
internal OnPlayerRankSetEvent(Group.RankSet method, Priority priority, Plugin plugin) { this.plugin = plugin; this.priority = priority; this.method = method; }