Executing commands on startup

How to execute commands on startup


Sometimes it's useful to execute a command as soon as you join a server, e.g. to auto-enable fly mode. To make this possible, MoreCommands allows so called "startup Commands". The way how startup commands can be used has been changed over time. This page describes the "old" way as well as the way how it is currently done. It is not recommended to use the old version (probably I will remove the desription for the old version eventually).

For all current versions

For all current versions, using startup commands works the following way:
As it is the case with the older versions, it is possible to have server executed startup commands and player executed startup commands. The former are executed on server startup by the server itself. Therefore, any commands requiring a player (e.g. the /jump command) can't be used. This type of startup commands is intended to do a kind of setup for the entire world. The latter are executed everytime a player joins a server, this can be the singleplayer server or a dedicated server. These startup commands are intended to do a setup for the player himself. Because there are two different types of startup commands, they are also stored in two different ways.

Server Executed Startup Commands

These startup commands are stored in the "config.cfg" file (the same file as the configuration file used in Config). They are stored in the property "startupCommands" and must be formatted as JSON Array (Use google if you don't know what that is or see Settings). This will then look like this:
... other config properties ...

startupCommands=["examplecommand", "ignorespawn Bat", "command2", ...]

... other config properties ...
	

As you can see there is the "startupCommands" key which is mapped to the JSON Array of startup commands. This json array must consist of string which are the actual startup commands.

Player Executed Startup Commands

Player executed commands are treated as a client-side setting as it is described in Settings. Therefore, they have to be stored in the "settings_client.json" file which will hold other settings as well. All of the properties described in Settings also hold for startup commands. This way you can make them dependent on certain constraints just as it is described on that page. The actual value for the startup commands again have to be a JSON array consisting of strings which are the actual startup commands. This will then look like this:
{
... other settings ...

"startupCommands" : [
	{
		"server" : "singleplayer",
		"world" : "MoreCommands",            will be executed on server singleplayer
		"value": ["say hi"]           <----  and in world "MoreCommands"
	},
	{                                                            will be executed on server 
		"server" : "singleplayer"                            singleplayer and every world
		"value": ["/killall Bat", "spawn Creeper 10"]  <--   except for"MoreCommands"
	},
	{                                                                              will be executed in
		"value": ["examplecommand", "ignorespawn Bat", "command2", ...] <----  every other case
	}
]

... other settings ...
}
	

As you can see you can freely apply constraints on startup commands as it is the case for other settings as well. However it is important to note that startup commands will NOT be merged as it is the case for setting with mappings as value. Therefore only the startup commands which have the highest priority will be executed. In this example you can see that for server "singleplayer" and world "MoreCommands", only the "/say hi" command will be executed. For every other world on server "singleplayer", the commands "/killall Bat" and "/spawn Creeper 10" will be executed. For every other server the other commands will be executed.

For either server executed or player executed startup commands it is possible to delay the execution of these commands if you want to do that for some reason (e.g. because the world has not properly been loaded yet). See Config for more details.

For Versions 1.7, 2.7, 3.0 and 4.0 and below

This is possible via two startup files. Which file is read is depending on the environment in which the commands shall be executed (singleplayer, multiplayer, dedicated server, integrated server):

startup.cfg
The startup commands are read from the file "startup.cfg" if the mod is used on a dedicated server or if you are playing singleplayer. The syntax for this file is just one command (the name) per line without a slash Example:
fly
ignorespawn Spider
clouds
	

startup_multiplayer.cfg
The startup commands are read from the file "startup_multiplayer.cfg" if the mod is used on the client side and the player joins dedicated a server (multiplayer). The syntax is different from the "startup.cfg" file: You can specify different commands to execute for each server: You do that by writing the line "IP:PORT {" where IP is the IP address of the server and PORT is the port of the server. Don't forget the "{", it MUST be in the same line as the IP and the port! On the next lines, you write all startup command for this server. One command name per line without a slash. After the startup commands for this server, you have to write a single "}" in an EXTRA line. You can also write startup commands in the file without assigning them to a server which will cause them to be executed on EVERY server. Example:
#will be executed on the server with ip 127.0.0.1 and port 25565
127.0.0.1:25565 {
	ignorespawn Spider
	clouds
}
#will be executed on the server with ip 816.14.7.686 and port 16824
816.14.7.686:16824 {
	fly
	noclip
}
#will be executed on every server
ignorespawn Creeper
	

For both files, you can write a "#" before a command which will result in the command being commented so it will NOT execute.
Both files are located in "minecraft_installation_folder/config/morecommands". If they don't exist, create them.