mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Make /rankinfo match against all player names (instead of names of players who have been ranked).
Also reduces size of dll by 2 KB
This commit is contained in:
parent
57ab1949b7
commit
ff51000c08
@ -27,15 +27,21 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||||
public override bool UseableWhenFrozen { get { return true; } }
|
public override bool UseableWhenFrozen { get { return true; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string name) {
|
||||||
if (CheckSuper(p, message, "player name")) return;
|
if (CheckSuper(p, name, "player name")) return;
|
||||||
if (message.Length == 0) message = p.name;
|
if (name.Length == 0) name = p.name;
|
||||||
|
|
||||||
List<string> rankings = Server.RankInfo.FindMatches(p, message, "rankings");
|
name = PlayerInfo.FindMatchesPreferOnline(p, name);
|
||||||
if (rankings == null) return;
|
if (name == null) return;
|
||||||
|
|
||||||
string target = PlayerMetaList.GetName(rankings[0]);
|
List<string> rankings = Server.RankInfo.FindAllExact(name);
|
||||||
Player.Message(p, " Rankings for {0}:", PlayerInfo.GetColoredName(p, target));
|
string target = PlayerInfo.GetColoredName(p, name);
|
||||||
|
|
||||||
|
if (rankings.Count == 0) {
|
||||||
|
Player.Message(p, "{0} %Shas no rankings.", target); return;
|
||||||
|
} else {
|
||||||
|
Player.Message(p, " Rankings for {0}:", target);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (string line in rankings) {
|
foreach (string line in rankings) {
|
||||||
string[] args = line.SplitSpaces();
|
string[] args = line.SplitSpaces();
|
||||||
|
@ -35,16 +35,13 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
name = PlayerInfo.FindMatchesPreferOnline(p, name);
|
name = PlayerInfo.FindMatchesPreferOnline(p, name);
|
||||||
if (name == null) return;
|
if (name == null) return;
|
||||||
|
|
||||||
List<string> notes = new List<string>();
|
List<string> notes = Server.Notes.FindAllExact(name);
|
||||||
foreach (string note in Server.Notes.Find(name)) {
|
|
||||||
notes.Add(note);
|
|
||||||
}
|
|
||||||
|
|
||||||
string target = PlayerInfo.GetColoredName(p, name);
|
string target = PlayerInfo.GetColoredName(p, name);
|
||||||
|
|
||||||
if (notes.Count == 0) {
|
if (notes.Count == 0) {
|
||||||
Player.Message(p, "{0} %Shas no notes.", target); return;
|
Player.Message(p, "{0} %Shas no notes.", target); return;
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, " Notes for {0}:", target);
|
Player.Message(p, " Notes for {0}:", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string line in notes) {
|
foreach (string line in notes) {
|
||||||
|
@ -45,42 +45,18 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<string> FindAllExact(string name) {
|
||||||
/// <summary> Finds all lines which caselessly start with the given name. </summary>
|
List<string> entries = new List<string>();
|
||||||
public IEnumerable<string> Find(string name) {
|
if (!File.Exists(file)) return entries;
|
||||||
if (!File.Exists(file)) yield break;
|
|
||||||
name += " ";
|
name += " ";
|
||||||
|
|
||||||
using (StreamReader r = new StreamReader(file)) {
|
using (StreamReader r = new StreamReader(file)) {
|
||||||
string line;
|
string line;
|
||||||
while ((line = r.ReadLine()) != null) {
|
while ((line = r.ReadLine()) != null) {
|
||||||
if (line.CaselessStarts(name)) yield return line;
|
if (line.CaselessStarts(name)) entries.Add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield break;
|
return entries;
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> FindMatches(Player p, string name, string group) {
|
|
||||||
int matches;
|
|
||||||
return Matcher.FindMulti<string>(p, name, out matches, AllLines(),
|
|
||||||
null, GetName, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<string> AllLines() {
|
|
||||||
if (!File.Exists(file)) yield break;
|
|
||||||
|
|
||||||
using (StreamReader r = new StreamReader(file)) {
|
|
||||||
string line;
|
|
||||||
while ((line = r.ReadLine()) != null) {
|
|
||||||
yield return line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetName(string line) {
|
|
||||||
int index = line.IndexOf(' ');
|
|
||||||
return index == -1 ? line : line.Substring(0, index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public static class Utils {
|
public static class Utils {
|
||||||
@ -84,9 +85,9 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static List<string> ReadAllLinesList(string path) {
|
public static List<string> ReadAllLinesList(string path) {
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
using (StreamReader r = new StreamReader(path)) {
|
using (StreamReader r = new StreamReader(path, Encoding.UTF8)) {
|
||||||
string item;
|
string line;
|
||||||
while ((item = r.ReadLine()) != null) { lines.Add(item); }
|
while ((line = r.ReadLine()) != null) { lines.Add(line); }
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user