mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Fix ZS not working properly when the level it is unloaded.
This commit is contained in:
parent
74a1d13650
commit
1b4a1c854d
@ -39,7 +39,8 @@ namespace MCGalaxy.Commands.World {
|
||||
if (!LevelInfo.ValidateAction(p, map, "delete this level")) return;
|
||||
|
||||
Player.Message(p, "Created backup.");
|
||||
LevelActions.Delete(map.ToLower());
|
||||
if (LevelActions.Delete(map)) return;
|
||||
Player.Message(p, LevelActions.DeleteFailedMessage);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -25,8 +25,8 @@ namespace MCGalaxy.Commands.World {
|
||||
public override string type { get { return CommandTypes.World; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new[] { new CommandAlias("j"), new CommandAlias("Join"),
|
||||
new CommandAlias("gr", "-random"), new CommandAlias("GotoRandom", "-random") }; }
|
||||
get { return new[] { new CommandAlias("j"), new CommandAlias("Join"), new CommandAlias("gr", "-random"),
|
||||
new CommandAlias("GotoRandom", "-random"), new CommandAlias("JoinRandom", "-random") }; }
|
||||
}
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
|
@ -200,8 +200,11 @@ namespace MCGalaxy.Commands.World {
|
||||
if (!OwnsMap(p, p.level)) return;
|
||||
|
||||
Player.Message(p, "Created backup.");
|
||||
LevelActions.Delete(map);
|
||||
Player.Message(p, "Map " + map + " was removed.");
|
||||
if (LevelActions.Delete(map)) {
|
||||
Player.Message(p, "Map " + map + " was removed.");
|
||||
} else {
|
||||
Player.Message(p, LevelActions.DeleteFailedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
using System;
|
||||
using MCGalaxy.Events.EconomyEvents;
|
||||
using MCGalaxy.Events.EntityEvents;
|
||||
using MCGalaxy.Events.LevelEvents;
|
||||
using MCGalaxy.Events.PlayerEvents;
|
||||
using MCGalaxy.Network;
|
||||
|
||||
@ -39,6 +40,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
OnPlayerActionEvent.Register(HandlePlayerAction, Priority.High);
|
||||
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
|
||||
OnBlockChangeEvent.Register(HandleBlockChange, Priority.High);
|
||||
OnLevelUnloadEvent.Register(HandleLevelUnload, Priority.High);
|
||||
}
|
||||
|
||||
public override void Unload(bool shutdown) {
|
||||
@ -51,6 +53,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
OnPlayerActionEvent.Unregister(HandlePlayerAction);
|
||||
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
|
||||
OnBlockChangeEvent.Unregister(HandleBlockChange);
|
||||
OnLevelUnloadEvent.Unregister(HandleLevelUnload);
|
||||
}
|
||||
|
||||
void HandleTabListEntryAdded(Entity entity, ref string tabName, ref string tabGroup, Player dst) {
|
||||
@ -165,5 +168,9 @@ namespace MCGalaxy.Games.ZS {
|
||||
Player.Message(p, "Blocks Left: &4" + p.Game.BlocksLeft);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleLevelUnload(Level lvl) {
|
||||
if (lvl == Game.Map) lvl.cancelunload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,7 @@ namespace MCGalaxy {
|
||||
|
||||
public static class LevelActions {
|
||||
|
||||
/// <summary> Renames the .lvl (and related) files and database tables.
|
||||
/// Does not perform any unloading. </summary>
|
||||
/// <summary> Renames the .lvl (and related) files and database tables. Does not unload. </summary>
|
||||
public static void Rename(string src, string dst) {
|
||||
File.Move(LevelInfo.MapPath(src), LevelInfo.MapPath(dst));
|
||||
|
||||
@ -108,11 +107,11 @@ namespace MCGalaxy {
|
||||
}*/
|
||||
|
||||
|
||||
/// <summary> Deletes the .lvl (and related) files and database tables.
|
||||
/// Unloads a level (if present) which exactly matches name. </summary>
|
||||
public static void Delete(string name) {
|
||||
public const string DeleteFailedMessage = "Unable to delete the level, because it could not be unloaded. A game may currently be running on it.";
|
||||
/// <summary> Deletes the .lvl (and related) files and database tables. Unloads level if it is loaded. </summary>
|
||||
public static bool Delete(string name) {
|
||||
Level lvl = LevelInfo.FindExact(name);
|
||||
if (lvl != null) lvl.Unload();
|
||||
if (lvl != null && !lvl.Unload()) return false;
|
||||
|
||||
if (!Directory.Exists("levels/deleted"))
|
||||
Directory.CreateDirectory("levels/deleted");
|
||||
@ -135,6 +134,7 @@ namespace MCGalaxy {
|
||||
|
||||
DeleteDatabaseTables(name);
|
||||
BlockDBFile.DeleteBackingFile(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void DeleteDatabaseTables(string name) {
|
||||
|
@ -105,10 +105,6 @@ namespace MCGalaxy {
|
||||
Economy.LoadDatabase();
|
||||
Server.zombie.CheckTableExists();
|
||||
|
||||
Level[] loaded = LevelInfo.Loaded.Items;
|
||||
foreach (Level l in loaded)
|
||||
l.Unload();
|
||||
|
||||
Background.QueueOnce(UpgradeTasks.CombineEnvFiles);
|
||||
Background.QueueOnce(LoadMainLevel);
|
||||
Plugin.Load();
|
||||
|
Loading…
x
Reference in New Issue
Block a user