From a9e9b081ff5e533ac0df19b7d4071baebc4f19d1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 8 Mar 2016 15:20:51 +1100 Subject: [PATCH] Cleanup /search and make it print help when an incorrect type is used, add CheckeredBrush and initial work on /brush. --- Commands/Command.All.cs | 1 + Commands/Information/CmdSearch.cs | 215 +++++++++++++++--------------- Commands/building/CmdBrush.cs | 55 ++++++++ Commands/building/CmdCuboid.cs | 18 +-- Commands/building/CmdFill.cs | 19 +-- Commands/building/CmdLine.cs | 6 +- Commands/building/CmdPyramid.cs | 9 +- Commands/building/CmdSpheroid.cs | 9 +- Drawing/Brushes/Brush.cs | 5 +- Drawing/Brushes/CheckeredBrush.cs | 57 ++++++++ Levels/Level.Physics.cs | 10 +- Levels/Physics/AirPhysics.cs | 2 +- MCGalaxy_.csproj | 2 + Player/Player.Handlers.cs | 3 - Player/Player.cs | 2 +- 15 files changed, 252 insertions(+), 161 deletions(-) create mode 100644 Commands/building/CmdBrush.cs create mode 100644 Drawing/Brushes/CheckeredBrush.cs diff --git a/Commands/Command.All.cs b/Commands/Command.All.cs index 765cf02ab..496eef525 100644 --- a/Commands/Command.All.cs +++ b/Commands/Command.All.cs @@ -55,6 +55,7 @@ namespace MCGalaxy all.Add(new CmdBots()); all.Add(new CmdBotSet()); all.Add(new CmdBotSummon()); + all.Add(new CmdBrush()); all.Add(new CmdC4()); all.Add(new CmdCenter()); all.Add(new CmdChain()); diff --git a/Commands/Information/CmdSearch.cs b/Commands/Information/CmdSearch.cs index 31ae0f01f..6e80ab39c 100644 --- a/Commands/Information/CmdSearch.cs +++ b/Commands/Information/CmdSearch.cs @@ -11,126 +11,125 @@ software distributed under the Licenses are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. -*/ + */ using System; using System.Collections.Generic; using System.IO; -namespace MCGalaxy.Commands -{ - public class CmdSearch : Command - { +using System.Text; + +namespace MCGalaxy.Commands { + + public class CmdSearch : Command { + public override string name { get { return "search"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Information; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } - public CmdSearch() { } + static char[] trimChars = { ' ' }; + const StringComparison comp = StringComparison.OrdinalIgnoreCase; - public override void Use(Player p, string message) - { - if (message.Split(' ').Length < 2) - { + public override void Use(Player p, string message) { + string[] args = message.Split(trimChars, 2); + if (args.Length < 2) { Help(p); return; } + args[0] = args[0].ToLower(); + string keyword = args[1]; + + if (args[0] == "cmd" || args[0] == "cmds" || args[0] == "command" || args[0] == "commands") { + SearchCommands(p, keyword); + } else if (args[0] == "block" || args[0] == "blocks") { + SearchBlocks(p, keyword); + } else if (args[0] == "rank" || args[0] == "ranks") { + SearchRanks(p, keyword); + } else if (args[0] == "user" || args[0] == "users" || args[0] == "player" || args[0] == "players") { + SearchPlayers(p, keyword); + } else if (args[0] == "loaded") { + SearchLoaded(p, keyword); + } else if (args[0] == "level" || args[0] == "levels") { + SearchUnloaded(p, keyword); + } else { Help(p); - return; } - string type = message.Split(' ')[0]; - string keyword = message.Remove(0, (type.Length + 1)); - // - if (type.ToLower().Contains("command") || type.ToLower().Contains("cmd")) - { - bool mode = true; - string[] keywords = keyword.Split(' '); - string[] found = null; - if (keywords.Length == 1) { found = Commands.CommandKeywords.Find(keywords[0]); } - else { found = Commands.CommandKeywords.Find(keywords); } - if (found == null) { Player.SendMessage(p, "No commands found matching keyword(s): '" + message.Remove(0, (type.Length + 1)) + "'"); } - else - { - Player.SendMessage(p, "&bfound: "); - foreach (string s in found) { if (mode) { Player.SendMessage(p, "&2/" + s); } else { Player.SendMessage(p, "&9/" + s); } mode = (mode) ? false : true; } - } - } - if (type.ToLower().Contains("block")) - { - string blocks = ""; - bool mode = true; - for (byte i = 0; i < 255; i++) - { - if (Block.Name(i).ToLower() != "unknown") - { - if (Block.Name(i).Contains(keyword)) - { - if (mode) { blocks += Server.DefaultColor + ", &9" + Block.Name(i); } - else { blocks += Server.DefaultColor + ", &2" + Block.Name(i); } - mode = (mode) ? false : true; - } - } - } - if (blocks == "") { Player.SendMessage(p, "No blocks found containing &b" + keyword); } - Player.SendMessage(p, blocks.Remove(0, 2)); - } - if (type.ToLower().Contains("rank")) - { - string ranks = ""; - foreach (Group g in Group.GroupList) - { - if (g.name.Contains(keyword)) - { - ranks += g.color + g.name + "'"; - } - } - if (ranks == "") { Player.SendMessage(p, "No ranks found containing &b" + keyword); } - else { foreach (string r in ranks.Split('\'')) { Player.SendMessage(p, r); } } - } - if (type.ToLower().Contains("player")) - { - string players = ""; - Player[] online = PlayerInfo.Online; - foreach (Player who in online) - { - if (who.name.ToLower().Contains(keyword.ToLower())) - { - players += ", " + who.color + who.name; - } - } - if (players == "") { Player.SendMessage(p, "No usernames found containing &b" + keyword); } - else { Player.SendMessage(p, players.Remove(0, 2)); } - } - if (type.ToLower().Contains("loaded")) - { - string levels = ""; - foreach (Level level in Server.levels) - { - if (level.name.ToLower().Contains(keyword.ToLower())) - { - levels += ", " + level.name; - } - } - if (levels == "") { Player.SendMessage(p, "No loaded levels found containing &b" + keyword); } - else { Player.SendMessage(p, levels.Remove(0, 2)); } - } - if (type.ToLower().Contains("levels")) - { - string searched = ""; - DirectoryInfo di = new DirectoryInfo("levels/"); - FileInfo[] fi = di.GetFiles("*.lvl"); - - foreach (FileInfo file in fi) - { - string level = file.Name.Replace(".lvl", "".ToLower()); - if ((level.Contains(keyword.ToLower()))) - { - searched += ", " + level; - } - } - - if (searched == "") { Player.SendMessage(p, "No levels found containing &b" + keyword); } - else { Player.SendMessage(p, searched.Remove(0, 2)); } - } - } - public override void Help(Player p) - { + + static void SearchCommands(Player p, string keyword) { + bool mode = true; + string[] keywords = keyword.Split(' '); + string[] found = keywords.Length == 1 ? + CommandKeywords.Find(keyword) : CommandKeywords.Find(keywords); + if (found == null) { + Player.SendMessage(p, "No commands found matching keyword(s): '" + keyword + "'"); return; + } + + Player.SendMessage(p, "&bCommands found: "); + foreach (string cmd in found) { + string code = mode ? "&2/" : "&9/"; + Player.SendMessage(p, code + cmd); + mode = !mode; + } + } + + static void SearchBlocks(Player p, string keyword) { + StringBuilder blocks = new StringBuilder(); + bool mode = true; + for (byte id = 0; id < 255; id++) { + string name = Block.Name(id); + if (name.ToLower() != "unknown" && name.Contains(keyword)) { + blocks.Append(mode ? "%S, &9" : "%S, &2").Append(name); + mode = !mode; + } + } + if (blocks.Length == 0) { Player.SendMessage(p, "No blocks found containing &b" + keyword); return; } + Player.SendMessage(p, blocks.ToString(4, blocks.Length - 4)); + } + + static void SearchRanks(Player p, string keyword) { + StringBuilder ranks = new StringBuilder(); + foreach (Group g in Group.GroupList) { + if (g.name.IndexOf(keyword, comp) >= 0) + ranks.Append(", ").Append(g.color).Append(g.name); + } + if (ranks.Length == 0) { Player.SendMessage(p, "No ranks found containing &b" + keyword); return; } + Player.SendMessage(p, ranks.ToString(2, ranks.Length - 2)); + } + + static void SearchPlayers(Player p, string keyword) { + StringBuilder players = new StringBuilder(); + Player[] online = PlayerInfo.Online; + foreach (Player who in online) { + if (who.name.IndexOf(keyword, comp) >= 0 && Player.CanSee(p, who)) + players.Append(", ").Append(who.color).Append(who.name); + } + if (players.Length == 0) { Player.SendMessage(p, "No usernames found containing &b" + keyword); return; } + Player.SendMessage(p, players.ToString(2, players.Length - 2)); + } + + static void SearchLoaded(Player p, string keyword) { + StringBuilder levels = new StringBuilder(); + foreach (Level level in Server.levels) { + if (level.name.IndexOf(keyword, comp) >= 0) + levels.Append(", ").Append(level.name); + } + if (levels.Length == 0) { Player.SendMessage(p, "No loaded levels found containing &b" + keyword); return; } + Player.SendMessage(p, levels.ToString(2, levels.Length - 2)); + } + + static void SearchUnloaded(Player p, string keyword) { + StringBuilder searched = new StringBuilder(); + DirectoryInfo di = new DirectoryInfo("levels/"); + FileInfo[] fi = di.GetFiles("*.lvl"); + + foreach (FileInfo file in fi) { + string level = file.Name.Replace(".lvl", ""); + if (level.IndexOf(keyword, comp) >= 0) + searched.Append(", ").Append(level); + } + + if (searched.Length == 0) { Player.SendMessage(p, "No levels found containing &b" + keyword); return; } + Player.SendMessage(p, searched.ToString(2, searched.Length - 2)); + } + + public override void Help(Player p) { Player.SendMessage(p, "&b/search &2commands &a &e- finds commands with those keywords"); Player.SendMessage(p, "&b/search &2blocks &a &e- finds blocks with that keyword"); Player.SendMessage(p, "&b/search &2ranks &a &e- finds blocks with that keyword"); diff --git a/Commands/building/CmdBrush.cs b/Commands/building/CmdBrush.cs new file mode 100644 index 000000000..e3d2ce3bf --- /dev/null +++ b/Commands/building/CmdBrush.cs @@ -0,0 +1,55 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using MCGalaxy; +using MCGalaxy.Drawing.Brushes; + +namespace MCGalaxy.Commands { + + public sealed class CmdBrush : Command { + public override string name { get { return "brush"; } } + public override string shortcut { get { return ""; } } + public override string type { get { return CommandTypes.Building; } } + public override bool museumUsable { get { return false; } } + public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } + + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } + if (p == null) { MessageInGameOnly(p); return; } + + foreach (var brush in Brush.Brushes) { + if (brush.Key.Equals(message, StringComparison.OrdinalIgnoreCase)) { + Player.SendMessage(p, "Set your brush to: " + brush.Key); + p.BrushName = brush.Key; + return; + } + } + Player.SendMessage(p, "No brush found with name \"" + message + "\"."); + Player.SendMessage(p, "Available brushes: " + AvailableBrushes); + } + + static string AvailableBrushes { + get { return string.Join( ", ", Brush.Brushes.Keys); } + } + + public override void Help(Player p) { + Player.SendMessage(p, "/brush - Sets the currently active brush to the given name."); + Player.SendMessage(p, "Available brushes: " + AvailableBrushes); + } + } +} diff --git a/Commands/building/CmdCuboid.cs b/Commands/building/CmdCuboid.cs index 58cb208f8..8ff09883e 100644 --- a/Commands/building/CmdCuboid.cs +++ b/Commands/building/CmdCuboid.cs @@ -58,18 +58,12 @@ namespace MCGalaxy.Commands } protected override SolidType GetType(string msg) { - if (msg == "solid") - return SolidType.solid; - else if (msg == "hollow") - return SolidType.hollow; - else if (msg == "walls") - return SolidType.walls; - else if (msg == "holes") - return SolidType.holes; - else if (msg == "wire") - return SolidType.wire; - else if (msg == "random") - return SolidType.random; + if (msg == "solid") return SolidType.solid; + else if (msg == "hollow") return SolidType.hollow; + else if (msg == "walls") return SolidType.walls; + else if (msg == "holes") return SolidType.holes; + else if (msg == "wire") return SolidType.wire; + else if (msg == "random") return SolidType.random; return SolidType.Invalid; } diff --git a/Commands/building/CmdFill.cs b/Commands/building/CmdFill.cs index 27b36eb6e..858356e38 100644 --- a/Commands/building/CmdFill.cs +++ b/Commands/building/CmdFill.cs @@ -27,21 +27,14 @@ namespace MCGalaxy.Commands { public override string name { get { return "fill"; } } public override string shortcut { get { return "f"; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } - public CmdFill() { } protected override SolidType GetType(string msg) { - if (msg == "default") - return SolidType.solid; - else if (msg == "up") - return SolidType.up; - else if (msg == "down") - return SolidType.down; - else if (msg == "layer") - return SolidType.layer; - else if (msg == "vertical_x") - return SolidType.verticalX; - else if (msg == "vertical_z") - return SolidType.verticalZ; + if (msg == "default") return SolidType.solid; + else if (msg == "up") return SolidType.up; + else if (msg == "down") return SolidType.down; + else if (msg == "layer") return SolidType.layer; + else if (msg == "vertical_x") return SolidType.verticalX; + else if (msg == "vertical_z") return SolidType.verticalZ; return SolidType.Invalid; } diff --git a/Commands/building/CmdLine.cs b/Commands/building/CmdLine.cs index bf101455d..24c825568 100644 --- a/Commands/building/CmdLine.cs +++ b/Commands/building/CmdLine.cs @@ -32,10 +32,8 @@ namespace MCGalaxy.Commands { protected override int MaxArgs { get { return 3; } } protected override SolidType GetType(string msg) { - if (msg == "walls") - return SolidType.walls; - else if (msg == "straight") - return SolidType.straight; + if (msg == "walls") return SolidType.walls; + else if (msg == "straight") return SolidType.straight; return SolidType.solid; } diff --git a/Commands/building/CmdPyramid.cs b/Commands/building/CmdPyramid.cs index 51163bf51..121fdaf72 100644 --- a/Commands/building/CmdPyramid.cs +++ b/Commands/building/CmdPyramid.cs @@ -55,12 +55,9 @@ namespace MCGalaxy.Commands } protected override SolidType GetType(string msg) { - if (msg == "solid") - return SolidType.solid; - else if (msg == "hollow") - return SolidType.hollow; - else if (msg == "reverse") - return SolidType.reverse; + if (msg == "solid") return SolidType.solid; + else if (msg == "hollow") return SolidType.hollow; + else if (msg == "reverse") return SolidType.reverse; return SolidType.Invalid; } diff --git a/Commands/building/CmdSpheroid.cs b/Commands/building/CmdSpheroid.cs index 26965ec13..de59b5fa4 100644 --- a/Commands/building/CmdSpheroid.cs +++ b/Commands/building/CmdSpheroid.cs @@ -50,12 +50,9 @@ namespace MCGalaxy.Commands { } protected override SolidType GetType(string msg) { - if (msg == "solid") - return SolidType.solid; - else if (msg == "hollow") - return SolidType.hollow; - else if (msg == "vertical") - return SolidType.vertical; + if (msg == "solid") return SolidType.solid; + else if (msg == "hollow") return SolidType.hollow; + else if (msg == "vertical") return SolidType.vertical; return SolidType.Invalid; } diff --git a/Drawing/Brushes/Brush.cs b/Drawing/Brushes/Brush.cs index b1c3adc2e..7541f245e 100644 --- a/Drawing/Brushes/Brush.cs +++ b/Drawing/Brushes/Brush.cs @@ -28,10 +28,11 @@ namespace MCGalaxy.Drawing.Brushes { public abstract byte NextExtBlock(DrawOp op); - public Dictionary> Brushes = new Dictionary> { + public static Dictionary> Brushes + = new Dictionary> { { "normal", SolidBrush.Process }, - { "solid", SolidBrush.Process }, { "paste", PasteBrush.Process }, + { "checkered", CheckeredBrush.Process }, }; } diff --git a/Drawing/Brushes/CheckeredBrush.cs b/Drawing/Brushes/CheckeredBrush.cs new file mode 100644 index 000000000..b360c8eb4 --- /dev/null +++ b/Drawing/Brushes/CheckeredBrush.cs @@ -0,0 +1,57 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using MCGalaxy.Commands; +using MCGalaxy.Drawing.Ops; + +namespace MCGalaxy.Drawing.Brushes { + + public sealed class CheckeredBrush : Brush { + readonly byte type1, extType1, type2, extType2; + + public CheckeredBrush(byte type1, byte extType1, byte type2, byte extType2) { + this.type1 = type1; this.extType1 = extType1; + this.type2 = type2; this.extType2 = extType2; + } + + public static CheckeredBrush Process(BrushArgs args) { + if (args.Message == "") + return new CheckeredBrush(args.Type, args.ExtType, 0, 0); + string[] parts = args.Message.Split(' '); + byte extType1; + byte type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1); + if (type1 == Block.Zero) return null; + if (parts.Length == 1) + return new CheckeredBrush(type1, extType1, 0, 0); + + byte extType2; + byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2); + if (type2 == Block.Zero) return null; + return new CheckeredBrush(type1, extType1, type2, extType2); + } + + public override byte NextBlock(DrawOp op) { + return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 1) == 0 ? type1 : type2; + } + + public override byte NextExtBlock(DrawOp op) { + return ((op.Coords.X + op.Coords.Y + op.Coords.Z) & 1) == 0 ? extType1 : extType2; + } + } +} diff --git a/Levels/Level.Physics.cs b/Levels/Level.Physics.cs index 7afdaeba6..549517074 100644 --- a/Levels/Level.Physics.cs +++ b/Levels/Level.Physics.cs @@ -269,7 +269,7 @@ namespace MCGalaxy { break; } if (StandardPhysics.DoLeafDecay(this, C)) - AddUpdate(C.b, 0); + AddUpdate(C.b, Block.air); C.time = 255; break; @@ -648,7 +648,7 @@ namespace MCGalaxy { case Block.mushroom: case Block.redmushroom: if (physics > 1 && physics != 5 && !CheckSpongeWater(x, y, z)) - AddUpdate(b, 0); //Adv physics kills flowers and mushrooms in water + AddUpdate(b, Block.air); //Adv physics kills flowers and mushrooms in water break; case Block.sand: @@ -778,10 +778,10 @@ namespace MCGalaxy { byte tile = GetTile(bBelow); if (tile == Block.staircasestep) { - AddUpdate(b, 0); + AddUpdate(b, Block.air); AddUpdate(bBelow, Block.staircasefull); } else if (tile == Block.cobblestoneslab) { - AddUpdate(b, 0); + AddUpdate(b, Block.air); AddUpdate(bBelow, Block.stone); } } @@ -826,7 +826,7 @@ namespace MCGalaxy { if (block == Block.Zero) continue; if ((!lava && Block.Convert(block) == Block.water) || (lava && Block.Convert(block) == Block.lava)) - AddUpdate(index, 0); + AddUpdate(index, Block.air); } } diff --git a/Levels/Physics/AirPhysics.cs b/Levels/Physics/AirPhysics.cs index 72144433c..9c7cb8798 100644 --- a/Levels/Physics/AirPhysics.cs +++ b/Levels/Physics/AirPhysics.cs @@ -51,7 +51,7 @@ namespace MCGalaxy.BlockPhysics { public static void DoFlood(Level lvl, Check C, Random rand, AirFlood mode, byte block) { if (C.time >= 1) { - lvl.AddUpdate(C.b, 0); + lvl.AddUpdate(C.b, Block.air); C.time = 255; return; } ushort x, y, z; diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index c19187cd9..b91c05143 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -103,6 +103,7 @@ + @@ -392,6 +393,7 @@ + diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index f8ff13a09..e7f7e1387 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -1138,12 +1138,9 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { } // handles the /womid client message, which displays the WoM vrersion if ( text.Truncate(6) == "/womid" ) { string version = (text.Length <= 21 ? text.Substring(text.IndexOf(' ') + 1) : text.Substring(7, 15)); - Player.GlobalMessage(Colors.red + "[INFO] " + color + DisplayName + "%f is using wom client"); - Player.GlobalMessage(Colors.red + "[INFO] %fVersion: " + version); Server.s.Log(Colors.red + "[INFO] " + color + DisplayName + "%f is using wom client"); Server.s.Log(Colors.red + "[INFO] %fVersion: " + version); UsingWom = true; - WoMVersion = version.Split('-')[1]; return; } diff --git a/Player/Player.cs b/Player/Player.cs index e51932927..3eea6df94 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -69,9 +69,9 @@ namespace MCGalaxy { public System.Timers.Timer afkTimer = new System.Timers.Timer(2000); public int afkCount = 0; public DateTime afkStart; - public string WoMVersion = ""; public bool cmdTimer = false; public bool UsingWom = false; + public string BrushName = "normal"; byte[] buffer = new byte[0]; byte[] tempbuffer = new byte[0xFF];