Tutorial:Command blocks and functions
Command blocks and functions can be used, among many other things, to change the difficulty, change the state of the weather, or give a player predesignated items. They are particularly useful for the /weather and /time set commands, as they are only available in cheat mode otherwise. The /time set command is especially useful, as it allows players to change the current time to a preset time at the press of a button.
Command blocks and functions can also be used to make text appear in the person's chat menu. The code to do this is /tell @p <message>, or /tell <username> <message>. If the @p parameter is present only the nearest person will see the message. If a username was specified, the username will be sent the message. The player can also type: /tell <your username> @p, e.g. /tell <username> and whenever someone walks over it, it will say: "[(hover note{Deafau;ts to @})] whispers to the player: <username>".
Changing the difficulty is accomplished by /difficulty <name of the difficulty> (e.g. /difficulty peaceful).
Complete article available
This cached Wiki page is unusually large, so it is loaded on demand to keep the initial page fast.