Пример #1
0
        ParseParams(List <string> parameters, CommandSenderInfo senderInfo)
        {
            // Parse /all parameter
            var all = parameters.Remove("/all");

            if (parameters.Count == 0)
            {
                throw new FriendlyMessageException(Resources.ErrorParameerCountNotValid);
            }

            // Parse prefab name
            var prefabName = parameters[0];

            // Verify existence of prefab files
            const string tts = global::Constants.cExtPrefabs; // Cannot interpolate in string: https://youtrack.jetbrains.com/issue/RSRP-465524

            if (!File.Exists(Path.Combine(Constants.PrefabsFolder, prefabName + ".xml")) ||
                !File.Exists(Path.Combine(Constants.PrefabsFolder, prefabName + tts)))
            {
                throw new FriendlyMessageException($"Could not find {prefabName}.xml/{tts} in {Constants.PrefabsFolder}.");
            }

            // Verify existence and validity of tile entity file
            if (all)
            {
                var fileName = prefabName + Export.TileEntityFileExtension;
                var filePath = Path.Combine(Constants.PrefabsFolder, fileName);
                if (!File.Exists(filePath))
                {
                    throw new FriendlyMessageException($"Could not find {fileName} in prefabs folder. This prefab does not have block metadata available, so you cannot use the /all option.");
                }
            }

            // Parse coordinates
            Vector3i pos1;

            if (parameters.Count == 1 || parameters.Count == 2)
            {
                pos1 = senderInfo.GetRemoteClientInfo().GetEntityPlayer().GetServerPos().ToVector3i();
            }
            else if (parameters.Count == 4 || parameters.Count == 5)
            {
                pos1 = CommandTools.ParseXYZ(parameters, 1);
            }
            else
            {
                throw new FriendlyMessageException(Resources.ErrorParameerCountNotValid);
            }

            // Parse rotation
            var rotate = 0;

            if (parameters.Count == 2 || parameters.Count == 5)
            {
                rotate = parameters[parameters.Count - 1].ToInt()
                         ?? throw new FriendlyMessageException("Rotation value is not valid. Allowed values: 0, 1, 2, or 3");
            }

            return(prefabName, pos1, rotate, all);
        }
Пример #2
0
        private static (string prefabName, Vector3i pos1, Vector3i pos2) ParseParams(List <string> parameters, CommandSenderInfo senderInfo)
        {
            if (parameters.Count == 0)
            {
                var ci = senderInfo.GetRemoteClientInfo();
                savedPos[ci.entityId] = ci.GetEntityPlayer().GetServerPos().ToVector3i();
                throw new FriendlyMessageException("Your current position was saved: " + savedPos[ci.entityId]);
            }

            var prefabName = parameters[0];

            // Sanatize prefabName to only include allowed characters
            if (!Regex.IsMatch(prefabName, @"^\w[\w.-]*$", RegexOptions.CultureInvariant))
            {
                throw new FriendlyMessageException("The prefix name contains illegal characters. Please use only letters, numbers, dash, and underscore.");
            }

            Vector3i pos1, pos2;

            if (parameters.Count == 1)
            {
                var ci = senderInfo.GetRemoteClientInfo();
                if (!savedPos.ContainsKey(ci.entityId))
                {
                    throw new FriendlyMessageException("Please save start point of the area first. See help for details.");
                }
                pos1 = savedPos[ci.entityId];
                pos2 = ci.GetEntityPlayer().GetServerPos().ToVector3i();
            }
            else if (parameters.Count == 7)
            {
                pos1 = CommandTools.ParseXYZ(parameters, 1);
                pos2 = CommandTools.ParseXYZ(parameters, 4);
            }
            else
            {
                throw new FriendlyMessageException(Resources.ErrorParameerCountNotValid);
            }

            return(prefabName, pos1, pos2);
        }