-
Notifications
You must be signed in to change notification settings - Fork 85
Scripting
MCGalaxy comes with extensive support for scripting/modding the software using C#.
The two main ways this can be accomplished are through Custom commands and Custom plugins.
Plugins execute with full trust, or in other words, they run with the same privileges as the server itself.
Therefore when using plugins developed by others, you should:
- Ensure that you trust the author of the plugin
- Try to compile plugins from source code yourself (rather than using pre-compiled DLLs from others)
Examples
Add notes for Mono
Custom commands provide a simple way to add new commands (e.g. /MyCommand
), although are limited in scope compared to plugins.
Generates C# source code for an example command and saves it to extra/commands/source
folder
Compiles the given C# source code file in extra/commands/source
folder into a .dll
Loads the custom command(s) from a compiled command .dll into the server
Unloads the given command from the server.
Custom commands are automatically loaded on server startup
Command names must be manually added to text/cmdautoload.txt
.
Each command name must be on a separate line
Custom plugins provide a more advanced way to modify the software.
Generates C# source code for an example plugin and saves it to plugins
folder
Compiles the given C# source code file in plugins
folder into a .dll
Compiles the given C# source code files in plugins
folder into a .dll
Example: /pcompile test,utils
compiles test.cs
and utils.cs
into test.dll
Loads the plugin(s) from a compiled plugin .dll into the server
Unloads the given plugin from the server. See /plugins
for the list of currently loaded plugins
Plugins are automatically loaded on server startup by default
When running MCGalaxy via .NET framework (or mono), it uses the CodeDomProvider
class to automatically locate and run the C# compiler - unfortunately, this class does not work in .NET 5 and later
Therefore when running MCGalaxy via .NET 5 or later (or .NET core), you must manually instruct MCGalaxy how to locate and run the C# compiler via the following two environment variables:
-
MCG_DOTNET_PATH
- path todotnet
executable (e.g./home/test/.dotnet/dotnet
) -
MCG_COMPILER_PATH
- path tocsc.dll
file (e.g./home/test/.dotnet/sdk/6.0.300/Roslyn/bincore/csc.dll
)
The easiest way to set these environment variables is to provide them when running MCGalaxy from the shell/terminal (e.g. MCG_DOTNET_PATH=/home/test/.dotnet/dotnet MCG_COMPILER_PATH=/home/test/.dotnet/sdk/6.0.300/Roslyn/bincore/csc.dll dotnet MCGalaxyCLI.exe
)
As both MCGalaxy and the majority of custom commands/plugins are written in C#, it is highly recommended that you also write commands/plugins in C#
However, creating and compiling custom commands/plugins written in Visual Basic can still be done by:
- Compiling and loading the Visual Basic Compiler plugin
- Using the following commands instead:
/cmdcreate [name] vb
/compile [name] vb
/pcreate [name] vb
/pcompile [name] vb