Пример #1
0
 bool DeleteAll(int player, string command, string argument)
 {
     if (command.Equals("delete_all_tpblocks", StringComparison.InvariantCultureIgnoreCase))
     {
         if (!m.PlayerHasPrivilege(player, "delete_all_tpblocks"))
         {
             m.SendMessage(player, chatPrefix + m.colorError() + "You are not allowed to delete ALL teleport blocks.");
             return(true);
         }
         for (int i = 0; i < number_of_teleport_blocks; i++)
         {
             Vector3i      emptyVector = new Vector3i(-1, -1, -1);
             TeleportBlock block       = tpblocks[i];
             block.target = emptyVector;
             Vector3i tempPos = block.position;
             m.SetBlock(tempPos.x, tempPos.y, tempPos.z, 0);                     //Set Block to "Empty"
             block.position = emptyVector;
             block.isPlaced = false;
             tpblocks[i]    = block;
         }
         m.SendMessage(player, chatPrefix + "&aALL teleport blocks and their targets have been deleted.");
         SaveTargetPositions();
         return(true);
     }
     return(false);
 }
Пример #2
0
        void AddBlock(int player, int x, int y, int z)
        {
            int ID = m.GetBlock(x, y, z);

            if (IsTeleportBlock(ID))
            {
                int           ID2   = ID - blockID_start;
                TeleportBlock block = tpblocks[ID2];
                if (block.isPlaced)                                                 //Check if Block with same ID is already set
                {
                    Vector3i oldPos = block.position;                               //Get position of old block
                    m.SetBlock(oldPos.x, oldPos.y, oldPos.z, 0);                    //Set block at old position to "Empty"
                    block.position = new Vector3i(x, y, z);                         //Save position of new block
                    m.SendMessage(player, chatPrefix + "&aTeleport Block position updated. Old block deleted.");
                }
                else
                {
                    block.position = new Vector3i(x, y, z);                             //Save position of new block
                    block.isPlaced = true;                                              //Set BlockID as used
                }
                tpblocks[ID2] = block;
                if (!IsTargetValid(tpblocks[ID2].target))
                {
                    m.SendMessage(player, chatPrefix + "&6Remember to set a target for this teleport block.");                      //Notify user if there is no target set
                }
                SaveTargetPositions();
            }
        }
Пример #3
0
        bool SetTarget(int player, string command, string argument)
        {
            if (command.Equals("set_tptarget", StringComparison.InvariantCultureIgnoreCase))
            {
                if (!m.PlayerHasPrivilege(player, "set_tptarget"))
                {
                    m.SendMessage(player, chatPrefix + m.colorError() + "You are not allowed to set teleport block targets.");
                    return(true);
                }
                int teleportBlockID, targetX, targetY, targetZ;
                try
                {
                    string[] args = argument.Split(' ');
                    teleportBlockID = int.Parse(args[0]);
                    targetX         = int.Parse(args[1]);
                    targetY         = int.Parse(args[2]);
                    targetZ         = int.Parse(args[3]);
                }
                catch
                {
                    m.SendMessage(player, chatPrefix + m.colorError() + "Invalid arguments. Try /help.");
                    return(true);
                }

                if ((teleportBlockID < number_of_teleport_blocks) && (teleportBlockID >= 0))
                {
                    if (m.IsValidPos(targetX, targetY, targetZ))
                    {
                        TeleportBlock block = tpblocks[teleportBlockID];
                        block.target = new Vector3i(targetX, targetY, targetZ);
                        tpblocks[teleportBlockID] = block;
                        m.SendMessage(player, chatPrefix + "&aSuccesfully set target coordinates:");
                        m.SendMessage(player, chatPrefix + string.Format("&aTeleport Block {0} now teleports to {1}, {2}, {3}", teleportBlockID, targetX, targetY, targetZ));
                        m.LogServerEvent(string.Format("[TeleportBlocks] {0} set Teleport Block {1} target to {2}, {3}, {4}", m.GetPlayerName(player), teleportBlockID, targetX, targetY, targetZ));
                        SaveTargetPositions();
                        return(true);
                    }
                    else
                    {
                        m.SendMessage(player, chatPrefix + m.colorError() + "The coordinates you entered are not valid.");
                        return(true);
                    }
                }
                else
                {
                    m.SendMessage(player, chatPrefix + m.colorError() + "The teleport block ID you entered does not exist.");
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
        void LoadTargetPositions()
        {
            try
            {
                tpblocks.Clear();
                if (!File.Exists("UserData" + Path.DirectorySeparatorChar + "TeleportBlocks.txt"))
                {
                    SaveTargetPositions();
                }
                Console.WriteLine(consolePrefix + "Loading teleport blocks...");
                using (TextReader tr = new StreamReader("UserData" + Path.DirectorySeparatorChar + "TeleportBlocks.txt", System.Text.Encoding.UTF8))
                {
                    string positionString = tr.ReadLine();
                    while (!string.IsNullOrEmpty(positionString))
                    {
                        string[] positionCoords = positionString.Split(';');
                        int      px             = int.Parse(positionCoords[0]);
                        int      py             = int.Parse(positionCoords[1]);
                        int      pz             = int.Parse(positionCoords[2]);

                        string   targetString = tr.ReadLine();
                        string[] targetCoords = targetString.Split(';');
                        int      tx           = int.Parse(targetCoords[0]);
                        int      ty           = int.Parse(targetCoords[1]);
                        int      tz           = int.Parse(targetCoords[2]);

                        bool pl = bool.Parse(tr.ReadLine());

                        TeleportBlock block = new TeleportBlock(new Vector3i(px, py, pz), new Vector3i(tx, ty, tz));
                        block.isPlaced = pl;
                        tpblocks.Add(block);
                        Console.WriteLine(consolePrefix + "Loaded {0}: {1}{2}{3} Target: {4}{5}{6} Placed: {7}", tpblocks.Count - 1, block.position.x, block.position.y, block.position.z, block.target.x, block.target.y, block.target.z, block.isPlaced);

                        positionString = tr.ReadLine();
                    }
                }
                if (number_of_teleport_blocks != tpblocks.Count)
                {
                    Console.WriteLine(consolePrefix + "Error while loading blocks file. Deleted.");
                    File.Delete("UserData" + Path.DirectorySeparatorChar + "TeleportBlocks.txt");
                    LoadTargetPositions();
                }
                Console.WriteLine(consolePrefix + "Successfully loaded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(consolePrefix + "ERROR:  " + ex.Message);
            }
        }
Пример #5
0
 void DeleteBlock(int player, int x, int y, int z, int BlockID)
 {
     if (IsTeleportBlock(BlockID))
     {
         if (!m.PlayerHasPrivilege(player, "delete_tpblocks"))
         {
             m.SetBlock(x, y, z, BlockID);
             m.SendMessage(player, chatPrefix + m.colorError() + "You are not allowed to delete teleport blocks.");
             return;
         }
         int           ID    = BlockID - blockID_start;
         TeleportBlock block = tpblocks[ID];
         block.position = new Vector3i(-1, -1, -1);
         block.target   = new Vector3i(-1, -1, -1);
         block.isPlaced = false;
         tpblocks[ID]   = block;
         m.SendMessage(player, chatPrefix + "&aThe block and its target position have been deleted.");
         SaveTargetPositions();
     }
 }