Docs꞉ Enum - GalaxyGamesMC/Ovommand GitHub Wiki

A - Understand Enums
B - How to use enum in Ovommand
⠀⠀1. Getting with custom enum
⠀⠀2. How to add Enum Parameter to my Command
C - Enum behaviors & privacy
⠀⠀1. Behavior of enums
⠀⠀2. Detail
D - List of command enums
⠀⠀- Boolean
⠀⠀- Vanilla Gamemode
⠀⠀- PocketMine Gamemode
⠀⠀- Online players
E - Frequently questioned answers

A - Understand Enums

In Minecraft Bedrock Edition, command enums refer to the predefined values or options that can be used as parameters in various commands. These enums are essentially a set of constants that represent different states, properties, or types within the game.

Enums are a way to group options together. There are two types of enums: hardcoded enum (or hard enum) and soft enum.

A hard enum has a fixed list of options that cannot be changed while the program is running. It's like having a pre-set menu where you can only choose from the available items. Once the program starts, the options in a hard enum remain the same.

On the other hand, a soft enum is more flexible. It allows you to change its options even when the program is running, without needing to resent AvailableCommands packet. It's like having a menu that can be modified on the go.

For example, let's say you want to use the /gamemode command to change a player's gamemode. The command syntax requires you to specify the game mode using values from a hard enum called Gamemode. In this case, the possible enum values would be:

  • survival: Represents the Survival game mode.
  • creative: Represents the Creative game mode.
  • adventure: Represents the Adventure game mode.
  • spectator: Represents the Spectator game mode.

By using one of these enum values as an parameter in the command, you can change a player's gamemode.

In summary, think of hard enums as static menus with fixed choices that don't change, while soft enums are dynamic menus that allow options to be modified without the need to resent AvailableCommands packet or restart the game.

B - How to use enum in Ovommand

Before using enum, you must have OvommandHook hooked to your plugin!

use galaxygames\ovommand\OvommandHook;

$enumManager = OvommandHook::getInstance()->getEnumMananger();
or
$enumManager = EnumManager::getInstance();

1. Getting with custom enum:

Hard Enum

$inputValues = [
    "meow" => "cat",
    "goof" => "dog"
];

$showAliases = [
    "meow" => ["purr", "nyan"],
    "goof" => "bark"
];

$hiddenAliases = [
    "goof" => "grr"
];
$enum = new HardEnum("myEnum", $values, $hiddenAliases, $showAliases);
$enumManager->register($enum);
$enum->getValue("bark"); //dog

The $inputValues is an array where the keys are the thing that gives you hints ingame and the values are returned when that key got chosen.
The $showAliases is an array where these show aliases will be shown along with $inputValues and return the correct value.
The $hiddenAliases is an array where these hidden aliases won't be shown to hints but still return the correct value.
Eg:

  • If meow got inputted, cat will be returned.
  • If goof got inputted, dog will be returned.
  • If grr got inputted, dog will be returned.
  • If purr got inputted, dog will be returned.

Soft Enum

Soft Enum is pretty much the same as Hard Enum, but they can change, remove or add, or event re-set the whole values list.

$inputValues = [
    "true" => true,
    "false" => false
];

$showAliases = [
    "true" => "yes",
    "false" => "no"
];

$enum = new Soft("myEnum2", $values, [], $showAliases);
$enumManager->register($enum);
$enum->addValue("none", null);
$enum->addValues(["a1" => 1, "a2" => 2, "a3" => 3, "a4" => 4]);
$enum->removeValue("none");
$enum->removeValue("a2", "a4");
$enum->removeValues(["a1"]);
$enum->getValue("yes"); //true
$enum->changeValue("true", "very true");
$enum->getValue("yes"); //very true

Default Enums

Default Enums is just a list of supported enums by default in Ovommand. You can use easily using this following codes:

$defaultEnum1 = $enumManager->getSoftEnum(DefaultEnums::ONLINE_PLAYER); //Get online players
$defaultEnum2 = $enumManager->getEnum(DefaultEnums::BOOLEAN);
//do things with it?

2. How to add Enum Parameter to my Command

Read Docs꞉ Getting Started with Ovommand & Docs꞉ Parameter before continuing with these following steps.

Firstly, you must be sure have read and know how to register an Ovommand's command. If then, the job is pretty much straight forward and should be easy ;)

class TestCommand extends BaseCommand{
    public function setup() : void{
        $this->registerParameters(0,
            new EnumParameter("first", DefaultEnums::ONLINE_PLAYER),
            new EnumParameter("second", DefaultEnums::BOOLEAN),
            new EnumParameter("third", "myEnum")
        );
    }
    
    public function onRun(CommandSender $sender, string $label, array $args, string $preLabel = "") : void{}
}

// TODO: UPDATE DOCS LATER

C - Enum behaviors & privacy

1. Behavior of enums

Soft Enum Hard Enum
Can value be read by owner? YES YES
Can value be read by other? (Public) YES YES
Can value be read by other? (Private) NO NO
Can value be written by owner? (Before server starts) YES YES
Can value be written by others? (Private) NO NO
Can value be written by others? (Before server starts, not Protected) YES YES
Can value be written by owner? (After server starts) YES NO
Can value be written by others? (After server starts, not Protected) YES NO
Can value be written by others? (Before server starts, Protected) NO NO
Can value be written by others? (After server starts, Protected) NO NO
Can alias be written by owner? (Before server starts) YES YES
Can alias be written by owner? (After server starts) YES NO
Can alias be written by others? (Before server starts, not Protected) YES YES
Can alias be written by others? (Before server starts, Protected) NO NO
Can alias be written by others? (After server starts, not Protected) YES NO
Can alias be written by others? (After server starts, Protected) NO NO

2. Detail

TODO...

D - List of command enums:

Type Description Is vanilla Supported
Boolean Boolean value true true
GameMode Minecraft Vanilla Gamemode true true
PocketMine GameMode PocketMine-MP Gamemode false true
Online Players All online players false true
Entity Type Specifies entity type within a world true false
Block Minecraft blocks true false
Item Minecraft items true false
Entity Equipment Slot Entity equipment slot true false
Entity Events Must be one of the default entity events found in an entity's behavior JSON file. true false
Biome Show all biomes in Minecraft true false
Title raw set Show all title raw set true false

Boolean

Name: Boolean
Supported: Yes
Ovommand: DefaultEnums::BOOLEAN
Source: Microsoft Creator

Name Aliases Value
true true
false false

GameMode

Name: GameMode
Supported: Yes
Ovommand: DefaultEnums::VANILLA_GAMEMODE

Name Aliases Value
adventure a Gamemode::ADVENTURE()
creative c Gamemode::CREATIVE()
spectator Gamemode::SPECTATOR()
survival s Gamemode::SURVIVAL()

PocketMine GameMode

Name: PMGameMode
Supported: Yes
Ovommand: DefaultEnums::GAMEMODE

Name Show aliases Hidden aliases Value
adventure a 2 Gamemode::ADVENTURE()
creative c 1 Gamemode::CREATIVE()
spectator v 3 Gamemode::SPECTATOR()
survival s 0 Gamemode::SURVIVAL()

Online players

Name: OnlinePlayers
Supported: Yes
Ovommand: DefaultEnums::ONLINE_PLAYER

Show all online players

Entity Type

Name: EntityType
Supported: No
Source: Microsoft Creator

Important ❗The list of entities may change rapidly due to game updates. The following table should not be used for application, but rather as a temporary reference.

Show table
Name Aliases Value
minecraft:slime slime Slime
minecraft:tnt tnt TNT
minecraft:camel camel Camel
minecraft:turtle turtle Turtle
minecraft:chicken chicken Chicken
minecraft:bee bee Bee
minecraft:axolotl axolotl Axolotl
minecraft:pig pig Pig
minecraft:hoglin hoglin Hoglin
minecraft:zoglin zoglin Zoglin
minecraft:sniffer sniffer Sniffer
minecraft:cat cat Cat
minecraft:cow cow Cow
minecraft:sheep sheep Sheep
minecraft:wolf wolf Wolf
minecraft:villager villager Villager
minecraft:wandering_trader wandering_trader Wandering Trader
minecraft:mooshroom mooshroom Mooshroom
minecraft:squid squid Squid
minecraft:glow_squid glow_squid Glow Squid
minecraft:strider strider Strider
minecraft:rabbit rabbit Rabbit
minecraft:bat bat Bat
minecraft:iron_golem iron_golem Iron Golem
minecraft:snow_golem snow_golem Snow Golem
minecraft:ocelot ocelot Ocelot
minecraft:horse horse Horse
minecraft:trader_llama trader_llama Trader Llama
minecraft:llama llama Llama
minecraft:polar_bear polar_bear Polar Bear
minecraft:parrot parrot Parrot
minecraft:dolphin dolphin Dolphin
minecraft:panda panda Panda
minecraft:fox fox Fox
minecraft:frog frog Frog
minecraft:tadpole tadpole Tadpole
minecraft:allay allay Allay
minecraft:husk husk Husk
minecraft:tropicalfish tropicalfish Tropical Fish
minecraft:wither_skeleton wither_skeleton Wither Skeleton
minecraft:cod cod Cod
minecraft:zombie_villager zombie_villager Zombie Villager
minecraft:pufferfish pufferfish Pufferfish
minecraft:witch witch Witch
minecraft:salmon salmon Salmon
minecraft:donkey donkey Donkey
minecraft:mule mule Mule
minecraft:skeleton_horse skeleton_horse Skeleton Horse
minecraft:zombie_horse zombie_horse Zombie Horse
minecraft:zombie zombie Zombie
minecraft:stray stray Stray
minecraft:drowned drowned Drowned
minecraft:creeper creeper Creeper
minecraft:skeleton skeleton Skeleton
minecraft:spider spider Spider
minecraft:zombie_pigman zombie_pigman Zombie Pigman
minecraft:enderman enderman Enderman
minecraft:silverfish silverfish Silverfish
minecraft:cave_spider cave_spider Cave Spider
minecraft:ghast ghast Ghast
minecraft:magma_cube magma_cube Magma Cube
minecraft:blaze blaze Blaze
minecraft:warden warden Warden
minecraft:guardian guardian Guardian
minecraft:elder_guardian elder_guardian Elder Guardian
minecraft:elder_guardian_ghost elder_guardian_ghost Elder Guardian Ghost
minecraft:wither wither Wither
minecraft:ender_dragon ender_dragon Ender Dragon
minecraft:shulker shulker Shulker
minecraft:endermite endermite Endermite
minecraft:vindicator vindicator Vindicator
minecraft:evocation_illager evocation_illager Evocation Illager
minecraft:vex vex Vex
minecraft:phantom phantom Phantom
minecraft:pillager pillager Pillager
minecraft:ravager ravager Ravager
minecraft:piglin_brute piglin_brute Piglin Brute
minecraft:piglin piglin Piglin
minecraft:goat goat Goat
minecraft:minecart minecart Minecart
minecraft:hopper_minecart hopper_minecart Hopper Minecart
minecraft:tnt_minecart tnt_minecart TNT Minecart
minecraft:chest_minecart chest_minecart Chest Minecart
minecraft:command_block_minecart command_block_minecart Command Block Minecart
minecraft:xp_bottle xp_bottle XP Bottle
minecraft:xp_orb xp_orb XP Orb
minecraft:ender_crystal ender_crystal Ender Crystal
minecraft:arrow arrow Arrow
minecraft:snowball snowball Snowball
minecraft:egg egg Egg
minecraft:splash_potion splash_potion Splash Potion
minecraft:leash_knot leash_knot Leash Knot
minecraft:boat boat Boat
minecraft:chest_boat chest_boat Chest Boat
minecraft:lightning_bolt lightning_bolt Lightning Bolt
minecraft:evocation_fang evocation_fang Evocation Fang
minecraft:armor_stand armor_stand Armor Stand
minecraft:fireworks_rocket fireworks_rocket Fireworks Rocket
minecraft:npc npc NPC

Difficulty

Name: Difficulty
Supported: No
Source: Microsoft Creator

Show table
Name Aliases Value
peaceful p 0 Peaceful
easy e 1 Easy
normal n 2 Normal
hard h 3 Hard

E - FQA

1. How to use enums from other plugins?


ovo_warning
This wiki is under construction....


⚠️ **GitHub.com Fallback** ⚠️