-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCmdMapsBy.cs
48 lines (40 loc) · 1.35 KB
/
CmdMapsBy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using MCGalaxy;
public sealed class CmdMapsBy : Command2
{
public override string name { get { return "MapsBy"; } }
public override string shortcut { get { return "MadeBy"; } }
public override string type { get { return CommandTypes.Information; } }
public override void Use(Player p, string message, CommandData data) {
if (message == "") { Help(p); return; }
string author = PlayerInfo.FindMatchesPreferOnline(p, message);
if (author == null) return;
string[] maps = LevelInfo.AllMapNames();
List<string> madeBy = new List<string>();
foreach (string map in maps) {
if (!IsMapAuthor(author, map)) continue;
madeBy.Add(map);
}
author = p.FormatNick(author);
if (madeBy.Count == 0) {
p.Message("{0} &Shas not made any maps", author);
} else {
p.Message("{0} &Sauthored these maps: {1}", author, madeBy.Join());
}
}
public static bool IsMapAuthor(string name, string map) {
LevelConfig cfg = LevelInfo.GetConfig(map);
string[] authors = cfg.Authors.SplitComma();
if (authors.Length > 0) {
foreach (string author in authors) {
if (author.CaselessEq(name)) return true;
}
}
return LevelInfo.IsRealmOwner(map, cfg, name);
}
public override void Help(Player p) {
p.Message("&T/mapsby &H[player]");
p.Message("&HLists all maps authored by the given player.");
}
}