From 7f7cf7cb52dd10ea5c73e9ced6d333688001cc9b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 10 Dec 2023 22:16:24 +1100 Subject: [PATCH] Make compiling module a proper plugin --- MCGalaxy/Modules/Compiling/CmdCmdCreate.cs | 2 +- MCGalaxy/Modules/Compiling/CmdCompile.cs | 2 +- MCGalaxy/Modules/Compiling/CmdCompload.cs | 2 +- MCGalaxy/Modules/Compiling/CompilerPlugin.cs | 44 +++++++++++++++++++ .../Modules/Relay/Discord/DiscordPlugin.cs | 2 + MCGalaxy/Scripting/Plugin.cs | 8 +++- MCGalaxy/Server/Server.cs | 12 ++--- README.md | 6 +-- 8 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 MCGalaxy/Modules/Compiling/CompilerPlugin.cs diff --git a/MCGalaxy/Modules/Compiling/CmdCmdCreate.cs b/MCGalaxy/Modules/Compiling/CmdCmdCreate.cs index c78e1e1a2..5bbdbd875 100644 --- a/MCGalaxy/Modules/Compiling/CmdCmdCreate.cs +++ b/MCGalaxy/Modules/Compiling/CmdCmdCreate.cs @@ -21,7 +21,7 @@ using MCGalaxy.Commands; namespace MCGalaxy.Modules.Compiling { - public sealed class CmdCmdCreate : CmdCompile + sealed class CmdCmdCreate : CmdCompile { public override string name { get { return "CmdCreate"; } } public override string shortcut { get { return ""; } } diff --git a/MCGalaxy/Modules/Compiling/CmdCompile.cs b/MCGalaxy/Modules/Compiling/CmdCompile.cs index 27bc8fc75..9ad220951 100644 --- a/MCGalaxy/Modules/Compiling/CmdCompile.cs +++ b/MCGalaxy/Modules/Compiling/CmdCompile.cs @@ -22,7 +22,7 @@ using MCGalaxy.Scripting; namespace MCGalaxy.Modules.Compiling { - public class CmdCompile : Command2 + class CmdCompile : Command2 { public override string name { get { return "Compile"; } } public override string type { get { return CommandTypes.Other; } } diff --git a/MCGalaxy/Modules/Compiling/CmdCompload.cs b/MCGalaxy/Modules/Compiling/CmdCompload.cs index 60c8c5d48..214617fb3 100644 --- a/MCGalaxy/Modules/Compiling/CmdCompload.cs +++ b/MCGalaxy/Modules/Compiling/CmdCompload.cs @@ -21,7 +21,7 @@ using MCGalaxy.Scripting; namespace MCGalaxy.Modules.Compiling { - public sealed class CmdCompLoad : CmdCompile + sealed class CmdCompLoad : CmdCompile { public override string name { get { return "CompLoad"; } } public override string shortcut { get { return "cml"; } } diff --git a/MCGalaxy/Modules/Compiling/CompilerPlugin.cs b/MCGalaxy/Modules/Compiling/CompilerPlugin.cs new file mode 100644 index 000000000..c3e1fbdec --- /dev/null +++ b/MCGalaxy/Modules/Compiling/CompilerPlugin.cs @@ -0,0 +1,44 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + https://opensource.org/license/ecl-2-0/ + https://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. +*/ +#if !MCG_STANDALONE +using System; + +namespace MCGalaxy.Modules.Compiling +{ + public sealed class CompilerPlugin : Plugin + { + public override string name { get { return "Compiler"; } } + + Command cmdCreate = new CmdCmdCreate(); + Command cmdCompile = new CmdCompile(); + Command cmdCompLoad = new CmdCompLoad(); + + public override void Load(bool startup) { + Server.EnsureDirectoryExists(ICompiler.COMMANDS_SOURCE_DIR); + + Command.Register(cmdCreate); + Command.Register(cmdCompile); + Command.Register(cmdCompLoad); + } + + public override void Unload(bool shutdown) { + Command.Unregister(cmdCreate, cmdCompile, cmdCompLoad); + } + } +} +#endif diff --git a/MCGalaxy/Modules/Relay/Discord/DiscordPlugin.cs b/MCGalaxy/Modules/Relay/Discord/DiscordPlugin.cs index 1b47cbebc..5c021b5c2 100644 --- a/MCGalaxy/Modules/Relay/Discord/DiscordPlugin.cs +++ b/MCGalaxy/Modules/Relay/Discord/DiscordPlugin.cs @@ -93,6 +93,8 @@ namespace MCGalaxy.Modules.Relay.Discord public static DiscordBot Bot = new DiscordBot(); public override void Load(bool startup) { + Server.EnsureDirectoryExists("text/discord"); + Bot.Config = Config; Bot.ReloadConfig(); Bot.Connect(); diff --git a/MCGalaxy/Scripting/Plugin.cs b/MCGalaxy/Scripting/Plugin.cs index 9a52d9330..fdc681ac1 100644 --- a/MCGalaxy/Scripting/Plugin.cs +++ b/MCGalaxy/Scripting/Plugin.cs @@ -137,8 +137,12 @@ namespace MCGalaxy LoadCorePlugin(new NotesPlugin()); LoadCorePlugin(new DiscordPlugin()); LoadCorePlugin(new IRCPlugin()); - LoadCorePlugin(new IPThrottler()); - + LoadCorePlugin(new IPThrottler()); + +#if !MCG_STANDALONE + LoadCorePlugin(new MCGalaxy.Modules.Compiling.CompilerPlugin()); +#endif + LoadCorePlugin(new CountdownPlugin()); LoadCorePlugin(new CTFPlugin()); LoadCorePlugin(new LSPlugin()); diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs index 084459cf9..46760215a 100644 --- a/MCGalaxy/Server/Server.cs +++ b/MCGalaxy/Server/Server.cs @@ -142,14 +142,14 @@ namespace MCGalaxy EnsureDirectoryExists("extra/bots"); EnsureDirectoryExists(Paths.ImportsDir); EnsureDirectoryExists("blockdefs"); -#if !MCG_STANDALONE - EnsureDirectoryExists(MCGalaxy.Modules.Compiling.ICompiler.COMMANDS_SOURCE_DIR); // TODO move to compiling module -#endif - EnsureDirectoryExists("text/discord"); // TODO move to discord plugin } - static void EnsureDirectoryExists(string dir) { - if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); + public static void EnsureDirectoryExists(string dir) { + try { + if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); + } catch (Exception ex) { + Logger.LogError("Creating directory " + dir, ex); + } } public static void LoadAllSettings() { LoadAllSettings(false); } diff --git a/README.md b/README.md index b9a4d6c77..03dbe75b5 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,10 @@ Compiling - .NET 6 / .NET 5 / .NET Core ----------------- * Compiling for .NET 6: No changes necessary -* Compiling for .NET 5: Change `TargetFramework` in CLI/MCGalaxyCLI_Core.csproj to `net5.0` -* Compiling for .NET Core: Change `TargetFramework` in CLI/MCGalaxyCLI_Core.csproj to `netcoreapp3.1` +* Compiling for .NET 5: Change `TargetFramework` in CLI/MCGalaxyCLI_dotnet.csproj to `net5.0` +* Compiling for .NET Core: Change `TargetFramework` in CLI/MCGalaxyCLI_dotnet.csproj to `netcoreapp3.1` -Then navigate into `CLI` directory, and then run `dotnet build MCGalaxyCLI_Core.csproj` +Then navigate into `CLI` directory, and then run `dotnet build MCGalaxyCLI_dotnet.csproj` **You will also need to copy `libsqlite3.so.0` from system libraries to `libsqlite3.so` in the server folder**