From 56e8d45f127facd713b9e0450980ce36d39334d8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 13 Dec 2022 20:08:16 +1100 Subject: [PATCH] Allow built-in commands to not always be autoloaded at startup --- MCGalaxy/Commands/Command.cs | 12 ++++++------ MCGalaxy/Generator/fCraft/MapGen.cs | 8 ++------ MCGalaxy/Generator/fCraft/MapGenArgs.cs | 1 - MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs | 4 ++-- MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs | 8 ++++++++ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/MCGalaxy/Commands/Command.cs b/MCGalaxy/Commands/Command.cs index 73522ab36..207c9e1e0 100644 --- a/MCGalaxy/Commands/Command.cs +++ b/MCGalaxy/Commands/Command.cs @@ -66,27 +66,27 @@ public abstract partial class Command } public static List allCmds = new List(); - public static List coreCmds = new List(); - public static bool IsCore(Command cmd) { return coreCmds.Contains(cmd); } + public static bool IsCore(Command cmd) { + return cmd.GetType().Assembly == Assembly.GetExecutingAssembly(); // TODO common method + } + public static List CopyAll() { return new List(allCmds); } public static void InitAll() { Type[] types = Assembly.GetExecutingAssembly().GetTypes(); - allCmds.Clear(); - coreCmds.Clear(); + allCmds.Clear(); foreach (Group grp in Group.AllRanks) { grp.Commands.Clear(); } for (int i = 0; i < types.Length; i++) { Type type = types[i]; - if (!type.IsSubclassOf(typeof(Command)) || type.IsAbstract) continue; + if (!type.IsSubclassOf(typeof(Command)) || type.IsAbstract || !type.IsPublic) continue; Command cmd = (Command)Activator.CreateInstance(type); if (Server.Config.DisabledCommands.CaselessContains(cmd.name)) continue; Register(cmd); } - coreCmds = new List(allCmds); IScripting.AutoloadCommands(); } diff --git a/MCGalaxy/Generator/fCraft/MapGen.cs b/MCGalaxy/Generator/fCraft/MapGen.cs index f2ff24fe9..d68aee365 100644 --- a/MCGalaxy/Generator/fCraft/MapGen.cs +++ b/MCGalaxy/Generator/fCraft/MapGen.cs @@ -257,7 +257,7 @@ public sealed class fCraftMapGen { int index = (level * length + z) * width + x; if( level >= 0 && level < mapHeight ) { if( slope < args.CliffThreshold ) { - map.blocks[index] = (snow ? Block.White : bGroundSurface); + map.blocks[index] = snow ? Block.White : bGroundSurface; } else { map.blocks[index] = bCliff; } @@ -269,11 +269,7 @@ public sealed class fCraftMapGen { if( level - yy < groundThickness ) { if( slope < args.CliffThreshold ) { - if( snow ) { - map.blocks[index] = Block.White; - } else { - map.blocks[index] = bGround; - } + map.blocks[index] = snow ? Block.White : bGround; } else { map.blocks[index] = bCliff; } diff --git a/MCGalaxy/Generator/fCraft/MapGenArgs.cs b/MCGalaxy/Generator/fCraft/MapGenArgs.cs index 1fda59837..a421b59c8 100644 --- a/MCGalaxy/Generator/fCraft/MapGenArgs.cs +++ b/MCGalaxy/Generator/fCraft/MapGenArgs.cs @@ -47,7 +47,6 @@ public sealed class fCraftMapGenArgs public int SnowAltitude = 70; public int SnowTransition = 7; - public bool AddCliffs = true; public bool CliffSmoothing = true; public float CliffThreshold = 1; diff --git a/MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs b/MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs index c9930a603..ff24fc478 100644 --- a/MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs +++ b/MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs @@ -21,7 +21,7 @@ namespace MCGalaxy.Modules.Moderation.Notes { - public class CmdNotes : Command2 + class CmdNotes : Command2 { public override string name { get { return "Notes"; } } public override string type { get { return CommandTypes.Moderation; } } @@ -98,7 +98,7 @@ public class CmdNotes : Command2 } } - public sealed class CmdMyNotes : CmdNotes + sealed class CmdMyNotes : CmdNotes { public override string name { get { return "MyNotes"; } } public override string type { get { return CommandTypes.Other; } } diff --git a/MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs b/MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs index 1f19a1c9f..ec5c5874a 100644 --- a/MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs +++ b/MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs @@ -26,14 +26,22 @@ public sealed class NotesPlugin : Plugin public override string MCGalaxy_Version { get { return Server.Version; } } public override string name { get { return "Core_NotesPlugin"; } } + Command notesCmd = new CmdNotes(); + Command myNotesCmd = new CmdMyNotes(); + public override void Load(bool startup) { OnModActionEvent.Register(HandleModerationAction, Priority.Low); + Command.Register(notesCmd); + Command.Register(myNotesCmd); } public override void Unload(bool shutdown) { OnModActionEvent.Unregister(HandleModerationAction); + Command.Unregister(notesCmd); + Command.Unregister(myNotesCmd); } + static void HandleModerationAction(ModAction action) { switch (action.Type) { case ModActionType.Frozen: