public static bool CloseDoor(int i, int j, bool forced = false, DoorOpener opener = DoorOpener.SERVER, Sender sender = null)
        {
            if (sender == null)
            {
                ConsoleSender cSender = new ConsoleSender(Program.server);
                cSender.ConsoleCommand.Sender = new Sender();
                sender = cSender;
            }

            DoorStateChangeEvent doorEvent = new DoorStateChangeEvent();
            doorEvent.Sender = sender;
            doorEvent.setVector(new Vector2(i, j));
            doorEvent.setDirection(1);
            doorEvent.setOpener(opener);
            doorEvent.setOpened(forced);
            Program.server.getPluginManager().processHook(Hooks.DOOR_STATECHANGE, doorEvent);
            if (doorEvent.Cancelled)
            {
                return true;
            }
            int num = 0;
            int num2 = i;
            int num3 = j;
            if (Main.tile[i, j] == null)
            {
                Main.tile[i, j] = new Tile();
            }
            int frameX = (int)Main.tile[i, j].frameX;
            int frameY = (int)Main.tile[i, j].frameY;
            if (frameX == 0)
            {
                num2 = i;
                num = 1;
            }
            else
            {
                if (frameX == 18)
                {
                    num2 = i - 1;
                    num = 1;
                }
                else
                {
                    if (frameX == 36)
                    {
                        num2 = i + 1;
                        num = -1;
                    }
                    else
                    {
                        if (frameX == 54)
                        {
                            num2 = i;
                            num = -1;
                        }
                    }
                }
            }
            if (frameY == 0)
            {
                num3 = j;
            }
            else
            {
                if (frameY == 18)
                {
                    num3 = j - 1;
                }
                else
                {
                    if (frameY == 36)
                    {
                        num3 = j - 2;
                    }
                }
            }
            int num4 = num2;
            if (num == -1)
            {
                num4 = num2 - 1;
            }
            if (!forced)
            {
                for (int k = num3; k < num3 + 3; k++)
                {
                    if (!Collision.EmptyTile(num2, k, true))
                    {
                        return false;
                    }
                }
            }
            for (int l = num4; l < num4 + 2; l++)
            {
                for (int m = num3; m < num3 + 3; m++)
                {
                    if (l == num2)
                    {
                        if (Main.tile[l, m] == null)
                        {
                            Main.tile[l, m] = new Tile();
                        }
                        Main.tile[l, m].type = 10;
                        Main.tile[l, m].frameX = (short)(WorldGen.genRand.Next(3) * 18);
                    }
                    else
                    {
                        if (Main.tile[l, m] == null)
                        {
                            Main.tile[l, m] = new Tile();
                        }
                        Main.tile[l, m].Active = false;
                    }
                }
            }
            for (int n = num2 - 1; n <= num2 + 1; n++)
            {
                for (int num5 = num3 - 1; num5 <= num3 + 2; num5++)
                {
                    WorldGen.TileFrame(n, num5, false, false);
                }
            }
            return true;
        }
        public static bool OpenDoor(int i, int j, int direction, bool state = false, DoorOpener opender = DoorOpener.SERVER, Sender sender = null)
        {
            if (sender == null)
            {
                ConsoleSender cSender = new ConsoleSender(Program.server);
                cSender.ConsoleCommand.Sender = new Sender();
                sender = cSender;
            }

            DoorStateChangeEvent doorEvent = new DoorStateChangeEvent();
            doorEvent.Sender = sender;
            doorEvent.setVector(new Vector2(i, j));
            doorEvent.setDirection(direction);
            doorEvent.setOpener(opender);
            doorEvent.setOpened(state);
            Program.server.getPluginManager().processHook(Hooks.DOOR_STATECHANGE, doorEvent);
            if (doorEvent.Cancelled)
            {
                return true;
            }

            int num = 0;
            if (Main.tile[i, j - 1] == null)
            {
                Main.tile[i, j - 1] = new Tile();
            }
            if (Main.tile[i, j - 2] == null)
            {
                Main.tile[i, j - 2] = new Tile();
            }
            if (Main.tile[i, j + 1] == null)
            {
                Main.tile[i, j + 1] = new Tile();
            }
            if (Main.tile[i, j] == null)
            {
                Main.tile[i, j] = new Tile();
            }
            if (Main.tile[i, j - 1].frameY == 0 && Main.tile[i, j - 1].type == Main.tile[i, j].type)
            {
                num = j - 1;
            }
            else
            {
                if (Main.tile[i, j - 2].frameY == 0 && Main.tile[i, j - 2].type == Main.tile[i, j].type)
                {
                    num = j - 2;
                }
                else
                {
                    if (Main.tile[i, j + 1].frameY == 0 && Main.tile[i, j + 1].type == Main.tile[i, j].type)
                    {
                        num = j + 1;
                    }
                    else
                    {
                        num = j;
                    }
                }
            }
            int num2 = i;
            short num3 = 0;
            int num4;
            if (direction == -1)
            {
                num2 = i - 1;
                num3 = 36;
                num4 = i - 1;
            }
            else
            {
                num2 = i;
                num4 = i + 1;
            }
            bool flag = true;
            for (int k = num; k < num + 3; k++)
            {
                if (Main.tile[num4, k] == null)
                {
                    Main.tile[num4, k] = new Tile();
                }
                if (Main.tile[num4, k].Active)
                {
                    if (Main.tile[num4, k].type != 3 && Main.tile[num4, k].type != 24 && Main.tile[num4, k].type != 52 && Main.tile[num4, k].type != 61 && Main.tile[num4, k].type != 62 && Main.tile[num4, k].type != 69 && Main.tile[num4, k].type != 71 && Main.tile[num4, k].type != 73 && Main.tile[num4, k].type != 74)
                    {
                        flag = false;
                        break;
                    }
                    WorldGen.KillTile(num4, k, false, false, false);
                }
            }
            if (flag)
            {
                Main.tile[num2, num].Active = true;
                Main.tile[num2, num].type = 11;
                Main.tile[num2, num].frameY = 0;
                Main.tile[num2, num].frameX = num3;
                if (Main.tile[num2 + 1, num] == null)
                {
                    Main.tile[num2 + 1, num] = new Tile();
                }
                Main.tile[num2 + 1, num].Active = true;
                Main.tile[num2 + 1, num].type = 11;
                Main.tile[num2 + 1, num].frameY = 0;
                Main.tile[num2 + 1, num].frameX = (short)(num3 + 18);
                if (Main.tile[num2, num + 1] == null)
                {
                    Main.tile[num2, num + 1] = new Tile();
                }
                Main.tile[num2, num + 1].Active = true;
                Main.tile[num2, num + 1].type = 11;
                Main.tile[num2, num + 1].frameY = 18;
                Main.tile[num2, num + 1].frameX = num3;
                if (Main.tile[num2 + 1, num + 1] == null)
                {
                    Main.tile[num2 + 1, num + 1] = new Tile();
                }
                Main.tile[num2 + 1, num + 1].Active = true;
                Main.tile[num2 + 1, num + 1].type = 11;
                Main.tile[num2 + 1, num + 1].frameY = 18;
                Main.tile[num2 + 1, num + 1].frameX = (short)(num3 + 18);
                if (Main.tile[num2, num + 2] == null)
                {
                    Main.tile[num2, num + 2] = new Tile();
                }
                Main.tile[num2, num + 2].Active = true;
                Main.tile[num2, num + 2].type = 11;
                Main.tile[num2, num + 2].frameY = 36;
                Main.tile[num2, num + 2].frameX = num3;
                if (Main.tile[num2 + 1, num + 2] == null)
                {
                    Main.tile[num2 + 1, num + 2] = new Tile();
                }
                Main.tile[num2 + 1, num + 2].Active = true;
                Main.tile[num2 + 1, num + 2].type = 11;
                Main.tile[num2 + 1, num + 2].frameY = 36;
                Main.tile[num2 + 1, num + 2].frameX = (short)(num3 + 18);
                for (int l = num2 - 1; l <= num2 + 2; l++)
                {
                    for (int m = num - 1; m <= num + 2; m++)
                    {
                        WorldGen.TileFrame(l, m, false, false);
                    }
                }
            }
            return flag;
        }