Skip to content

Commit

Permalink
Fixed null exception and changed the load method
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal78900 committed Aug 6, 2021
1 parent 8594d6d commit 6538060
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
10 changes: 7 additions & 3 deletions MapEditorReborn/Commands/UtilityCommands/Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ public bool Execute(ArraySegment<string> 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<MapSchematic>(File.ReadAllText(path));
// Handler.CurrentLoadedMap = Loader.Deserializer.Deserialize<MapSchematic>(File.ReadAllText(path));
Handler.CurrentLoadedMap = map;

response = $"You've successfully loaded map named {arguments.At(0)}!";
return true;
Expand Down
3 changes: 2 additions & 1 deletion MapEditorReborn/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ internal static void OnGenerated()
else
{
CurrentLoadedMap = null;
return;
}

if (!(bool)CurrentLoadedMap?.RemoveDefaultSpawnPoints)
if (!CurrentLoadedMap.RemoveDefaultSpawnPoints)
return;

List<string> spawnPointTags = new List<string>()
Expand Down
18 changes: 9 additions & 9 deletions MapEditorReborn/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, () =>
{
Expand Down
2 changes: 1 addition & 1 deletion MapEditorReborn/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override void OnDisabled()
public override string Author => "Michal78900 (original idea by Killers0992)";

/// <inheritdoc/>
public override Version Version => new Version(0, 2, 0);
public override Version Version => new Version(0, 3, 0);

/// <inheritdoc/>
public override Version RequiredExiledVersion => new Version(2, 11, 1);
Expand Down

0 comments on commit 6538060

Please sign in to comment.