Page 1 of 1

/numberofblocks (block) - Displays number of (block)s

PostPosted: 29 Mar 2014, 12:07
by Leeizazombie
Hey, I was using this command to debug a mini-game I'm working on, and I thought that it would also be of use for map building! or if you are playing hide the block, you can check if that block even exists in the world.

Syntax: /numberofblocks (block)
Shortcut: /nob (block)

Please be aware that if you enter an invalid block name, it will just say there is 0 of it. (I'll try update that)

Preview:
Spoiler:


Code:
Code: Select all
using System;
using System.Collections.Generic;

namespace MCDzienny
{
    public class CmdNumberOfBlocks : Command
    {
        public override string name { get { return "numberofblocks"; } }
        public override string shortcut { get { return "nob"; } }
        public override string type { get { return "build"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Use(Player p, string message)
        {
            byte b1;
            string blockname = message.Split(' ')[0];
            b1 = Block.Byte(message.Split(' ')[0]);
            ushort x2, y2, z2; int currentBlock = 0;

            if (b1 == null)
            {
                Player.SendMessage(p, "Please enter a valid block type!");
                return;
            }

            List<MCDzienny.Level.Pos> stored = new List<MCDzienny.Level.Pos>(); MCDzienny.Level.Pos pos;

            foreach (byte b in p.level.blocks)
            {
                if (b == b1)
                {
                    p.level.IntToPos(currentBlock, out x2, out y2, out z2);
                    pos.x = x2;
                    pos.z = z2;
                    stored.Add(pos);
                }
                currentBlock++;
            }
            Player.SendMessage(p, "There is: %7" +  stored.Count.ToString() + Server.DefaultColor + " of %7" + blockname + Server.DefaultColor + " blocks in%b " + p.level.name);
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/nob (block) - Shows how many (block) is in the current level.");
        }
    }
}