Skip to content
UnknownShadow200 edited this page May 17, 2023 · 25 revisions

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.

A word of caution

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:

  1. Ensure that you trust the author of the plugin
  2. Try to compile plugins from source code yourself (rather than using pre-compiled DLLs from others)

General reference

Examples

Add notes for Mono

Custom commands

Custom commands provide a simple way to add new commands (e.g. /MyCommand), although are limited in scope compared to plugins.

Compiling

/cmdcreate [name]

Generates C# source code for an example command and saves it to extra/commands/source folder

/compile [name]

Compiles the given C# source code file in extra/commands/source folder into a .dll

Loading/Unloading

/cmdload [name]

Loads the custom command(s) from a compiled command .dll into the server

/cmdunload [name]

Unloads the given command from the server.

Autoloading on server startup

1.9.4.2 and later

Custom commands are automatically loaded on server startup

1.9.4.1 and earlier

Command names must be manually added to text/cmdautoload.txt.
Each command name must be on a separate line

Custom plugins

Custom plugins provide a more advanced way to modify the software.

Compiling

/pcreate [name]

Generates C# source code for an example plugin and saves it to plugins folder

/pcompile [name]

Compiles the given C# source code file in plugins folder into a .dll

/pcompile [name1,name2..]

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

Loading/Unloading

/pload [name]

Loads the plugin(s) from a compiled plugin .dll into the server

/punload [name]

Unloads the given plugin from the server. See /plugins for the list of currently loaded plugins

Autoloading on server startup

Plugins are automatically loaded on server startup by default

Compiling in .NET 5 and later

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 to dotnet executable (e.g. /home/test/.dotnet/dotnet)
  • MCG_COMPILER_PATH - path to csc.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)

Visual Basic support

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:

  1. Compiling and loading the Visual Basic Compiler plugin
  2. Using the following commands instead:
  • /cmdcreate [name] vb
  • /compile [name] vb
  • /pcreate [name] vb
  • /pcompile [name] vb
Clone this wiki locally