-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCmdBestMaps.cs
65 lines (53 loc) · 2.03 KB
/
CmdBestMaps.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.IO;
using MCGalaxy;
namespace MCGalaxy.Commands.Info
{
public sealed class CmdBestMaps : Command2
{
public override string name { get { return "BestMaps"; } }
public override string shortcut { get { return "bm"; } }
public override string type { get { return "information"; } }
public override void Use(Player p, string message, CommandData data)
{
string path = "./text/bestmaps.txt";
string[] args = message.SplitSpaces();
if (message.Length == 0)
{
string[] maps = File.ReadAllLines(path); // Retrieve all maps in the list
if (maps.Length == 0)
{
p.Message("There are no maps in the BestMaps list. Add some via &b/BestMaps add [name]&S.");
return;
}
Random rnd = new Random();
PlayerActions.ChangeMap(p, maps[rnd.Next(maps.Length)]); // Send player to a randomly-selected map from the list
}
else if (args[0].CaselessEq("add"))
{
if (args.Length < 2)
{
p.Message("You need to specify a map name to add to the list.");
return;
}
string map = args[1].ToLower();
if (!LevelInfo.MapExists(map))
{
p.Message("Specified map does not exist.");
return;
}
File.AppendAllText(path, map + Environment.NewLine); // Add new map into the list
p.Message("Added &b" + map + " &Sinto the BestMaps list.");
}
else
{
Help(p);
}
}
public override void Help(Player p)
{
p.Message("&T/BestMaps &H- Teleports you to one of the best maps on the server.");
p.Message("&T/BestMaps add [map] &H- Adds [map] into the list of best maps.");
}
}
}