<commit_before>﻿using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Utility;

namespace Content.Server.Commands.GameTicking
{
    [AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
    class MappingCommand : IClientCommand
    {
        public string Command => "mapping";
        public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
        public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";

        public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "Only players can use this command");
                return;
            }

            var mapManager = IoCManager.Resolve<IMapManager>();
            int mapId;
            string mapName;

            switch (args.Length)
            {
                case 1:
                    if (player.AttachedEntity == null)
                    {
                        shell.SendText(player, "The map name argument cannot be omitted if you have no entity.");
                        return;
                    }

                    mapId = (int) mapManager.NextMapId();
                    mapName = args[0];
                    break;
                case 2:
                    if (!int.TryParse(args[0], out var id))
                    {
                        shell.SendText(player, $"{args[0]} is not a valid integer.");
                        return;
                    }

                    mapId = id;
                    mapName = args[1];
                    break;
                default:
                    shell.SendText(player, Help);
                    return;
            }

            shell.ExecuteCommand(player, $"addmap {mapId} false");
            shell.ExecuteCommand(player, $"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\"");
            shell.ExecuteCommand(player, "aghost");
            shell.ExecuteCommand(player, $"tp 0 0 {mapId}");

            var newGrid = mapManager.GetAllGrids().OrderByDescending(g => (int) g.Index).First();
            var pauseManager = IoCManager.Resolve<IPauseManager>();

            pauseManager.SetMapPaused(newGrid.ParentMapId, true);

            shell.SendText(player, $"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
        }
    }
}<commit_msg>Add support for map UID persistence to mapping commands.<commit_after>﻿using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Utility;

namespace Content.Server.Commands.GameTicking
{
    [AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
    class MappingCommand : IClientCommand
    {
        public string Command => "mapping";
        public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
        public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";

        public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "Only players can use this command");
                return;
            }

            var mapManager = IoCManager.Resolve<IMapManager>();
            int mapId;
            string mapName;

            switch (args.Length)
            {
                case 1:
                    if (player.AttachedEntity == null)
                    {
                        shell.SendText(player, "The map name argument cannot be omitted if you have no entity.");
                        return;
                    }

                    mapId = (int) mapManager.NextMapId();
                    mapName = args[0];
                    break;
                case 2:
                    if (!int.TryParse(args[0], out var id))
                    {
                        shell.SendText(player, $"{args[0]} is not a valid integer.");
                        return;
                    }

                    mapId = id;
                    mapName = args[1];
                    break;
                default:
                    shell.SendText(player, Help);
                    return;
            }

            shell.ExecuteCommand(player, $"addmap {mapId} false");
            shell.ExecuteCommand(player, $"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true");
            shell.ExecuteCommand(player, "aghost");
            shell.ExecuteCommand(player, $"tp 0 0 {mapId}");

            var newGrid = mapManager.GetAllGrids().OrderByDescending(g => (int) g.Index).First();
            var pauseManager = IoCManager.Resolve<IPauseManager>();

            pauseManager.SetMapPaused(newGrid.ParentMapId, true);

            shell.SendText(player, $"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
        }
    }
}
{'fraction_non_alphanumeric': 0.10293577981651376, 'fraction_numerical': 0.0029357798165137615, 'mean_word_length': 1.7132901941264311, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672014', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1379, 'n_words': 363}