mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -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,22 +27,28 @@ namespace MCGalaxy.Commands.Info {
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
public override bool UseableWhenFrozen { get { return true; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (CheckSuper(p, message, "player name")) return;
|
||||
if (message.Length == 0) message = p.name;
|
||||
public override void Use(Player p, string name) {
|
||||
if (CheckSuper(p, name, "player name")) return;
|
||||
if (name.Length == 0) name = p.name;
|
||||
|
||||
List<string> rankings = Server.RankInfo.FindMatches(p, message, "rankings");
|
||||
if (rankings == null) return;
|
||||
name = PlayerInfo.FindMatchesPreferOnline(p, name);
|
||||
if (name == null) return;
|
||||
|
||||
string target = PlayerMetaList.GetName(rankings[0]);
|
||||
Player.Message(p, " Rankings for {0}:", PlayerInfo.GetColoredName(p, target));
|
||||
List<string> rankings = Server.RankInfo.FindAllExact(name);
|
||||
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) {
|
||||
string[] args = line.SplitSpaces();
|
||||
TimeSpan delta;
|
||||
string oldRank, newRank;
|
||||
int offset;
|
||||
|
||||
|
||||
if (args.Length <= 6) {
|
||||
delta = DateTime.UtcNow - long.Parse(args[2]).FromUnixTime();
|
||||
newRank = args[3]; oldRank = args[4];
|
||||
|
@ -35,16 +35,13 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
name = PlayerInfo.FindMatchesPreferOnline(p, name);
|
||||
if (name == null) return;
|
||||
|
||||
List<string> notes = new List<string>();
|
||||
foreach (string note in Server.Notes.Find(name)) {
|
||||
notes.Add(note);
|
||||
}
|
||||
|
||||
List<string> notes = Server.Notes.FindAllExact(name);
|
||||
string target = PlayerInfo.GetColoredName(p, name);
|
||||
|
||||
if (notes.Count == 0) {
|
||||
Player.Message(p, "{0} %Shas no notes.", target); return;
|
||||
} else {
|
||||
Player.Message(p, " Notes for {0}:", target);
|
||||
Player.Message(p, " Notes for {0}:", target);
|
||||
}
|
||||
|
||||
foreach (string line in notes) {
|
||||
|
@ -45,42 +45,18 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Finds all lines which caselessly start with the given name. </summary>
|
||||
public IEnumerable<string> Find(string name) {
|
||||
if (!File.Exists(file)) yield break;
|
||||
public List<string> FindAllExact(string name) {
|
||||
List<string> entries = new List<string>();
|
||||
if (!File.Exists(file)) return entries;
|
||||
name += " ";
|
||||
|
||||
using (StreamReader r = new StreamReader(file)) {
|
||||
string line;
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.CaselessStarts(name)) yield return line;
|
||||
if (line.CaselessStarts(name)) entries.Add(line);
|
||||
}
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
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);
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace MCGalaxy {
|
||||
public static class Utils {
|
||||
@ -84,9 +85,9 @@ namespace MCGalaxy {
|
||||
|
||||
public static List<string> ReadAllLinesList(string path) {
|
||||
List<string> lines = new List<string>();
|
||||
using (StreamReader r = new StreamReader(path)) {
|
||||
string item;
|
||||
while ((item = r.ReadLine()) != null) { lines.Add(item); }
|
||||
using (StreamReader r = new StreamReader(path, Encoding.UTF8)) {
|
||||
string line;
|
||||
while ((line = r.ReadLine()) != null) { lines.Add(line); }
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user