diff --git a/MapEditorReborn/Commands/UtilityCommands/Load.cs b/MapEditorReborn/Commands/UtilityCommands/Load.cs index de57203a..30464a5d 100644 --- a/MapEditorReborn/Commands/UtilityCommands/Load.cs +++ b/MapEditorReborn/Commands/UtilityCommands/Load.cs @@ -36,15 +36,19 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s return false; } - string path = Path.Combine(MapEditorReborn.PluginDir, $"{arguments.At(0)}.yml"); + MapSchematic map = Handler.GetMapByName(arguments.At(0)); - if (!File.Exists(path)) + // string path = Path.Combine(MapEditorReborn.PluginDir, $"{arguments.At(0)}.yml"); + + // if (!File.Exists(path)) + if (map == null) { response = $"MapSchematic with this name does not exist!"; return false; } - Handler.CurrentLoadedMap = Loader.Deserializer.Deserialize(File.ReadAllText(path)); + // Handler.CurrentLoadedMap = Loader.Deserializer.Deserialize(File.ReadAllText(path)); + Handler.CurrentLoadedMap = map; response = $"You've successfully loaded map named {arguments.At(0)}!"; return true; diff --git a/MapEditorReborn/Handler.cs b/MapEditorReborn/Handler.cs index 2e2257df..c512c536 100644 --- a/MapEditorReborn/Handler.cs +++ b/MapEditorReborn/Handler.cs @@ -109,9 +109,10 @@ internal static void OnGenerated() else { CurrentLoadedMap = null; + return; } - if (!(bool)CurrentLoadedMap?.RemoveDefaultSpawnPoints) + if (!CurrentLoadedMap.RemoveDefaultSpawnPoints) return; List spawnPointTags = new List() diff --git a/MapEditorReborn/Methods.cs b/MapEditorReborn/Methods.cs index 6172dd36..d5b61c9a 100644 --- a/MapEditorReborn/Methods.cs +++ b/MapEditorReborn/Methods.cs @@ -36,15 +36,6 @@ public static void LoadMap(MapSchematic map) { Log.Debug("Trying to load the map...", Config.Debug); - if (!Server.Host.SessionVariables.ContainsKey(RemoveDefaultSpawnPointsVarName)) - { - Server.Host.SessionVariables.Add(RemoveDefaultSpawnPointsVarName, map.RemoveDefaultSpawnPoints); - } - else - { - Server.Host.SessionVariables[RemoveDefaultSpawnPointsVarName] = map.RemoveDefaultSpawnPoints; - } - foreach (GameObject spawnedObj in SpawnedObjects) { // NetworkServer.Destroy(spawnedObj) doesn't call OnDestroy methods in components for some reason. @@ -68,6 +59,15 @@ public static void LoadMap(MapSchematic map) return; } + if (!Server.Host.SessionVariables.ContainsKey(RemoveDefaultSpawnPointsVarName)) + { + Server.Host.SessionVariables.Add(RemoveDefaultSpawnPointsVarName, map.RemoveDefaultSpawnPoints); + } + else + { + Server.Host.SessionVariables[RemoveDefaultSpawnPointsVarName] = map.RemoveDefaultSpawnPoints; + } + // Map.Rooms is null at this time, so this delay is required. Timing.CallDelayed(0.01f, () => { diff --git a/MapEditorReborn/Plugin.cs b/MapEditorReborn/Plugin.cs index 57401a30..f05942dc 100644 --- a/MapEditorReborn/Plugin.cs +++ b/MapEditorReborn/Plugin.cs @@ -86,7 +86,7 @@ public override void OnDisabled() public override string Author => "Michal78900 (original idea by Killers0992)"; /// - public override Version Version => new Version(0, 2, 0); + public override Version Version => new Version(0, 3, 0); /// public override Version RequiredExiledVersion => new Version(2, 11, 1);