Cleanup /search and make it print help when an incorrect type is used, add CheckeredBrush and initial work on /brush.

This commit is contained in:
UnknownShadow200 2016-03-08 15:20:51 +11:00
parent 79dc8dfd82
commit a9e9b081ff
15 changed files with 252 additions and 161 deletions

View File

@ -55,6 +55,7 @@ namespace MCGalaxy
all.Add(new CmdBots()); all.Add(new CmdBots());
all.Add(new CmdBotSet()); all.Add(new CmdBotSet());
all.Add(new CmdBotSummon()); all.Add(new CmdBotSummon());
all.Add(new CmdBrush());
all.Add(new CmdC4()); all.Add(new CmdC4());
all.Add(new CmdCenter()); all.Add(new CmdCenter());
all.Add(new CmdChain()); all.Add(new CmdChain());

View File

@ -15,122 +15,121 @@ permissions and limitations under the Licenses.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
namespace MCGalaxy.Commands using System.Text;
{
public class CmdSearch : Command namespace MCGalaxy.Commands {
{
public class CmdSearch : Command {
public override string name { get { return "search"; } } public override string name { get { return "search"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } } public override string type { get { return CommandTypes.Information; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } 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) public override void Use(Player p, string message) {
{ string[] args = message.Split(trimChars, 2);
if (message.Split(' ').Length < 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); Help(p);
return;
} }
string type = message.Split(' ')[0]; }
string keyword = message.Remove(0, (type.Length + 1));
// static void SearchCommands(Player p, string keyword) {
if (type.ToLower().Contains("command") || type.ToLower().Contains("cmd"))
{
bool mode = true; bool mode = true;
string[] keywords = keyword.Split(' '); string[] keywords = keyword.Split(' ');
string[] found = null; string[] found = keywords.Length == 1 ?
if (keywords.Length == 1) { found = Commands.CommandKeywords.Find(keywords[0]); } CommandKeywords.Find(keyword) : CommandKeywords.Find(keywords);
else { found = Commands.CommandKeywords.Find(keywords); } if (found == null) {
if (found == null) { Player.SendMessage(p, "No commands found matching keyword(s): '" + message.Remove(0, (type.Length + 1)) + "'"); } Player.SendMessage(p, "No commands found matching keyword(s): '" + keyword + "'"); return;
else }
{
Player.SendMessage(p, "&bfound: "); Player.SendMessage(p, "&bCommands found: ");
foreach (string s in found) { if (mode) { Player.SendMessage(p, "&2/" + s); } else { Player.SendMessage(p, "&9/" + s); } mode = (mode) ? false : true; } foreach (string cmd in found) {
string code = mode ? "&2/" : "&9/";
Player.SendMessage(p, code + cmd);
mode = !mode;
} }
} }
if (type.ToLower().Contains("block"))
{ static void SearchBlocks(Player p, string keyword) {
string blocks = ""; StringBuilder blocks = new StringBuilder();
bool mode = true; bool mode = true;
for (byte i = 0; i < 255; i++) for (byte id = 0; id < 255; id++) {
{ string name = Block.Name(id);
if (Block.Name(i).ToLower() != "unknown") if (name.ToLower() != "unknown" && name.Contains(keyword)) {
{ blocks.Append(mode ? "%S, &9" : "%S, &2").Append(name);
if (Block.Name(i).Contains(keyword)) mode = !mode;
{
if (mode) { blocks += Server.DefaultColor + ", &9" + Block.Name(i); }
else { blocks += Server.DefaultColor + ", &2" + Block.Name(i); }
mode = (mode) ? false : true;
} }
} }
if (blocks.Length == 0) { Player.SendMessage(p, "No blocks found containing &b" + keyword); return; }
Player.SendMessage(p, blocks.ToString(4, blocks.Length - 4));
} }
if (blocks == "") { Player.SendMessage(p, "No blocks found containing &b" + keyword); }
Player.SendMessage(p, blocks.Remove(0, 2)); 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 (type.ToLower().Contains("rank")) if (ranks.Length == 0) { Player.SendMessage(p, "No ranks found containing &b" + keyword); return; }
{ Player.SendMessage(p, ranks.ToString(2, ranks.Length - 2));
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); } static void SearchPlayers(Player p, string keyword) {
else { foreach (string r in ranks.Split('\'')) { Player.SendMessage(p, r); } } StringBuilder players = new StringBuilder();
}
if (type.ToLower().Contains("player"))
{
string players = "";
Player[] online = PlayerInfo.Online; Player[] online = PlayerInfo.Online;
foreach (Player who in online) foreach (Player who in online) {
{ if (who.name.IndexOf(keyword, comp) >= 0 && Player.CanSee(p, who))
if (who.name.ToLower().Contains(keyword.ToLower())) players.Append(", ").Append(who.color).Append(who.name);
{
players += ", " + who.color + 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));
} }
if (players == "") { Player.SendMessage(p, "No usernames found containing &b" + keyword); }
else { Player.SendMessage(p, players.Remove(0, 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 (type.ToLower().Contains("loaded")) if (levels.Length == 0) { Player.SendMessage(p, "No loaded levels found containing &b" + keyword); return; }
{ Player.SendMessage(p, levels.ToString(2, levels.Length - 2));
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); } static void SearchUnloaded(Player p, string keyword) {
else { Player.SendMessage(p, levels.Remove(0, 2)); } StringBuilder searched = new StringBuilder();
}
if (type.ToLower().Contains("levels"))
{
string searched = "";
DirectoryInfo di = new DirectoryInfo("levels/"); DirectoryInfo di = new DirectoryInfo("levels/");
FileInfo[] fi = di.GetFiles("*.lvl"); FileInfo[] fi = di.GetFiles("*.lvl");
foreach (FileInfo file in fi) foreach (FileInfo file in fi) {
{ string level = file.Name.Replace(".lvl", "");
string level = file.Name.Replace(".lvl", "".ToLower()); if (level.IndexOf(keyword, comp) >= 0)
if ((level.Contains(keyword.ToLower()))) searched.Append(", ").Append(level);
{
searched += ", " + level;
}
} }
if (searched == "") { Player.SendMessage(p, "No levels found containing &b" + keyword); } if (searched.Length == 0) { Player.SendMessage(p, "No levels found containing &b" + keyword); return; }
else { Player.SendMessage(p, searched.Remove(0, 2)); } Player.SendMessage(p, searched.ToString(2, searched.Length - 2));
} }
} public override void Help(Player p) {
public override void Help(Player p)
{
Player.SendMessage(p, "&b/search &2commands &a<keywords[more]> &e- finds commands with those keywords"); Player.SendMessage(p, "&b/search &2commands &a<keywords[more]> &e- finds commands with those keywords");
Player.SendMessage(p, "&b/search &2blocks &a<keyword> &e- finds blocks with that keyword"); Player.SendMessage(p, "&b/search &2blocks &a<keyword> &e- finds blocks with that keyword");
Player.SendMessage(p, "&b/search &2ranks &a<keyword> &e- finds blocks with that keyword"); Player.SendMessage(p, "&b/search &2ranks &a<keyword> &e- finds blocks with that keyword");

View File

@ -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 <name> - Sets the currently active brush to the given name.");
Player.SendMessage(p, "Available brushes: " + AvailableBrushes);
}
}
}

View File

@ -58,18 +58,12 @@ namespace MCGalaxy.Commands
} }
protected override SolidType GetType(string msg) { protected override SolidType GetType(string msg) {
if (msg == "solid") if (msg == "solid") return SolidType.solid;
return SolidType.solid; else if (msg == "hollow") return SolidType.hollow;
else if (msg == "hollow") else if (msg == "walls") return SolidType.walls;
return SolidType.hollow; else if (msg == "holes") return SolidType.holes;
else if (msg == "walls") else if (msg == "wire") return SolidType.wire;
return SolidType.walls; else if (msg == "random") return SolidType.random;
else if (msg == "holes")
return SolidType.holes;
else if (msg == "wire")
return SolidType.wire;
else if (msg == "random")
return SolidType.random;
return SolidType.Invalid; return SolidType.Invalid;
} }

View File

@ -27,21 +27,14 @@ namespace MCGalaxy.Commands {
public override string name { get { return "fill"; } } public override string name { get { return "fill"; } }
public override string shortcut { get { return "f"; } } public override string shortcut { get { return "f"; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public CmdFill() { }
protected override SolidType GetType(string msg) { protected override SolidType GetType(string msg) {
if (msg == "default") if (msg == "default") return SolidType.solid;
return SolidType.solid; else if (msg == "up") return SolidType.up;
else if (msg == "up") else if (msg == "down") return SolidType.down;
return SolidType.up; else if (msg == "layer") return SolidType.layer;
else if (msg == "down") else if (msg == "vertical_x") return SolidType.verticalX;
return SolidType.down; else if (msg == "vertical_z") return SolidType.verticalZ;
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; return SolidType.Invalid;
} }

View File

@ -32,10 +32,8 @@ namespace MCGalaxy.Commands {
protected override int MaxArgs { get { return 3; } } protected override int MaxArgs { get { return 3; } }
protected override SolidType GetType(string msg) { protected override SolidType GetType(string msg) {
if (msg == "walls") if (msg == "walls") return SolidType.walls;
return SolidType.walls; else if (msg == "straight") return SolidType.straight;
else if (msg == "straight")
return SolidType.straight;
return SolidType.solid; return SolidType.solid;
} }

View File

@ -55,12 +55,9 @@ namespace MCGalaxy.Commands
} }
protected override SolidType GetType(string msg) { protected override SolidType GetType(string msg) {
if (msg == "solid") if (msg == "solid") return SolidType.solid;
return SolidType.solid; else if (msg == "hollow") return SolidType.hollow;
else if (msg == "hollow") else if (msg == "reverse") return SolidType.reverse;
return SolidType.hollow;
else if (msg == "reverse")
return SolidType.reverse;
return SolidType.Invalid; return SolidType.Invalid;
} }

View File

@ -50,12 +50,9 @@ namespace MCGalaxy.Commands {
} }
protected override SolidType GetType(string msg) { protected override SolidType GetType(string msg) {
if (msg == "solid") if (msg == "solid") return SolidType.solid;
return SolidType.solid; else if (msg == "hollow") return SolidType.hollow;
else if (msg == "hollow") else if (msg == "vertical") return SolidType.vertical;
return SolidType.hollow;
else if (msg == "vertical")
return SolidType.vertical;
return SolidType.Invalid; return SolidType.Invalid;
} }

View File

@ -28,10 +28,11 @@ namespace MCGalaxy.Drawing.Brushes {
public abstract byte NextExtBlock(DrawOp op); public abstract byte NextExtBlock(DrawOp op);
public Dictionary<string, Func<BrushArgs, Brush>> Brushes = new Dictionary<string, Func<BrushArgs, Brush>> { public static Dictionary<string, Func<BrushArgs, Brush>> Brushes
= new Dictionary<string, Func<BrushArgs, Brush>> {
{ "normal", SolidBrush.Process }, { "normal", SolidBrush.Process },
{ "solid", SolidBrush.Process },
{ "paste", PasteBrush.Process }, { "paste", PasteBrush.Process },
{ "checkered", CheckeredBrush.Process },
}; };
} }

View File

@ -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;
}
}
}

View File

@ -269,7 +269,7 @@ namespace MCGalaxy {
break; break;
} }
if (StandardPhysics.DoLeafDecay(this, C)) if (StandardPhysics.DoLeafDecay(this, C))
AddUpdate(C.b, 0); AddUpdate(C.b, Block.air);
C.time = 255; C.time = 255;
break; break;
@ -648,7 +648,7 @@ namespace MCGalaxy {
case Block.mushroom: case Block.mushroom:
case Block.redmushroom: case Block.redmushroom:
if (physics > 1 && physics != 5 && !CheckSpongeWater(x, y, z)) 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; break;
case Block.sand: case Block.sand:
@ -778,10 +778,10 @@ namespace MCGalaxy {
byte tile = GetTile(bBelow); byte tile = GetTile(bBelow);
if (tile == Block.staircasestep) { if (tile == Block.staircasestep) {
AddUpdate(b, 0); AddUpdate(b, Block.air);
AddUpdate(bBelow, Block.staircasefull); AddUpdate(bBelow, Block.staircasefull);
} else if (tile == Block.cobblestoneslab) { } else if (tile == Block.cobblestoneslab) {
AddUpdate(b, 0); AddUpdate(b, Block.air);
AddUpdate(bBelow, Block.stone); AddUpdate(bBelow, Block.stone);
} }
} }
@ -826,7 +826,7 @@ namespace MCGalaxy {
if (block == Block.Zero) continue; if (block == Block.Zero) continue;
if ((!lava && Block.Convert(block) == Block.water) || (lava && Block.Convert(block) == Block.lava)) if ((!lava && Block.Convert(block) == Block.water) || (lava && Block.Convert(block) == Block.lava))
AddUpdate(index, 0); AddUpdate(index, Block.air);
} }
} }

View File

@ -51,7 +51,7 @@ namespace MCGalaxy.BlockPhysics {
public static void DoFlood(Level lvl, Check C, Random rand, AirFlood mode, byte block) { public static void DoFlood(Level lvl, Check C, Random rand, AirFlood mode, byte block) {
if (C.time >= 1) { if (C.time >= 1) {
lvl.AddUpdate(C.b, 0); lvl.AddUpdate(C.b, Block.air);
C.time = 255; return; C.time = 255; return;
} }
ushort x, y, z; ushort x, y, z;

View File

@ -103,6 +103,7 @@
<Compile Include="API\WhoWas.cs" /> <Compile Include="API\WhoWas.cs" />
<Compile Include="Commands\Building\CmdAbort.cs" /> <Compile Include="Commands\Building\CmdAbort.cs" />
<Compile Include="Commands\Building\CmdBind.cs" /> <Compile Include="Commands\Building\CmdBind.cs" />
<Compile Include="Commands\building\CmdBrush.cs" />
<Compile Include="Commands\Building\CmdCenter.cs" /> <Compile Include="Commands\Building\CmdCenter.cs" />
<Compile Include="Commands\Building\CmdClick.cs" /> <Compile Include="Commands\Building\CmdClick.cs" />
<Compile Include="Commands\Building\CmdCmdBind.cs" /> <Compile Include="Commands\Building\CmdCmdBind.cs" />
@ -392,6 +393,7 @@
<Compile Include="Commands\World\CmdUnlock.cs" /> <Compile Include="Commands\World\CmdUnlock.cs" />
<Compile Include="Drawing\BlockWriter.cs" /> <Compile Include="Drawing\BlockWriter.cs" />
<Compile Include="Drawing\Brushes\Brush.cs" /> <Compile Include="Drawing\Brushes\Brush.cs" />
<Compile Include="Drawing\Brushes\CheckeredBrush.cs" />
<Compile Include="Drawing\Brushes\PasteBrush.cs" /> <Compile Include="Drawing\Brushes\PasteBrush.cs" />
<Compile Include="Drawing\Brushes\SolidBrush.cs" /> <Compile Include="Drawing\Brushes\SolidBrush.cs" />
<Compile Include="Drawing\CopyState.cs" /> <Compile Include="Drawing\CopyState.cs" />

View File

@ -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 // handles the /womid client message, which displays the WoM vrersion
if ( text.Truncate(6) == "/womid" ) { if ( text.Truncate(6) == "/womid" ) {
string version = (text.Length <= 21 ? text.Substring(text.IndexOf(' ') + 1) : text.Substring(7, 15)); 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] " + color + DisplayName + "%f is using wom client");
Server.s.Log(Colors.red + "[INFO] %fVersion: " + version); Server.s.Log(Colors.red + "[INFO] %fVersion: " + version);
UsingWom = true; UsingWom = true;
WoMVersion = version.Split('-')[1];
return; return;
} }

View File

@ -69,9 +69,9 @@ namespace MCGalaxy {
public System.Timers.Timer afkTimer = new System.Timers.Timer(2000); public System.Timers.Timer afkTimer = new System.Timers.Timer(2000);
public int afkCount = 0; public int afkCount = 0;
public DateTime afkStart; public DateTime afkStart;
public string WoMVersion = "";
public bool cmdTimer = false; public bool cmdTimer = false;
public bool UsingWom = false; public bool UsingWom = false;
public string BrushName = "normal";
byte[] buffer = new byte[0]; byte[] buffer = new byte[0];
byte[] tempbuffer = new byte[0xFF]; byte[] tempbuffer = new byte[0xFF];