Fix unloading custom commands not removing command aliases

This commit is contained in:
UnknownShadow200 2020-03-30 18:00:32 +11:00
parent 89221b1110
commit 59b86d578d
2 changed files with 21 additions and 9 deletions

View File

@ -85,5 +85,21 @@ namespace MCGalaxy.Commands {
} }
return null; return null;
} }
/// <summary> Registers default aliases specified by a command. </summary>
internal static void RegisterDefaults(Command cmd) {
CommandAlias[] aliases = cmd.Aliases;
if (aliases == null) return;
foreach (CommandAlias a in aliases) {
Alias alias = new Alias(a.Trigger, cmd.name, a.Format);
coreAliases.Add(alias);
}
}
internal static void UnregisterDefaults(Command cmd) {
if (cmd.Aliases == null) return;
coreAliases.RemoveAll(a => a.Target == cmd.name);
}
} }
} }

View File

@ -87,14 +87,8 @@ namespace MCGalaxy {
CommandExtraPerms.Set(cmd.name, i + 1, extra[i].Description, CommandExtraPerms.Set(cmd.name, i + 1, extra[i].Description,
extra[i].Perm, null, null); extra[i].Perm, null, null);
} }
} }
Alias.RegisterDefaults(cmd);
CommandAlias[] aliases = cmd.Aliases;
if (aliases == null) return;
foreach (CommandAlias a in aliases) {
Alias alias = new Alias(a.Trigger, cmd.name, a.Format);
Alias.coreAliases.Add(alias);
}
} }
public static Command Find(string name) { public static Command Find(string name) {
@ -109,6 +103,8 @@ namespace MCGalaxy {
foreach (Group grp in Group.GroupList) { foreach (Group grp in Group.GroupList) {
grp.Commands.Remove(cmd); grp.Commands.Remove(cmd);
} }
Alias.UnregisterDefaults(cmd);
return removed; return removed;
} }
@ -148,7 +144,7 @@ namespace MCGalaxy {
} }
// Clunky design, but needed to stay backwards compatible with custom commands // Clunky design, but needed to stay backwards compatible with custom commands
public abstract class Command2 : Command { public abstract class Command2 : Command {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
if (p == null) p = Player.Console; if (p == null) p = Player.Console;
Use(p, message, p.DefaultCmdData); Use(p, message, p.DefaultCmdData);