Commands
MinecraftConsoles has a command system based on the 4J Studios console edition architecture. Commands use a binary packet-based dispatch instead of the text-parsing approach from Java Edition.
Command architecture
Section titled “Command architecture”Base class: Command
Section titled “Base class: Command”File: Minecraft.World/Command.h, .cpp
All commands extend the abstract Command class.
class Command{public: virtual EGameCommand getId() = 0; virtual int getPermissionLevel(); virtual void execute(shared_ptr<CommandSender> source, byteArray commandData) = 0; virtual bool canExecute(shared_ptr<CommandSender> source);
static void logAdminAction(...);};Permission levels:
| Level | Constant | Examples |
|---|---|---|
| 0 | LEVEL_ALL | help, emote |
| 1 | LEVEL_MODERATORS | mute |
| 2 | LEVEL_GAMEMASTERS | seed, tp, give |
| 3 | LEVEL_ADMINS | whitelist, ban |
| 4 | LEVEL_OWNERS | stop, save-all |
Unlike Java Edition, commands receive byteArray commandData (a binary packet) instead of parsed string arguments. The default getPermissionLevel() returns LEVEL_GAMEMASTERS (2).
Admin logging
Section titled “Admin logging”Two static logAdminAction() overloads handle command logging:
logAdminAction(source, messageType, message, customData, additionalMessage)for standard logginglogAdminAction(source, type, messageType, message, customData, additionalMessage)with an extra type parameter
These use ChatPacket::EChatPacketMessage for message categorization. A static AdminLogCommand *logger pointer is set via setLogger().
Protected helper
Section titled “Protected helper”getPlayer(PlayerUID) returns a shared_ptr<ServerPlayer> for a given player UID, used by commands that target specific players.
CommandDispatcher
Section titled “CommandDispatcher”File: Minecraft.World/CommandDispatcher.h, .cpp
Routes commands by their EGameCommand enum value.
class CommandDispatcher{ unordered_map<EGameCommand, Command*> commandsById; unordered_set<Command*> commands;
public: int performCommand(shared_ptr<CommandSender> sender, EGameCommand command, byteArray commandData); Command *addCommand(Command *command);};performCommand() checks canExecute() before running. If the sender doesn’t have permission, a red “You do not have permission” message is shown (except in content packages). Returns an integer status code.
addCommand() registers a command and returns it for chaining.
EGameCommand enum
Section titled “EGameCommand enum”File: Minecraft.World/CommandsEnum.h
enum EGameCommand{ eGameCommand_DefaultGameMode, eGameCommand_Effect, eGameCommand_EnchantItem, eGameCommand_Experience, eGameCommand_GameMode, eGameCommand_Give, eGameCommand_Kill, eGameCommand_Time, eGameCommand_ToggleDownfall, eGameCommand_Teleport, eGameCommand_COUNT};The eGameCommand_COUNT value is 10, meaning there are 10 registered command types.
CommandSender
Section titled “CommandSender”File: Minecraft.World/CommandSender.h
The interface for anything that can send commands:
sendMessage(wstring message, EChatPacketMessage type, int customData, wstring additionalMessage)sends feedbackhasPermission(EGameCommand command)checks if the sender can use a command
CommandBlockEntity implements this interface directly.
Implemented commands (C++)
Section titled “Implemented commands (C++)”These commands have native C++ implementations that are fully functional:
GameModeCommand
Section titled “GameModeCommand”File: Minecraft.World/GameModeCommand.h, .cpp
Changes a player’s game mode. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_GameMode.
Includes getModeForString() to parse the mode argument from the binary packet.
DefaultGameModeCommand
Section titled “DefaultGameModeCommand”File: Minecraft.World/DefaultGameModeCommand.h, .cpp
Sets the server’s default game mode. Extends GameModeCommand. Command ID: eGameCommand_DefaultGameMode. Permission level: LEVEL_GAMEMASTERS.
GiveItemCommand
Section titled “GiveItemCommand”File: Minecraft.World/GiveItemCommand.h, .cpp
Gives items to players. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Give.
Has a static preparePacket() helper that builds a GameCommandPacket with item ID, amount, aux value, and optional NBT tag string.
KillCommand
Section titled “KillCommand”File: Minecraft.World/KillCommand.h, .cpp
Kills the command sender. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Kill.
TimeCommand
Section titled “TimeCommand”File: Minecraft.World/TimeCommand.h, .cpp
Sets or adds to the world time. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Time.
Methods: doSetTime() and doAddTime(). Has a static preparePacket() for toggling day/night via a packet.
ToggleDownfallCommand
Section titled “ToggleDownfallCommand”File: Minecraft.World/ToggleDownfallCommand.h, .cpp
Toggles weather. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_ToggleDownfall.
EnchantItemCommand
Section titled “EnchantItemCommand”File: Minecraft.World/EnchantItemCommand.h, .cpp
Enchants a player’s held item. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_EnchantItem.
Has a static preparePacket() that takes enchantment ID and level (default 1).
ExperienceCommand
Section titled “ExperienceCommand”File: Minecraft.World/ExperienceCommand.h, .cpp
Grants experience to a player. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Experience.
TeleportCommand
Section titled “TeleportCommand”File: Minecraft.Client/TeleportCommand.h, .cpp
Teleports players. Lives in Minecraft.Client rather than Minecraft.World, which is unusual. Command ID: eGameCommand_Teleport.
EffectCommand
Section titled “EffectCommand”File: Minecraft.World/EffectCommand.h, .cpp
Applies or removes status effects from players. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Effect.
Java reference commands (commented out)
Section titled “Java reference commands (commented out)”Several command files have complete Java source code in block comments. These are reference implementations that haven’t been ported to C++ yet. They exist only as #if 0 blocks or Java code in comments.
GameDifficultyCommand
Section titled “GameDifficultyCommand”File: Minecraft.World/GameDifficultyCommand.h
Sets the server difficulty. Accepts peaceful/p, easy/e, normal/n, hard/h, or numeric 0-3. Tab-completion supported. Default permission level 2.
GameRuleCommand
Section titled “GameRuleCommand”File: Minecraft.World/GameRuleCommand.h
Gets, sets, or lists game rules. With 0 args it lists all rules, with 1 arg it shows a rule value, with 2 args it sets a rule. Tab-completes rule names and true/false values. Default permission level 2.
ShowSeedCommand
Section titled “ShowSeedCommand”File: Minecraft.World/ShowSeedCommand.h
Displays the world seed. Allows execution in singleplayer regardless of permission level (overrides canExecute()). Default permission level 2.
WeatherCommand
Section titled “WeatherCommand”File: Minecraft.World/WeatherCommand.h
Sets weather to clear, rain, or thunder with an optional duration in seconds. Default duration is 300 to 600 seconds (randomly chosen). Tab-completes weather type names. Default permission level 2.
PlaySoundCommand
Section titled “PlaySoundCommand”File: Minecraft.World/PlaySoundCommand.h
Plays a sound at a location for a specific player. Supports position, volume, pitch, and minimum volume arguments. Handles the case where the player is too far away by either sending the sound at reduced volume from a closer position or throwing an error. Default permission level 2.
SpreadPlayersCommand
Section titled “SpreadPlayersCommand”File: Minecraft.World/SpreadPlayersCommand.h
Spreads players randomly across an area. Has a MAX_ITERATION_COUNT of 10,000 for the randomization algorithm. Default permission level 2.
SetPlayerTimeoutCommand
Section titled “SetPlayerTimeoutCommand”File: Minecraft.World/SetPlayerTimeoutCommand.h
Sets the connection timeout for a player.
AdminLogCommand
Section titled “AdminLogCommand”File: Minecraft.World/AdminLogCommand.h
The logging backend used by Command::logAdminAction().
GameRules
Section titled “GameRules”File: Minecraft.World/GameRules.h, .cpp
While the GameRuleCommand itself isn’t ported, the GameRules class is implemented in C++. It stores game rules as typed values.
The inner GameRule class stores each rule as a wstring with cached bool, int, and double conversions.
Defined rules (4J converted from strings to integer constants):
| Rule constant | Purpose |
|---|---|
RULE_DOFIRETICK | Fire spread |
RULE_MOBGRIEFING | Mob block destruction |
RULE_KEEPINVENTORY | Keep items on death |
RULE_DOMOBSPAWNING | Mob spawning |
RULE_DOMOBLOOT | Mob item drops |
RULE_DOTILEDROPS | Block item drops |
RULE_COMMANDBLOCKOUTPUT | Command block output to chat |
RULE_NATURAL_REGENERATION | Natural health regeneration |
RULE_DAYLIGHT | Daylight cycle |
getBoolean(int rule) is the main query method.
EntitySelector
Section titled “EntitySelector”File: Minecraft.World/EntitySelector.h, .cpp
Used throughout the command and entity systems for filtering entities.
class EntitySelector{public: static const EntitySelector *ENTITY_STILL_ALIVE; static const EntitySelector *CONTAINER_ENTITY_SELECTOR; virtual bool matches(shared_ptr<Entity> entity) const = 0;};Built-in selectors:
| Class | File | Purpose |
|---|---|---|
AliveEntitySelector | EntitySelector.cpp | Matches entities that are still alive |
ContainerEntitySelector | EntitySelector.cpp | Matches entities that are containers |
MobCanWearArmourEntitySelector | EntitySelector.cpp | Matches mobs that can wear a specific armor item |
HorseEntitySelector | EntityHorse.h | Matches horse entities (for breeding) |
LivingEntitySelector | WitherBoss.h | Matches living entities (for Wither targeting) |
The two static singleton instances (ENTITY_STILL_ALIVE, CONTAINER_ENTITY_SELECTOR) are used throughout the codebase for common filtering operations.
Comparison with LCEMP
Section titled “Comparison with LCEMP”LCEMP has a smaller set of commands. The commands in MinecraftConsoles but not in the LCEMP base include:
/effect(stub)/enchant/xp(experience)/defaultgamemode- All the Java-reference commands (difficulty, gamerule, seed, weather, playsound, spreadplayers)
Both codebases share the core commands: /gamemode, /give, /kill, /time, /toggledownfall, /tp.
MinecraftConsoles also adds the GameRules system, CommandBlock / CommandBlockEntity, and the EntitySelector system, none of which exist in LCEMP.