public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            p.SendBlockchange(x, y, z, p.level.GetTile(x, y, z));
            CatchPos cpos = (CatchPos)p.blockchangeObject;

            if (cpos.mode == 2)
            {
                cpos.x = x; cpos.y = y; cpos.z = z;
                p.blockchangeObject = cpos;
                p.Blockchange      += new Player.BlockchangeEventHandler(Blockchange2);
                return;
            }

            LavaSurvival.MapSettings settings = Server.lava.LoadMapSettings(p.level.name);
            if (cpos.mode == 0)
            {
                settings.blockFlood = new LavaSurvival.Pos(x, y, z);
            }
            if (cpos.mode == 1)
            {
                settings.blockLayer = new LavaSurvival.Pos(x, y, z);
            }
            Server.lava.SaveMapSettings(settings);

            Player.SendMessage(p, String.Format("Position set! &b({0}, {1}, {2})", x, y, z));
        }
        public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            p.SendBlockchange(x, y, z, p.level.GetTile(x, y, z));
            CatchPos cpos = (CatchPos)p.blockchangeObject;

            if (cpos.mode == 2)
            {
                ushort sx = Math.Min(cpos.x, x);
                ushort ex = Math.Max(cpos.x, x);
                ushort sy = Math.Min(cpos.y, y);
                ushort ey = Math.Max(cpos.y, y);
                ushort sz = Math.Min(cpos.z, z);
                ushort ez = Math.Max(cpos.z, z);

                LavaSurvival.MapSettings settings = Server.lava.LoadMapSettings(p.level.name);
                settings.safeZone = new LavaSurvival.Pos[] { new LavaSurvival.Pos(sx, sy, sz), new LavaSurvival.Pos(ex, ey, ez) };
                Server.lava.SaveMapSettings(settings);

                Player.SendMessage(p, String.Format("Safe zone set! &b({0}, {1}, {2}) ({3}, {4}, {5})", sx, sy, sz, ex, ey, ez));
            }
        }
        public override void Use(Player p, string message)
        {
            if (String.IsNullOrEmpty(message))
            {
                Help(p); return;
            }
            string[] s = message.ToLower().Split(' ');
            if (p == null && (s[0] == "go" || s[0] == "setup"))
            {
                Player.SendMessage(p, "The \"" + s[0] + "\" command can only be used in-game!"); return;
            }

            if (s[0] == "go")
            {
                if (!Server.lava.active)
                {
                    Player.SendMessage(p, "There is no Lava Survival game right now."); return;
                }
                Command.all.Find("goto").Use(p, Server.lava.map.name);
                return;
            }
            if (s[0] == "info")
            {
                if (!Server.lava.active)
                {
                    Player.SendMessage(p, "There is no Lava Survival game right now."); return;
                }
                if (!Server.lava.roundActive)
                {
                    Player.SendMessage(p, "The round of Lava Survival hasn't started yet."); return;
                }
                Server.lava.AnnounceRoundInfo(p, p == null);
                Server.lava.AnnounceTimeLeft(!Server.lava.flooded, true, p, p == null);
                return;
            }
            if (p == null || p.group.Permission >= Server.lava.controlRank)
            {
                if (s[0] == "start")
                {
                    switch (Server.lava.Start(s.Length > 1 ? s[1] : ""))
                    {
                    case 0:
                        Player.GlobalMessage("Lava Survival has started! Join the fun with /ls go");
                        return;

                    case 1:
                        Player.SendMessage(p, "There is already an active Lava Survival game.");
                        return;

                    case 2:
                        Player.SendMessage(p, "You must have at least 3 configured maps to play Lava Survival.");
                        return;

                    case 3:
                        Player.SendMessage(p, "The specified map doesn't exist.");
                        return;

                    default:
                        Player.SendMessage(p, "An unknown error occurred.");
                        return;
                    }
                }
                if (s[0] == "stop")
                {
                    switch (Server.lava.Stop())
                    {
                    case 0:
                        Player.GlobalMessage("Lava Survival has ended! We hope you had fun!");
                        return;

                    case 1:
                        Player.SendMessage(p, "There isn't an active Lava Survival game.");
                        return;

                    default:
                        Player.SendMessage(p, "An unknown error occurred.");
                        return;
                    }
                }
                if (s[0] == "end")
                {
                    if (!Server.lava.active)
                    {
                        Player.SendMessage(p, "There isn't an active Lava Survival game."); return;
                    }
                    if (Server.lava.roundActive)
                    {
                        Server.lava.EndRound();
                    }
                    else if (Server.lava.voteActive)
                    {
                        Server.lava.EndVote();
                    }
                    else
                    {
                        Player.SendMessage(p, "There isn't an active round or vote to end.");
                    }
                    return;
                }
            }
            if (p == null || p.group.Permission >= Server.lava.setupRank)
            {
                if (s[0] == "setup")
                {
                    if (s.Length < 2)
                    {
                        SetupHelp(p); return;
                    }
                    if (Server.lava.active)
                    {
                        Player.SendMessage(p, "You cannot configure Lava Survival while a game is active."); return;
                    }
                    if (s[1] == "map")
                    {
                        if (s.Length < 3)
                        {
                            SetupHelp(p, "map"); return;
                        }
                        Level foundLevel = Level.Find(s[2]);
                        if (foundLevel == null)
                        {
                            Player.SendMessage(p, "The level must be loaded to add/remove it.");
                            return;
                        }
                        else
                        {
                            if (foundLevel == Server.mainLevel)
                            {
                                Player.SendMessage(p, "You cannot use the main map for Lava Survival."); return;
                            }
                            if (Server.lava.HasMap(foundLevel.name))
                            {
                                Server.lava.RemoveMap(foundLevel.name);
                                foundLevel.motd       = "ignore";
                                foundLevel.overload   = 1500;
                                foundLevel.unload     = true;
                                foundLevel.loadOnGoto = true;
                                Level.SaveSettings(foundLevel);
                                Player.SendMessage(p, "Map \"" + foundLevel.name + "\" has been removed.");
                                return;
                            }
                            else
                            {
                                Server.lava.AddMap(foundLevel.name);

                                LavaSurvival.MapSettings settings = Server.lava.LoadMapSettings(foundLevel.name);
                                settings.blockFlood = new LavaSurvival.Pos((ushort)(foundLevel.width / 2), (ushort)(foundLevel.depth - 1), (ushort)(foundLevel.height / 2));
                                settings.blockLayer = new LavaSurvival.Pos(0, (ushort)(foundLevel.depth / 2), 0);
                                ushort x = (ushort)(foundLevel.width / 2), y = (ushort)(foundLevel.depth / 2), z = (ushort)(foundLevel.height / 2);
                                settings.safeZone = new LavaSurvival.Pos[] { new LavaSurvival.Pos((ushort)(x - 3), y, (ushort)(z - 3)), new LavaSurvival.Pos((ushort)(x + 3), (ushort)(y + 4), (ushort)(z + 3)) };
                                Server.lava.SaveMapSettings(settings);

                                foundLevel.motd       = "Lava Survival: " + foundLevel.name.Capitalize();
                                foundLevel.overload   = 1000000;
                                foundLevel.unload     = false;
                                foundLevel.loadOnGoto = false;
                                Level.SaveSettings(foundLevel);
                                Player.SendMessage(p, "Map \"" + foundLevel.name + "\" has been added.");
                                return;
                            }
                        }
                    }
                    if (s[1] == "block")
                    {
                        if (!Server.lava.HasMap(p.level.name))
                        {
                            Player.SendMessage(p, "Add the map before configuring it."); return;
                        }
                        if (s.Length < 3)
                        {
                            SetupHelp(p, "block"); return;
                        }

                        if (s[2] == "flood")
                        {
                            Player.SendMessage(p, "Place or destroy the block you want to be the total flood block spawn point.");
                            CatchPos cpos; cpos.mode = 0;
                            cpos.x = 0; cpos.y = 0; cpos.z = 0;
                            p.blockchangeObject = cpos;
                            p.ClearBlockchange();
                            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
                            return;
                        }
                        if (s[2] == "layer")
                        {
                            Player.SendMessage(p, "Place or destroy the block you want to be the layer flood base spawn point.");
                            CatchPos cpos; cpos.mode = 1;
                            cpos.x = 0; cpos.y = 0; cpos.z = 0;
                            p.blockchangeObject = cpos;
                            p.ClearBlockchange();
                            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
                            return;
                        }

                        SetupHelp(p, "block");
                        return;
                    }
                    if (s[1] == "safezone" || s[1] == "safe")
                    {
                        Player.SendMessage(p, "Place two blocks to determine the edges.");
                        CatchPos cpos; cpos.mode = 2;
                        cpos.x = 0; cpos.y = 0; cpos.z = 0;
                        p.blockchangeObject = cpos;
                        p.ClearBlockchange();
                        p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
                        return;
                    }
                    if (s[1] == "settings")
                    {
                        if (s.Length < 3)
                        {
                            Player.SendMessage(p, "Maps: &b" + Server.lava.Maps.Concatenate(", "));
                            Player.SendMessage(p, "Setup rank: " + Group.findPerm(Server.lava.setupRank).color + Group.findPerm(Server.lava.setupRank).trueName);
                            Player.SendMessage(p, "Control rank: " + Group.findPerm(Server.lava.controlRank).color + Group.findPerm(Server.lava.controlRank).trueName);
                            Player.SendMessage(p, "Start on server startup: " + (Server.lava.startOnStartup ? "&aON" : "&cOFF"));
                            Player.SendMessage(p, "Send AFK to main: " + (Server.lava.sendAfkMain ? "&aON" : "&cOFF"));
                            Player.SendMessage(p, "Vote count: &b" + Server.lava.voteCount);
                            Player.SendMessage(p, "Vote time: &b" + Server.lava.voteTime + " minute" + (Server.lava.voteTime == 1 ? "" : "s"));
                            return;
                        }

                        try
                        {
                            switch (s[2])
                            {
                            case "sendafkmain":
                                Server.lava.sendAfkMain = !Server.lava.sendAfkMain;
                                Player.SendMessage(p, "Send AFK to main: " + (Server.lava.sendAfkMain ? "&aON" : "&cOFF"));
                                break;

                            case "votecount":
                                Server.lava.voteCount = (byte)MathHelper.Clamp(decimal.Parse(s[3]), 2, 10);
                                Player.SendMessage(p, "Vote count: &b" + Server.lava.voteCount);
                                break;

                            case "votetime":
                                Server.lava.voteTime = double.Parse(s[3]);
                                Player.SendMessage(p, "Vote time: &b" + Server.lava.voteTime + "minute" + (Server.lava.voteTime == 1 ? "" : "s"));
                                break;

                            default:
                                SetupHelp(p, "settings");
                                return;
                            }
                            Server.lava.SaveSettings();
                            return;
                        }
                        catch { Player.SendMessage(p, "INVALID INPUT"); return; }
                    }
                    if (s[1] == "mapsettings")
                    {
                        if (!Server.lava.HasMap(p.level.name))
                        {
                            Player.SendMessage(p, "Add the map before configuring it."); return;
                        }
                        LavaSurvival.MapSettings settings = Server.lava.LoadMapSettings(p.level.name);
                        if (s.Length < 4)
                        {
                            Player.SendMessage(p, "Fast lava chance: &b" + settings.fast + "%");
                            Player.SendMessage(p, "Killer lava/water chance: &b" + settings.killer + "%");
                            Player.SendMessage(p, "Destroy blocks chance: &b" + settings.destroy + "%");
                            Player.SendMessage(p, "Water flood chance: &b" + settings.water + "%");
                            Player.SendMessage(p, "Layer flood chance: &b" + settings.layer + "%");
                            Player.SendMessage(p, "Layer height: &b" + settings.layerHeight + " block" + (settings.layerHeight == 1 ? "" : "s"));
                            Player.SendMessage(p, "Layer count: &b" + settings.layerCount);
                            Player.SendMessage(p, "Layer time: &b" + settings.layerInterval + " minute" + (settings.layerInterval == 1 ? "" : "s"));
                            Player.SendMessage(p, "Round time: &b" + settings.roundTime + " minute" + (settings.roundTime == 1 ? "" : "s"));
                            Player.SendMessage(p, "Flood time: &b" + settings.floodTime + " minute" + (settings.floodTime == 1 ? "" : "s"));
                            Player.SendMessage(p, "Flood position: &b" + settings.blockFlood.ToString(", "));
                            Player.SendMessage(p, "Layer position: &b" + settings.blockLayer.ToString(", "));
                            Player.SendMessage(p, String.Format("Safe zone: &b({0}) ({1})", settings.safeZone[0].ToString(", "), settings.safeZone[1].ToString(", ")));
                            return;
                        }

                        try
                        {
                            switch (s[2])
                            {
                            case "fast":
                                settings.fast = (byte)MathHelper.Clamp(decimal.Parse(s[3]), 0, 100);
                                Player.SendMessage(p, "Fast lava chance: &b" + settings.fast + "%");
                                break;

                            case "killer":
                                settings.killer = (byte)MathHelper.Clamp(decimal.Parse(s[3]), 0, 100);
                                Player.SendMessage(p, "Killer lava/water chance: &b" + settings.killer + "%");
                                break;

                            case "destroy":
                                settings.destroy = (byte)MathHelper.Clamp(decimal.Parse(s[3]), 0, 100);
                                Player.SendMessage(p, "Destroy blocks chance: &b" + settings.destroy + "%");
                                break;

                            case "water":
                                settings.water = (byte)MathHelper.Clamp(decimal.Parse(s[3]), 0, 100);
                                Player.SendMessage(p, "Water flood chance: &b" + settings.water + "%");
                                break;

                            case "layer":
                                settings.layer = (byte)MathHelper.Clamp(decimal.Parse(s[3]), 0, 100);
                                Player.SendMessage(p, "Layer flood chance: &b" + settings.layer + "%");
                                break;

                            case "layerheight":
                                settings.layerHeight = int.Parse(s[3]);
                                Player.SendMessage(p, "Layer height: &b" + settings.layerHeight + " block" + (settings.layerHeight == 1 ? "" : "s"));
                                break;

                            case "layercount":
                                settings.layerCount = int.Parse(s[3]);
                                Player.SendMessage(p, "Layer count: &b" + settings.layerCount);
                                break;

                            case "layertime":
                                settings.layerInterval = double.Parse(s[3]);
                                Player.SendMessage(p, "Layer time: &b" + settings.layerInterval + " minute" + (settings.layerInterval == 1 ? "" : "s"));
                                break;

                            case "roundtime":
                                settings.roundTime = double.Parse(s[3]);
                                Player.SendMessage(p, "Round time: &b" + settings.roundTime + " minute" + (settings.roundTime == 1 ? "" : "s"));
                                break;

                            case "floodtime":
                                settings.floodTime = double.Parse(s[3]);
                                Player.SendMessage(p, "Flood time: &b" + settings.floodTime + " minute" + (settings.floodTime == 1 ? "" : "s"));
                                break;

                            default:
                                SetupHelp(p, "mapsettings");
                                return;
                            }
                        }
                        catch { Player.SendMessage(p, "INVALID INPUT"); return; }
                        Server.lava.SaveMapSettings(settings);
                        return;
                    }
                }
            }

            Help(p);
        }