Make /vip and /whitelist use multi page output, also colour the names in them.

This commit is contained in:
UnknownShadow200 2016-09-06 21:53:21 +10:00
parent c45ebb2ebd
commit 5a2aac4573
2 changed files with 62 additions and 45 deletions

View File

@ -30,60 +30,63 @@ namespace MCGalaxy.Commands {
if (message == "") { Help(p); return; }
string[] args = message.Split(' ');
if (args[0].CaselessEq("add") {
AddVIP(p, args);
} else if (args[0].CaselessEq("remove") {
RemoveVIP(p, args);
} else if (args[0].CaselessEq("list") {
if (args[0].CaselessEq("add")) {
if (args.Length < 2) { Help(p); return; }
AddVIP(p, args[1]);
} else if (args[0].CaselessEq("remove")) {
if (args.Length < 2) { Help(p); return; }
RemoveVIP(p, args[1]);
} else if (args[0].CaselessEq("list")) {
ListVIPs(p, args);
} else if (args.Length == 1) {
AddVIP(p, args[0]);
} else {
Help(p);
}
}
void AddVIP(Player p, string[] args) {
if (args.Length < 2) { Help(p); return; }
args[1] = PlayerInfo.FindMatchesPreferOnline(p, args[1]);
if (args[1] == null) return;
static void AddVIP(Player p, string name) {
name = PlayerInfo.FindMatchesPreferOnline(p, name);
if (name == null) return;
if (Server.vip.Contains(args[1])) {
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis already a VIP.");
if (Server.vip.Contains(name)) {
Player.Message(p, PlayerInfo.GetColoredName(p, name) + " %Sis already a VIP.");
} else {
Server.vip.Add(args[1]);
Server.vip.Add(name);
Server.vip.Save(false);
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis now a VIP.");
Player.Message(p, PlayerInfo.GetColoredName(p, name) + " %Sis now a VIP.");
Player who = PlayerInfo.FindExact(args[1]);
if (who != null) Player.Message(who, "You are now a VIP!");
Player vip = PlayerInfo.FindExact(name);
if (vip != null) Player.Message(vip, "You are now a VIP!");
}
}
void RemoveVIP(Player p, string[] args) {
if (args.Length < 2) { Help(p); return; }
args[1] = PlayerInfo.FindMatchesPreferOnline(p, args[1]);
if (args[1] == null) return;
void RemoveVIP(Player p, string name) {
name = PlayerInfo.FindMatchesPreferOnline(p, name);
if (name == null) return;
if (!Server.vip.Contains(args[1])) {
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis not a VIP.");
if (!Server.vip.Contains(name)) {
Player.Message(p, PlayerInfo.GetColoredName(p, name) + " %Sis not a VIP.");
} else {
Server.vip.Remove(args[1]);
Server.vip.Remove(name);
Server.vip.Save(false);
Player.Message(p, PlayerInfo.GetColoredName(p, args[1]) + " %Sis no longer a VIP.");
Player.Message(p, PlayerInfo.GetColoredName(p, name) + " %Sis no longer a VIP.");
Player who = PlayerInfo.FindExact(args[1]);
if (who != null) Player.Message(who, "You are no longer a VIP!");
Player vip = PlayerInfo.FindExact(name);
if (vip != null) Player.Message(vip, "You are no longer a VIP!");
}
}
void ListVIPs(Player p, string[] args) {
static void ListVIPs(Player p, string[] args) {
List<string> list = Server.vip.All();
string modifier = args.Length > 1 ? args[1] : "";
if (list.Count == 5) {
if (list.Count == 0) {
Player.Message(p, "There are no VIPs.");
} else {
Player.Message(p, "VIPs:");
MultiPageOutput.Output(p, list, (name, i) => name,
MultiPageOutput.Output(p, list,
(name, i) => PlayerInfo.GetColoredName(p, name),
"vip list", "players", modifier, false);
}
}

View File

@ -15,6 +15,8 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System.Collections.Generic;
namespace MCGalaxy.Commands {
public sealed class CmdWhitelist : Command {
public override string name { get { return "whitelist"; } }
@ -27,20 +29,18 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) {
if (!Server.useWhitelist) { Player.Message(p, "Whitelist is not enabled."); return; }
if (message == "") { Help(p); return; }
int sep = message.IndexOf(' ');
string action = sep >= 0 ? message.Substring(0, sep) : message;
string player = sep >= 0 ? message.Substring(sep + 1) : "";
string[] args = message.Split(' ');
if (action.CaselessEq("list")) {
string names = Server.whiteList.All().Join(", ");
Player.Message(p, "Whitelist: &f" + names); return;
}
if (player == "") { Add(p, action); return; }
if (action.CaselessEq("add")) {
Add(p, player);
} else if (action.CaselessEq("del") || action.CaselessEq("remove")) {
Remove(p, player);
if (args[0].CaselessEq("add")) {
if (args.Length < 2) { Help(p); return; }
Add(p, args[1]);
} else if (args[0].CaselessEq("del") || args[0].CaselessEq("remove")) {
if (args.Length < 2) { Help(p); return; }
Remove(p, args[1]);
} else if (args[0].CaselessEq("list")) {
List(p, args);
} else if (args.Length == 1) {
Add(p, args[0]);
} else {
Help(p);
}
@ -48,7 +48,7 @@ namespace MCGalaxy.Commands {
static void Add(Player p, string player) {
if (Server.whiteList.Contains(player)) {
Player.Message(p, "&f" + player + " %Sis already on the whitelist!"); return;
Player.Message(p, player + " %Sis already on the whitelist!"); return;
}
Server.whiteList.Add(player);
@ -60,7 +60,7 @@ namespace MCGalaxy.Commands {
static void Remove(Player p, string player) {
if (!Server.whiteList.Contains(player)) {
Player.Message(p, "&f" + player + " %Sis not on the whitelist!"); return;
Player.Message(p, player + " %Sis not on the whitelist!"); return;
}
Server.whiteList.Remove(player);
@ -70,8 +70,22 @@ namespace MCGalaxy.Commands {
Server.s.Log("WHITELIST: Removed " + player);
}
static void List(Player p, string[] args) {
List<string> list = Server.whiteList.All();
string modifier = args.Length > 1 ? args[1] : "";
if (list.Count == 0) {
Player.Message(p, "There are no whitelisted players.");
} else {
Player.Message(p, "Whitelisted players:");
MultiPageOutput.Output(p, list,
(name, i) => PlayerInfo.GetColoredName(p, name),
"whitelist list", "players", modifier, false);
}
}
public override void Help(Player p) {
Player.Message(p, "%T/whitelist <add/del> [player]");
Player.Message(p, "%T/whitelist add/del [player]");
Player.Message(p, "%HAdds or removes [player] from the whitelist.");
Player.Message(p, "%T/whitelist list");
Player.Message(p, "%HLists all players who are on the whitelist.");