Make /measure 45.245% less sucky. (Thanks Skinnygamer)

This commit is contained in:
UnknownShadow200 2016-03-04 21:34:28 +11:00
parent d92f61698d
commit 79f99cdbfa
3 changed files with 63 additions and 55 deletions

View File

@ -1,78 +1,86 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
namespace MCGalaxy.Commands
{ namespace MCGalaxy.Commands {
public sealed class CmdMeasure : Command
{ public sealed class CmdMeasure : Command {
public override string name { get { return "measure"; } } public override string name { get { return "measure"; } }
public override string shortcut { get { return "ms"; } } public override string shortcut { get { return "ms"; } }
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.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdMeasure() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (message.IndexOf(' ') != -1) { Help(p); return; } if (message.IndexOf(' ') != -1) { Help(p); return; }
CatchPos cpos = default(CatchPos);
if (message != "") {
cpos.toIgnore = Block.Byte(message);
if (cpos.toIgnore == Block.Zero) {
Player.SendMessage(p, "Could not find block specified"); return;
}
}
CatchPos cpos; p.blockchangeObject = cpos;
cpos.toIgnore = Block.Byte(message);
if (cpos.toIgnore == Block.Zero && message != "") { Player.SendMessage(p, "Could not find block specified"); return; }
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
Player.SendMessage(p, "Place two blocks to determine the edges."); Player.SendMessage(p, "Place two blocks to determine the edges.");
p.ClearBlockchange(); p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
public override void Help(Player p)
{ void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
Player.SendMessage(p, "/measure [ignore] - Measures all the blocks between two points");
Player.SendMessage(p, "/measure [ignore] - Enter a block to ignore them");
}
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
{
RevertAndClearState(p, x, y, z); RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject; CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
} }
public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
{ void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z); RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject; CatchPos cpos = (CatchPos)p.blockchangeObject;
ushort minX = Math.Min(cpos.x, x), maxX = Math.Max(cpos.x, x);
ushort minY = Math.Min(cpos.y, y), maxY = Math.Max(cpos.y, y);
ushort minZ = Math.Min(cpos.z, z), maxZ = Math.Max(cpos.z, z);
int foundBlocks = 0;
ushort xx, yy, zz; int foundBlocks = 0; for (ushort yy = minY; yy <= maxY; yy++)
for (ushort zz = minZ; zz <= maxZ; zz++)
for (ushort xx = minX; xx <= maxX; xx++)
{
if (p.level.GetTile(xx, yy, zz) != cpos.toIgnore) foundBlocks++;
}
for (xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx) int width = maxX - minX + 1, height = maxY - minY + 1, length = maxZ - minZ + 1;
for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy) Player.SendMessage(p, "Measuring between (" + minX + ", " + minY + ", " + minZ +
for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz) ") and (" + maxX + ", " + maxY + ", " + maxZ + ")");
{ Player.SendMessage(p, "Area is " + width + " wide, " + height + " high, " + length + " long." +
if (p.level.GetTile(xx, yy, zz) != cpos.toIgnore) foundBlocks++; " Volume is " + (width * height * length) + " blocks." );
} string name = " non-" + Block.Name(cpos.toIgnore);
Player.SendMessage(p, "There are " + foundBlocks + name + " blocks in the area.");
Player.SendMessage(p, foundBlocks + " blocks are between (" + cpos.x + ", " + cpos.y + ", " + cpos.z + ") and (" + x + ", " + y + ", " + z + ")");
if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
} }
struct CatchPos
{ struct CatchPos { public ushort x, y, z; public byte toIgnore; }
public ushort x, y, z; public byte toIgnore;
public override void Help(Player p) {
Player.SendMessage(p, "%T/measure [ignore]");
Player.SendMessage(p, "%HMeasures all the blocks between two points");
Player.SendMessage(p, "%H [ignore] is optional, and specifies the block which is not counted.");
} }
} }
} }

View File

@ -60,14 +60,14 @@ namespace MCGalaxy.Commands {
string banner = p == null ? "(console)" : p.FullName; string banner = p == null ? "(console)" : p.FullName;
string banMsg = null; string banMsg = null;
if (who == null) { if (who == null) {
banMsg = target + " &f(offline)" + " %Swas &8banned" + Server.DefaultColor + " by " + banner + "%S." + banReason; banMsg = target + " &f(offline) %Swas &8banned %Sby " + banner + "%S." + banReason;
Player.GlobalMessage(banMsg); Player.GlobalMessage(banMsg);
} else { } else {
if (stealth) { if (stealth) {
banMsg = who.FullName + " %Swas STEALTH &8banned" + Server.DefaultColor + " by " + banner + "%S." + banReason; banMsg = who.FullName + " %Swas STEALTH &8banned %Sby " + banner + "%S." + banReason;
Chat.GlobalMessageOps(banMsg); Chat.GlobalMessageOps(banMsg);
} else { } else {
banMsg = who.FullName + " %Swas &8banned" + Server.DefaultColor + " by " + banner + "%S." + banReason; banMsg = who.FullName + " %Swas &8banned %Sby " + banner + "%S." + banReason;
Player.GlobalMessage(banMsg); Player.GlobalMessage(banMsg);
} }

View File

@ -52,7 +52,7 @@ namespace MCGalaxy.Commands
if (grp.Permission == LevelPermission.Banned) if (grp.Permission == LevelPermission.Banned)
{ {
string banner = p == null ? "console" : p.color + p.DisplayName + Server.DefaultColor; string banner = p == null ? "console" : p.color + p.DisplayName + Server.DefaultColor;
Player.GlobalMessage(plr.color + plr.name + Server.DefaultColor + " was &8banned" + Server.DefaultColor + " by " + banner + "."); Player.GlobalMessage(plr.FullName + " %Swas &8banned" + " %Sby " + banner + ".");
} }
else else
{ {