Skip to content

Commit

Permalink
Allow built-in commands to not always be autoloaded at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Dec 13, 2022
1 parent aefa65c commit 56e8d45
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
12 changes: 6 additions & 6 deletions MCGalaxy/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ public abstract partial class Command
}

public static List<Command> allCmds = new List<Command>();
public static List<Command> coreCmds = new List<Command>();
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<Command> CopyAll() { return new List<Command>(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<Command>(allCmds);
IScripting.AutoloadCommands();
}

Expand Down
8 changes: 2 additions & 6 deletions MCGalaxy/Generator/fCraft/MapGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Generator/fCraft/MapGenArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down Expand Up @@ -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; } }
Expand Down
8 changes: 8 additions & 0 deletions MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 56e8d45

Please sign in to comment.