From 3e59cda39342f88662bb86dd088492845d5765ab Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 29 Mar 2016 00:03:09 +1100 Subject: [PATCH] Add /unloaded all to also include loaded levels in the list. (Thanks RealRoland) --- Commands/Information/CmdUnloaded.cs | 107 +++++++++++------------- Commands/building/CmdDraw.cs | 7 +- Commands/building/DrawCmd.cs | 7 +- Commands/other/CmdNick.cs | 2 +- Commands/other/CmdTitle.cs | 2 +- Economy/Economy.cs | 3 +- Economy/NameItems.cs | 39 +++++++-- Games/ZombieSurvival/ZombieGame.Core.cs | 2 +- 8 files changed, 98 insertions(+), 71 deletions(-) diff --git a/Commands/Information/CmdUnloaded.cs b/Commands/Information/CmdUnloaded.cs index 1a4e87b25..f1f75215a 100644 --- a/Commands/Information/CmdUnloaded.cs +++ b/Commands/Information/CmdUnloaded.cs @@ -19,11 +19,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; -namespace MCGalaxy.Commands -{ - public sealed class CmdUnloaded : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdUnloaded : Command { public override string name { get { return "unloaded"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Information; } } @@ -31,63 +31,56 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public CmdUnloaded() { } - public override void Use(Player p, string message) - { - string unloadedLevels = ""; int currentNum = 0; int maxMaps = 0; - Level[] loaded = LevelInfo.Loaded.Items; - - if (message != "") - { - try { - int n = int.Parse(message); - if (n <= 0) { Help(p); return; } - maxMaps = n * 50; - currentNum = maxMaps - 50; - } catch { Help(p); return; } + public override void Use(Player p, string message) { + bool all = false; + int start = 0, end = 0; + if (message.CaselessStarts("all")) { + all = true; + int index = message.IndexOf(' '); + message = message.Substring(index == -1 ? message.Length : (index + 1)); + } + if (message != "") { + if (!int.TryParse(message, out end) || end <= 0) { Help(p); return; } + end *= 50; + start = end - 50; } DirectoryInfo di = new DirectoryInfo("levels/"); - FileInfo[] fi = di.GetFiles("*.lvl"); - if (maxMaps == 0) - { - foreach (FileInfo file in fi) - { - string level = file.Name.Replace(".lvl", ""); - if (!loaded.Any(l => l.name.CaselessEq(level))) { - string visit = GetLoadOnGoto(level) && (p == null || p.group.Permission >= GetPerVisitPermission(level)) ? "%aYes" : "%cNo"; - unloadedLevels += ", " + Group.findPerm(GetPerBuildPermission(level)).color + level + " &b[" + visit + "&b]"; - } - } - if (unloadedLevels != "") - { + FileInfo[] files = di.GetFiles("*.lvl"); + if (end == 0) { + StringBuilder list = ListMaps(p, all, files, 0, files.Length); + if (list.Length > 0) { Player.SendMessage(p, "Unloaded levels [Accessible]: "); - Player.SendMessage(p, unloadedLevels.Remove(0, 2)); - if (fi.Length > 50) { Player.SendMessage(p, "For a more structured list, use /unloaded <1/2/3/..>"); } + Player.SendMessage(p, list.Remove(0, 2).ToString()); + if (files.Length > 50) { Player.SendMessage(p, "For a more structured list, use /unloaded <1/2/3/..>"); } + } else { + Player.SendMessage(p, "No maps are unloaded"); + } + } else { + if (end > files.Length) end = files.Length; + if (start > files.Length) { Player.SendMessage(p, "No maps beyond number " + files.Length); return; } + + StringBuilder list = ListMaps(p, all, files, start, end); + if (list.Length > 0) { + Player.SendMessage(p, "Unloaded levels [Accessible] (" + start + " to " + end + "):"); + Player.SendMessage(p, list.Remove(0, 2).ToString()); + } else { + Player.SendMessage(p, "No maps are unloaded"); } - else Player.SendMessage(p, "No maps are unloaded"); } - else - { - if (maxMaps > fi.Length) maxMaps = fi.Length; - if (currentNum > fi.Length) { Player.SendMessage(p, "No maps beyond number " + fi.Length); return; } - - Player.SendMessage(p, "Unloaded levels [Accessible] (" + currentNum + " to " + maxMaps + "):"); - for (int i = currentNum; i < maxMaps; i++) - { - string level = fi[i].Name.Replace(".lvl", ""); - if (!loaded.Any(l => l.name.CaselessEq(level))) { - string visit = GetLoadOnGoto(level) && (p == null || p.group.Permission >= GetPerVisitPermission(level)) ? "%aYes" : "%cNo"; - unloadedLevels += ", " + Group.findPerm(GetPerBuildPermission(level)).color + level + " &b[" + visit + "&b]"; - } - } - - if (unloadedLevels != "") - { - Player.SendMessage(p, unloadedLevels.Remove(0, 2)); - } - else Player.SendMessage(p, "No maps are unloaded"); + } + + StringBuilder ListMaps(Player p, bool all, FileInfo[] files, int start, int end) { + StringBuilder builder = new StringBuilder(); + Level[] loaded = LevelInfo.Loaded.Items; + for (int i = start; i < end; i++) { + string level = files[i].Name.Replace(".lvl", ""); + if (!all && loaded.Any(l => l.name.CaselessEq(level))) continue; + + string visit = GetLoadOnGoto(level) && (p == null || p.group.Permission >= GetPerVisitPermission(level)) ? "%aYes" : "%cNo"; + builder.Append(", ").Append(Group.findPerm(GetPerBuildPermission(level)).color + level + " &b[" + visit + "&b]"); } - //Exception catching since it needs to be tested on Ocean Flatgrass + return builder; } LevelPermission GetPerVisitPermission(string level) { @@ -112,8 +105,10 @@ namespace MCGalaxy.Commands } public override void Help(Player p) { - Player.SendMessage(p, "%f/unloaded " + Server.DefaultColor + "- Lists all unloaded levels and their accessible state."); - Player.SendMessage(p, "%f/unloaded <1/2/3/..> " + Server.DefaultColor + "- Shows a compact list."); + Player.SendMessage(p, "%f/unloaded %S- Lists all unloaded levels, and their accessible state."); + Player.SendMessage(p, "%f/unloaded all %S- Lists all loaded and unloaded levels, and their accessible state."); + Player.SendMessage(p, "%f/unloaded <1/2/3/..> %S- Shows a compact list."); + Player.SendMessage(p, "%f/unloaded all <1/2/3/..> %S- Shows a compact list."); } } } diff --git a/Commands/building/CmdDraw.cs b/Commands/building/CmdDraw.cs index 788455256..2c05bf821 100644 --- a/Commands/building/CmdDraw.cs +++ b/Commands/building/CmdDraw.cs @@ -20,10 +20,9 @@ using MCGalaxy.Drawing; using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Ops; -namespace MCGalaxy.Commands -{ - public sealed class CmdDraw : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdDraw : Command { public override string name { get { return "draw"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Building; } } diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index ff56fa79e..8d63bab22 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -119,8 +119,11 @@ namespace MCGalaxy.Commands { protected enum DrawMode { normal, solid, hollow, walls, holes, wire, random, - vertical, reverse, straight, - up, down, layer, verticalX, verticalZ, + vertical, reverse, straight, // line + up, down, layer, verticalX, verticalZ, // fill + cone, hcone, icone, hicone, volcano, // draw + pyramid, hpyramid, ipyramid, hipyramid,// draw + sphere, hsphere, // draw } } } diff --git a/Commands/other/CmdNick.cs b/Commands/other/CmdNick.cs index 3d62bc82f..94f6e9aed 100644 --- a/Commands/other/CmdNick.cs +++ b/Commands/other/CmdNick.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands { who.DisplayName = who.name; Player.SendChatFrom(who, who.FullName + "%S has reverted their nick to their original name.", false); } else { - if (newName.Length > 60) { Player.SendMessage(p, "Nick must be under 60 letters."); return; } + if (newName.Length >= 30) { Player.SendMessage(p, "Nick must be under 30 letters."); return; } Player.SendChatFrom(who, who.FullName + "%S has changed their nick to " + who.color + newName + "%S.", false); who.DisplayName = newName; } diff --git a/Commands/other/CmdTitle.cs b/Commands/other/CmdTitle.cs index 901695798..443be9a7c 100644 --- a/Commands/other/CmdTitle.cs +++ b/Commands/other/CmdTitle.cs @@ -42,7 +42,7 @@ namespace MCGalaxy.Commands { ParameterisedQuery query = ParameterisedQuery.Create(); if (newTitle != "") newTitle = newTitle.Replace("[", "").Replace("]", ""); - if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; } + if (newTitle.Length >= 20) { Player.SendMessage(p, "Title must be under 20 letters."); return; } if (newTitle == "") { Player.SendChatFrom(who, who.FullName + " %Shad their title removed.", false); diff --git a/Economy/Economy.cs b/Economy/Economy.cs index 617c66696..c3087a29f 100644 --- a/Economy/Economy.cs +++ b/Economy/Economy.cs @@ -150,7 +150,8 @@ namespace MCGalaxy { public static Item[] Items = { new ColorItem(), new TitleColorItem(), new TitleItem(), new RankItem(), new LevelItem(), new LoginMessageItem(), - new LogoutMessageItem(), new BlocksItem(), new QueueLevelItem(), new InfectMessageItem() }; + new LogoutMessageItem(), new BlocksItem(), new QueueLevelItem(), + new InfectMessageItem(), new NickItem(), }; public static Item GetItem(string name) { foreach (Item item in Items) { diff --git a/Economy/NameItems.cs b/Economy/NameItems.cs index 57077ae8f..629f7faed 100644 --- a/Economy/NameItems.cs +++ b/Economy/NameItems.cs @@ -32,16 +32,15 @@ namespace MCGalaxy.Eco { protected override void OnBuyCommand(Player p, string message, string[] args) { if (args.Length == 1) { Command.all.Find("title").Use(null, p.name); - Player.SendMessage(p, "%aYour title was removed for free."); - return; + Player.SendMessage(p, "%aYour title was removed for free."); return; } string title = message.Split(trimChars, 2)[1]; // keep spaces this way if (title == p.title) { - Player.SendMessage(p, "%cYou already have that title"); return; + Player.SendMessage(p, "%cYou already have that title."); return; } - if (title.Length > 17) { - Player.SendMessage(p, "%cTitles cannot be longer than 17 characters"); return; + if (title.Length >= 20) { + Player.SendMessage(p, "%cTitles must be under 20 characters."); return; } Command.all.Find("title").Use(null, p.name + " " + title); @@ -49,6 +48,36 @@ namespace MCGalaxy.Eco { MakePurchase(p, Price, "%3Title: %f" + title); } } + + public sealed class NickItem : SimpleItem { + + public NickItem() { + Aliases = new[] { "nickname", "nick", "nicks", "name", "names" }; + NoArgsResetsItem = true; + } + + public override string Name { get { return "Nickname"; } } + static char[] trimChars = { ' ' }; + + protected override void OnBuyCommand(Player p, string message, string[] args) { + if (args.Length == 1) { + Command.all.Find("nick").Use(null, p.name); + Player.SendMessage(p, "%aYour nickname was removed for free."); return; + } + + string nick = message.Split(trimChars, 2)[1]; // keep spaces this way + if (nick == p.DisplayName) { + Player.SendMessage(p, "%cYou already have that nickname."); return; + } + if (nick.Length >= 30) { + Player.SendMessage(p, "%cNicknames must be under 30 characters."); return; + } + + Command.all.Find("nick").Use(null, p.name + " " + nick); + Player.SendMessage(p, "%aYour nickname was changed to [" + p.color + nick + "%a]"); + MakePurchase(p, Price, "%3Nickname: %f" + nick); + } + } public sealed class TitleColorItem : SimpleItem { diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index e8590062f..8312f5172 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -413,7 +413,7 @@ namespace MCGalaxy.Games { } void SendVoteMessage(Player p, string lvl1, string lvl2) { - const string line1 = "&eVote for the next level! Type &a1&e, &c2&e or &93"; + const string line1 = "&eLevel vote - type &a1&e, &c2&e or &93"; string line2 = "&eLevels: &a" + lvl1 + "&e, &c" + lvl2 + "&e, &9random"; if (p.HasCpeExt(CpeExt.MessageTypes)) { p.SendCpeMessage(CpeMessageType.BottomRight2, line1, true);