### Install and Run Endstone Source: https://github.com/endstonemc/endstone/blob/main/README.md Install Endstone using pip and run the server. This is the initial setup for getting started. ```shell pip install endstone endstone ``` -------------------------------- ### Install Conan and Dependencies Source: https://github.com/endstonemc/endstone/blob/main/CLAUDE.md Installs Conan and then uses it to install project dependencies. Ensure you are in a Visual Studio Developer prompt with clang-cl/lld-link on PATH when running on Windows. ```shell pip install conan conan install . --build=missing ``` -------------------------------- ### Install Twine Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/publish-your-plugin.md Install the twine utility, which is used for publishing Python packages to PyPI and other repositories. ```shell pip install twine ``` -------------------------------- ### Install RakNet Headers Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Installs the RakNet header files to the installation's include directory. FILES_MATCHING ensures only .h files are copied. ```cmake install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Source/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### Example Workflow for Stub Generation Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md A step-by-step example demonstrating the process of making binding changes, building, generating stubs, verifying, and committing. ```bash # 1. Make your binding changes # (e.g., edit src/endstone/python/... ) # 2. Build and install pip install -U . # 3. Generate stubs python scripts/stubgen.py # 4. Verify git status # Check the generated .pyi files # 5. Commit git add endstone/*.pyi git commit -m "docs: update type stubs for new bindings" ``` -------------------------------- ### Install Documentation Requirements Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Install the Python dependencies required for building the project's documentation using Material for MkDocs. ```shell pip install -r docs/requirements.txt ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Installs the generated CMake configuration files (raknetConfig.cmake and raknetConfigVersion.cmake) to the installation directory. This completes the package setup for RakNet. ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/raknetConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/raknetConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/raknet) ``` -------------------------------- ### Install Dependencies with Conan Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Install the project's dependencies using Conan. The --build=missing flag ensures that any missing dependencies are built. ```shell conan install . --build=missing ``` -------------------------------- ### Install endstone-stubgen Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md Install the necessary tool for generating type stubs if it's not already installed. ```bash pip install endstone-stubgen ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Start a live development server to preview the documentation as it is being written. Changes are reflected automatically. ```shell mkdocs serve ``` -------------------------------- ### Build Endstone from Source Source: https://github.com/endstonemc/endstone/blob/main/README.md Clone the Endstone repository and install it from source. This method requires Git and Python. ```shell git clone https://github.com/EndstoneMC/endstone.git cd endstone pip install . endstone ``` -------------------------------- ### Start Endstone Server Locally Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/start-your-server.md Run this command in the directory where you want your server to be located to bootstrap Endstone. ```bash endstone ``` -------------------------------- ### Install Endstone Test Plugin Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md Install the endstone_test plugin in editable mode. This is required for running runtime tests. ```bash pip install -e tests/endstone_test ``` -------------------------------- ### Run Endstone using Docker Source: https://github.com/endstonemc/endstone/blob/main/README.md Install and run Endstone using Docker. This method requires Docker to be installed. ```shell docker pull endstone/endstone docker run --rm -it -p 19132:19132/udp endstone/endstone ``` -------------------------------- ### Install Endstone with Persistent Build Directory Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Install Endstone from source while keeping the C++ build tree persistent across reinstalls for faster subsequent builds. Specify the build directory using -C build-dir. ```shell pip install -U . -C build-dir=./build ``` -------------------------------- ### Install Endstone from Source Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Install Endstone from its source code using pip. This command also utilizes the PEP 517 backend, which runs Conan internally. ```shell pip install -U . # or with uv: uv pip install -U . ``` -------------------------------- ### Install RakNet Targets Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Installs the RakNet library and related files to the appropriate directories based on the build type and platform. This makes the library available for use by other projects. ```cmake install(TARGETS raknet EXPORT raknetTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) ``` -------------------------------- ### C++ Command Handler Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Implement the `onCommand` method in your C++ plugin to handle incoming commands. This example shows how to respond to a '/hello' command. ```c++ #include class MyPlugin : public endstone::Plugin { public: bool onCommand(endstone::CommandSender &sender, const endstone::Command &command, const std::vector &args) override { if (command.getName() == "hello") { sender.sendMessage("Hello World!"); } return true; } // ... }; ``` -------------------------------- ### Install CMake Export Files Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Installs CMake configuration files for the RakNet target. These files allow other CMake projects to find and use the installed RakNet library. ```cmake install(EXPORT raknetTargets NAMESPACE raknet:: FILE raknetTargets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/raknet) ``` -------------------------------- ### Check Endstone Installation (Python) Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Use this command in the terminal to verify that the `endstone` package is installed in your Python environment. ```bash pip show endstone ``` -------------------------------- ### Python Command Handler Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Implement the `on_command` method in your Python plugin to handle incoming commands. This example shows how to respond to a '/hello' command. ```python from endstone.command import Command, CommandSender from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" commands = { "hello": { "description": "Greet the command sender.", "usages": ["/hello"], "permissions": ["my_plugin.command.hello"], } } permissions = { "my_plugin.command.hello": { "description": "Allow users to use the /hello command.", "default": True, } } def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool: if command.name == "hello": sender.send_message("Hello World!") return True # ... ``` -------------------------------- ### Install Conan Package Manager Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Install the Conan package manager, which is required for managing Endstone's development dependencies. ```shell pip install conan ``` -------------------------------- ### Install Endstone with pip (Latest) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/installation.md Installs the latest version of the Endstone package using pip. It's recommended to run this command within an activated virtual environment. ```sh pip install endstone ``` -------------------------------- ### Start Endstone Server with Docker (Command Prompt) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/start-your-server.md Use this command to run Endstone within Docker on Windows Command Prompt. It maps the current directory and exposes the default Minecraft Bedrock port. ```bash docker run --rm -it -v "%cd%":/home/endstone -p 19132:19132/udp endstone/endstone ``` -------------------------------- ### Configure Endstone DevTools Build Source: https://github.com/endstonemc/endstone/blob/main/src/endstone/core/devtools/CMakeLists.txt Sets up the minimum CMake version, project name, and languages. This is the standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.15) project(endstone_devtools LANGUAGES CXX) ``` -------------------------------- ### Example Test for Server Name Source: https://github.com/endstonemc/endstone/blob/main/tests/endstone_test/README.md A basic pytest example demonstrating how to test the server name using the 'server' fixture. This test verifies that the server's name is correctly identified as 'Endstone'. ```python from endstone import Server def test_server_name(server: Server) -> None: """Verify server name is 'Endstone'.""" assert server.name == "Endstone" ``` -------------------------------- ### Start Endstone Server with Docker (Linux/Powershell) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/start-your-server.md Use this command to run Endstone within Docker on Linux or Powershell. It maps the current directory and exposes the default Minecraft Bedrock port. ```bash docker run --rm -it -v ${PWD}:/home/endstone -p 19132:19132/udp endstone/endstone ``` -------------------------------- ### Check CMake Version Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Verify the installed CMake version. This command is run after activating the Conan build environment. ```shell cmake --version ``` -------------------------------- ### Example Conventional Commit Message Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md Use this format for commit messages to clearly indicate the type of change and its scope. This example shows a new feature related to players. ```git commit feat(player): add event for player join Implement PlayerJoinEvent that fires when a player connects to the server. ``` -------------------------------- ### pyproject.toml Configuration (Python) Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md This file defines build system requirements and project metadata for your Python plugin. Ensure the `name` field starts with `endstone-` and follows the `lower-case-with-dash` convention. ```toml [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [project] name = "endstone-my-plugin" version = "0.1.0" description = "My first Python plugin for Endstone servers!" ``` -------------------------------- ### Editable Install Python Plugin Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/install-your-plugin.md Install a Python plugin in development mode using pip's editable flag. This allows changes to the source code to take effect immediately after a server reload. ```sh pip install --editable . ``` -------------------------------- ### Configure RakNet in CMake Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/test_package/CMakeLists.txt Sets the minimum CMake version, project name, C++ standard, finds the RakNet package, and links the executable against it. Ensure RakNet is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11) find_package(raknet CONFIG REQUIRED) add_executable(test_package test_package.cpp) target_link_libraries(test_package PRIVATE raknet::raknet) ``` -------------------------------- ### Configure RakNet Include Directories Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Configures the include directories for the RakNet target. It specifies build-time and install-time include paths, ensuring headers are accessible during development and after installation. ```cmake target_include_directories(raknet PUBLIC $ $) ``` -------------------------------- ### Set Minimum CMake Version and Project Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Specifies the minimum required CMake version and defines the project name and version. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.15) project(raknet VERSION 4.081 LANGUAGES CXX) ``` -------------------------------- ### Find Dependencies for DevTools Source: https://github.com/endstonemc/endstone/blob/main/src/endstone/core/devtools/CMakeLists.txt Locates required external libraries like glfw3, imgui, and zstr. Ensure these libraries are installed and discoverable by CMake. ```cmake find_package(glfw3 CONFIG REQUIRED) find_package(imgui CONFIG REQUIRED) find_package(zstr CONFIG REQUIRED) ``` -------------------------------- ### Configure Package Configuration File Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Generates the raknetConfig.cmake file from a template. This file is essential for CMake's find_package mechanism to locate the installed RakNet library. ```cmake configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/raknetConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/raknetConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/raknet) ``` -------------------------------- ### Include CMake Modules Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Includes necessary CMake modules for package configuration and installation directory definitions. These modules provide utility functions for managing project structure and packaging. ```cmake include(GNUInstallDirs) include(CMakePackageConfigHelpers) ``` -------------------------------- ### Schedule Task in C++ Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/schedule-tasks.md Schedules a task to send a popup message to all online players every 20 ticks using C++. This example demonstrates the use of runTaskTimer within an Endstone plugin. ```c++ #include class MyPlugin : public endstone::Plugin { public: // ... void onEnable() override { getLogger().info("onEnable is called"); getServer().getScheduler().runTaskTimer([&]() { sayHi(); }, 0, 20); } void sayHi() { for (auto& player : getServer().getOnlinePlayers()) { player->sendPopup("Hi"); } } }; ``` -------------------------------- ### Build Documentation Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Build the static documentation files for the project. This command generates the final documentation site. ```shell mkdocs build ``` -------------------------------- ### Create a Basic Endstone Plugin Source: https://github.com/endstonemc/endstone/blob/main/README.md A simple Python plugin that logs a message on enable and sends a welcome message to players when they join. Requires the 'endstone' library. ```python from endstone.plugin import Plugin from endstone.event import event_handler, PlayerJoinEvent class MyPlugin(Plugin): api_version = "0.10" def on_enable(self): self.logger.info("MyPlugin enabled!") self.register_events(self) @event_handler def on_player_join(self, event: PlayerJoinEvent): event.player.send_message(f"Welcome, {event.player.name}!") ``` -------------------------------- ### Build C++ Plugin Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/install-your-plugin.md Build your C++ plugin using your IDE's build command. Copy the resulting .dll file to your server's plugins directory. ```sh ``` -------------------------------- ### Build Your Package Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/publish-your-plugin.md Build your Python package using the 'build' command. This command generates a source-distribution and wheel in the 'dist/' directory. ```shell pipx run build ``` -------------------------------- ### Build Python Plugin Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/install-your-plugin.md Use pipx to build a Python plugin wheel. Copy the resulting .whl file to your server's plugins directory. ```bash pip install pipx pipx run build --wheel ``` -------------------------------- ### Initialize Python Plugin Package Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Ensures the 'MyPlugin' class is discoverable by importing it in the package's __init__.py and adding it to the __all__ variable. ```python from endstone_my_plugin.my_plugin import MyPlugin __all__ = ["MyPlugin"] ``` -------------------------------- ### Activate Conan Build Environment (Windows Command Prompt) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Activate the build virtual environment created by Conan in a Windows Command Prompt. This is necessary for manual CMake builds. ```cmd .\build\Release\generators\conanbuild.bat ``` -------------------------------- ### Define a Basic Command in Python Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Use the 'commands' dictionary in your Plugin class to define a new command with its description and usages. ```python from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" commands = { "hello": { "description": "Greet the command sender.", "usages": ["/hello"], } } # ... ``` -------------------------------- ### Define a Basic Command in C++ Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Utilize the command() builder pattern within the ENDSTONE_PLUGIN macro to define commands with descriptions and usages. ```c++ #include "my_plugin.h" ENDSTONE_PLUGIN("my_plugin", "0.1.0", MyPlugin) { description = "My first C++ plugin for Endstone servers"; command("hello") .description("Greet the command sender.") .usages("/hello"); } ``` -------------------------------- ### Python Command with Optional Parameter Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Defines a '/hello' command in Python that accepts an optional message parameter. If no message is provided, it defaults to 'Hello World!'; otherwise, it sends the provided message. ```python from endstone.command import Command, CommandSender from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" commands = { "hello": { "description": "Greet the command sender.", "usages": ["/hello [msg: message]"], "permissions": ["my_plugin.command.hello"], } } permissions = { "my_plugin.command.hello": { "description": "Allow users to use the /hello command.", "default": True, } } def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool: if command.name == "hello": if len(args) == 0: #(1)! sender.send_message("Hello World!") else: sender.send_message(args[0]) return True # ... ``` -------------------------------- ### CMakeLists.txt Configuration (C++) Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md This file configures the CMake build system for your C++ plugin. It specifies the project name, C++ standard, and fetches the Endstone library from its Git repository. ```cmake cmake_minimum_required(VERSION 3.15) project(my_plugin CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) FetchContent_Declare( endstone GIT_REPOSITORY https://github.com/EndstoneMC/endstone.git GIT_TAG v{{ git.short_tag[1:].rsplit('.', 1)[0] }} #(1)! ) FetchContent_MakeAvailable(endstone) ``` -------------------------------- ### Configure Python Plugin Metadata Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Specify the compatible API version for your Python plugin. Ensure the entry point in `pyproject.toml` matches your project name without the 'endstone-' prefix. ```python from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" def on_load(self) -> None: self.logger.info("on_load is called!") def on_enable(self) -> None: self.logger.info("on_enable is called!") def on_disable(self) -> None: self.logger.info("on_disable is called!") ``` ```toml [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [project] name = "endstone-my-plugin" version = "0.1.0" description = "My first Python plugin for Endstone servers!" [project.entry-points."endstone"] my-plugin = "endstone_my_plugin:MyPlugin" ``` -------------------------------- ### Create Python Plugin Class Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Defines the main plugin class 'MyPlugin' that extends 'endstone.plugin.Plugin'. This is the entry point for your Python plugin. ```python from endstone.plugin import Plugin class MyPlugin(Plugin): pass ``` -------------------------------- ### Activate Conan Build Environment (Linux) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Activate the build virtual environment created by Conan on Linux. This is necessary for manual CMake builds. ```shell source ./build/Release/generators/conanbuild.sh ``` -------------------------------- ### Upload to PyPI Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/publish-your-plugin.md Upload your package distributions to the live Python Package Index (PyPI) using twine. This command should be used after successfully testing on TestPyPI. ```shell twine upload -r pypi dist/* ``` -------------------------------- ### Activate Conan Build Environment (Windows PowerShell) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Activate the build virtual environment created by Conan in Windows PowerShell. This is necessary for manual CMake builds. ```powershell .\build\Release\generators\conanbuild.ps1 ``` -------------------------------- ### C++ Plugin Command Handler Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Implements the '/hello' command handler in C++. It checks if a message argument is provided and sends either a default greeting or the custom message to the sender. ```c++ #include class MyPlugin : public endstone::Plugin { public: bool onCommand(endstone::CommandSender &sender, const endstone::Command &command, const std::vector &args) override { if (command.getName() == "hello") { if (args.empty()) { sender.sendMessage("Hello World!"); } else { sender.sendMessage(args[0]); } } return true; } // ... }; ``` -------------------------------- ### Configure Endstone Version Header Source: https://github.com/endstonemc/endstone/blob/main/include/CMakeLists.txt Configures the version header file for Endstone. It uses a template and replaces placeholders with build-time variables. ```cmake if (NOT DEFINED ENDSTONE_VERSION_FULL) set(ENDSTONE_VERSION_FULL "${PROJECT_VERSION}") endif () configure_file(endstone/version.h.in "${CMAKE_CURRENT_BINARY_DIR}/generated/endstone/version.h" @ONLY) ``` -------------------------------- ### Upload to TestPyPI Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/publish-your-plugin.md Upload your package distributions to the TestPyPI repository using twine. This is a staging environment for testing the publishing process without affecting the live PyPI. ```shell twine upload -r testpypi dist/* ``` -------------------------------- ### Define Minimum CMake Version and Project Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Sets the minimum required CMake version and defines the project name and language. ```cmake cmake_minimum_required(VERSION 3.15) project(endstone_test LANGUAGES CXX) ``` -------------------------------- ### Build Endstone with CMake Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Build the Endstone project using CMake presets for a release configuration. This command configures the build and then compiles the project. ```shell cmake --preset conan-release cmake --build --preset conan-release ``` -------------------------------- ### Configure C++ Plugin Metadata Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Define your C++ plugin's name, version, and main class using the `ENDSTONE_PLUGIN` macro. The plugin name must only contain lowercase letters, numbers, and underscores. ```c++ #include "my_plugin.h" ENDSTONE_PLUGIN(/*(1)!*/"my_plugin", /*(2)!*/"0.1.0", /*(3)!*/MyPlugin) { description = "My first C++ plugin for Endstone servers"; } ``` -------------------------------- ### C++ Plugin Command Registration Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Registers a '/hello' command in C++ with a description and usage that includes an optional message parameter. This snippet shows the command registration part of a C++ Endstone plugin. ```c++ #include "my_plugin.h" ENDSTONE_PLUGIN("my_plugin", "0.1.0", MyPlugin) { description = "My first C++ plugin for Endstone servers"; command("hello") .description("Greet the command sender.") .usages("/hello [msg: message]") .permissions("my_plugin.command.hello"); permission("my_plugin.command.hello") .description("Allow users to use the /hello command.") .default_(endstone::PermissionDefault::True); } ``` -------------------------------- ### Set Plugin Output Directories Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Configures the output directories for the 'test_plugin' target, ensuring libraries and runtimes are placed in the 'plugins' folder. ```cmake set_target_properties(test_plugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "plugins") set_target_properties(test_plugin PROPERTIES RUNTIME_OUTPUT_DIRECTORY "plugins") ``` -------------------------------- ### Configure CMake for C++ Plugin Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Adds a new plugin target to the CMakeLists.txt file, fetching the Endstone library and specifying the plugin's source file. ```cmake cmake_minimum_required(VERSION 3.15) project(my_plugin CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) FetchContent_Declare( endstone GIT_REPOSITORY https://github.com/EndstoneMC/endstone.git GIT_TAG v{{ git.short_tag[1:].rsplit('.', 1)[0] }} ) FetchContent_MakeAvailable(endstone) endstone_add_plugin(${PROJECT_NAME} src/my_plugin.cpp) ``` -------------------------------- ### Add Permissions to a Command in C++ Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Assign command permissions using the .permissions() method and define permission details with the permission() builder, setting the default access level. ```c++ #include "my_plugin.h" ENDSTONE_PLUGIN("my_plugin", "0.1.0", MyPlugin) { description = "My first C++ plugin for Endstone servers"; command("hello") .description("Greet the command sender.") .usages("/hello") .permissions("my_plugin.command.hello"); permission("my_plugin.command.hello") .description("Allow users to use the /hello command.") .default_(endstone::PermissionDefault::True); /*(1)*/ } ``` -------------------------------- ### Find and Link Funchook with CMake Source: https://github.com/endstonemc/endstone/blob/main/recipes/funchook/all/test_package/CMakeLists.txt This snippet shows how to locate the funchook package using CMake's find_package command and then link the funchook::funchook target to an executable. This is typically used in a project's main CMakeLists.txt file. ```cmake cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES C) find_package(funchook CONFIG REQUIRED) add_executable(test_package test_package.c) target_link_libraries(test_package PRIVATE funchook::funchook) ``` -------------------------------- ### Clone Endstone Repository Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/contributing.md Clone the Endstone repository to your local machine and navigate into the project directory. ```shell git clone https://github.com/EndstoneMC/endstone.git cd endstone ``` -------------------------------- ### Platform-Specific Settings for Windows Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Applies Windows-specific compile definitions and links the ws2_32 library. This is necessary for network functionality on Windows. ```cmake if(WIN32) target_compile_definitions(raknet PRIVATE WIN32 _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE _WINSOCK_DEPRECATED_NO_WARNINGS ) target_link_libraries(raknet PUBLIC ws2_32) else() find_package(Threads REQUIRED) target_link_libraries(raknet PUBLIC Threads::Threads) endif() ``` -------------------------------- ### Run C++ Tests with CTest Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md Execute the C++ unit tests using CTest. Ensure you specify the correct build directory. ```bash ctest --test-dir build/Release ``` -------------------------------- ### Add Dependencies for Test Executable Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Specifies that the 'endstone_test' executable depends on the 'test_plugin' target. This ensures the plugin is built before the test executable. ```cmake add_dependencies(endstone_test test_plugin) ``` -------------------------------- ### Define Endstone Interface Library Source: https://github.com/endstonemc/endstone/blob/main/include/CMakeLists.txt Defines the main Endstone library as an INTERFACE library and creates an alias target. It also sets up include directories and links necessary dependencies. ```cmake add_library(endstone INTERFACE) add_library(endstone::endstone ALIAS endstone) target_include_directories(endstone INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} $) target_link_libraries(endstone INTERFACE fmt::fmt nonstd::expected-lite) ``` -------------------------------- ### Link Libraries for Test Executable Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Links the 'endstone_test' executable against the Endstone core library and Google Test/Mock libraries. This makes Endstone and testing functionalities available to the tests. ```cmake target_link_libraries(endstone_test PRIVATE endstone::core GTest::gtest_main GTest::gmock_main) ``` -------------------------------- ### Activate Virtual Environment on Windows Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/installation.md Activates the 'venv' virtual environment on Windows systems. The terminal prompt will change to indicate activation. ```sh . venv/Scripts/activate ``` -------------------------------- ### Activate Virtual Environment on Linux Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/installation.md Activates the 'venv' virtual environment on Linux systems. The terminal prompt will change to indicate activation. ```sh . venv/bin/activate ``` -------------------------------- ### Implement Python Plugin Lifecycle Methods Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Overrides the on_load, on_enable, and on_disable methods in the Python 'MyPlugin' class to log messages when these events occur. ```python from endstone.plugin import Plugin class MyPlugin(Plugin): def on_load(self) -> None: self.logger.info("on_load is called!") def on_enable(self) -> None: self.logger.info("on_enable is called!") def on_disable(self) -> None: self.logger.info("on_disable is called!") ``` -------------------------------- ### Run Python Tests with Pytest Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md Execute all Python tests using the pytest framework. ```bash pytest ``` -------------------------------- ### Include Header in C++ Source Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Includes the 'my_plugin.h' header file in the C++ source file to make the 'MyPlugin' class definition available. ```c++ #include "my_plugin.h" ``` -------------------------------- ### Fetch fmt Dependency Source: https://github.com/endstonemc/endstone/blob/main/include/CMakeLists.txt Fetches the fmt library if not found, using a specific Git tag. This ensures a consistent version of the fmt library is used for the build. ```cmake find_package(fmt QUIET) if (NOT fmt_FOUND) FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 11.2.0 ) FetchContent_MakeAvailable(fmt) endif () ``` -------------------------------- ### Add Executable Target for Endstone Tests Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Defines the 'endstone_test' executable target and lists all its source files. This is used to build the main test runner. ```cmake add_executable(endstone_test bedrock/test_actor_definition_identifier.cpp bedrock/test_binary_stream.cpp bedrock/test_block_pos.cpp bedrock/test_check.cpp bedrock/test_function_ref.cpp bedrock/test_hashed_string.cpp bedrock/test_sem_version.cpp bedrock/test_spin_lock.cpp bedrock/test_static_optimized_string.cpp bedrock/test_uuid.cpp test_identifier.cpp test_nbt.cpp test_base64.cpp test_command_lexer.cpp test_command_usage_parser.cpp test_cpp_plugin_loader.cpp test_logger_factory.cpp test_player_ban_list.cpp test_scheduler.cpp test_service_manager.cpp test_thread_pool_executor.cpp test_uuid.cpp test_vector.cpp ) ``` -------------------------------- ### Implement C++ Plugin Lifecycle Methods Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Overrides the onLoad, onEnable, and onDisable methods in the C++ 'MyPlugin' class to log messages when these events occur using the logger. ```c++ #include class MyPlugin : public endstone::Plugin { public: void onLoad() override { getLogger().info("onLoad is called"); } void onEnable() override { getLogger().info("onEnable is called"); } void onDisable() override { getLogger().info("onDisable is called"); } }; ``` -------------------------------- ### Link Libraries to Endstone DevTools Source: https://github.com/endstonemc/endstone/blob/main/src/endstone/core/devtools/CMakeLists.txt Links the endstone_devtools library against its dependencies, including endstone::core, glfw, imgui, and zstr. This ensures the library has access to required functionalities. ```cmake target_link_libraries(endstone_devtools PUBLIC endstone::core glfw imgui::imgui zstr::zstr) ``` -------------------------------- ### Apply Yellow, Aqua, and Gold Colors in Python Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/use-color-codes.md This Python snippet demonstrates how to apply different color formats (yellow, aqua, gold) to text using f-strings and the ColorFormat enum. Remember to use ColorFormat.RESET to end formatting. ```python from endstone import ColorFormat my_beautiful_text = f"This is {ColorFormat.YELLOW}yellow, {ColorFormat.AQUA}aqua and {ColorFormat.GOLD}gold{ColorFormat.RESET}." ``` -------------------------------- ### Fetch expected-lite Dependency Source: https://github.com/endstonemc/endstone/blob/main/include/CMakeLists.txt Fetches the expected-lite library if not found, using a specific Git tag. This ensures a consistent version of the expected-lite library is used for the build. ```cmake find_package(expected-lite QUIET) if (NOT expected-lite_FOUND) FetchContent_Declare( expected-lite GIT_REPOSITORY https://github.com/martinmoene/expected-lite.git GIT_TAG v0.8.0 ) FetchContent_MakeAvailable(expected-lite) endif () ``` -------------------------------- ### Add Permissions to a Command in Python Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-commands.md Specify command permissions using the 'permissions' key within the 'commands' dictionary and define the permission details in the 'permissions' dictionary. ```python from endstone.command import Command, CommandSender from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" commands = { "hello": { "description": "Greet the command sender.", "usages": ["/hello"], "permissions": ["my_plugin.command.hello"], } } permissions = { "my_plugin.command.hello": { "description": "Allow users to use the /hello command.", "default": True, #(1)! } } # ... ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/installation.md Creates a new isolated Python environment named 'venv'. This is recommended for managing project dependencies. ```sh python3 -m venv venv ``` -------------------------------- ### Run Python Tests with Pytest Source: https://github.com/endstonemc/endstone/blob/main/CLAUDE.md Execute Python tests using the pytest command. Specify the test directory. ```shell pytest tests/endstone/python ``` -------------------------------- ### Generate Type Stubs Source: https://github.com/endstonemc/endstone/blob/main/CONTRIBUTING.md Regenerate Python type stub files (.pyi) after modifying bindings. This ensures IDE support and type checking. ```bash python scripts/stubgen.py ``` -------------------------------- ### Write Package Version File Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Generates the raknetConfigVersion.cmake file, which specifies the version of the RakNet package. This is used by CMake to check for compatible versions. ```cmake write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/raknetConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) ``` -------------------------------- ### Define Endstone DevTools Library Source: https://github.com/endstonemc/endstone/blob/main/src/endstone/core/devtools/CMakeLists.txt Creates a static library target for the developer tools, listing all source files. This groups the tool's code for compilation. ```cmake add_library(endstone_devtools imgui_impl_glfw.cpp imgui_impl_opengl3.cpp imgui_json.cpp devtools.cpp devtools_command.cpp vanilla_data.cpp ) ``` -------------------------------- ### Set C++ Standard and Compiler Options Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Configures the C++ standard to C++11 and disables C++ extensions for better portability. It also sets the code to be position-independent, which is crucial for shared libraries. ```cmake set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) ``` -------------------------------- ### Discover Tests with Google Test Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Enables Google Test's test discovery mechanism for the 'endstone_test' executable. This allows CMake to automatically find and list all tests defined within the executable. ```cmake gtest_discover_tests(endstone_test) ``` -------------------------------- ### Create Alias Target for DevTools Source: https://github.com/endstonemc/endstone/blob/main/src/endstone/core/devtools/CMakeLists.txt Creates an alias for the endstone_devtools library. This allows for cleaner referencing in other CMake files. ```cmake add_library(endstone::devtools ALIAS endstone_devtools) ``` -------------------------------- ### Define C++ Plugin Class Header Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/create-your-first-plugin.md Declares the main C++ plugin class 'MyPlugin' which inherits from 'endstone::Plugin'. This header file defines the class structure. ```c++ #include class MyPlugin : public endstone::Plugin {}; ``` -------------------------------- ### Add Endstone Plugin Target Source: https://github.com/endstonemc/endstone/blob/main/tests/CMakeLists.txt Adds a new plugin target named 'test_plugin' using the specified source file. This is used for building Endstone plugins. ```cmake endstone_add_plugin(test_plugin test_plugin.cpp) ``` -------------------------------- ### C++ Player Join Event Handler Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-event-listeners.md Defines a method to handle PlayerJoinEvent in a C++ Endstone plugin. This method is declared within the plugin class. ```c++ #include class MyPlugin : public endstone::Plugin { public: // ... void onEnable() { getLogger().info("onEnable is called"); } void onPlayerJoin(endstone::PlayerJoinEvent& event) { getServer().broadcastMessage(ColorFormat::Yellow + "{} has joined the server", event.getPlayer().getName()); } }; ``` -------------------------------- ### Configure RakNet Build Type Option Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Defines a CMake option to control whether RakNet is built as a shared or static library. The default is OFF, meaning it builds as a static library. ```cmake option(RAKNET_BUILD_SHARED "Build RakNet as a shared library." OFF) ``` -------------------------------- ### Python Registering Event Handlers Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-event-listeners.md Registers all methods decorated with @event_handler within the plugin instance to the Endstone event system. Call this within the on_enable method. ```python from endstone import ColorFormat from endstone.event import event_handler, PlayerJoinEvent from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" # ... def on_enable(self) -> None: self.logger.info("on_enable is called!") self.register_events(self) @event_handler def on_player_join(self, event: PlayerJoinEvent): self.server.broadcast_message(ColorFormat.YELLOW + f"{event.player.name} has joined the server") ``` -------------------------------- ### Set RakNet Output Name Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Sets the output name for the RakNet library. This ensures the library file is named 'raknet' regardless of the build type or platform. ```cmake set_target_properties(raknet PROPERTIES OUTPUT_NAME raknet) ``` -------------------------------- ### Schedule Task in Python Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/schedule-tasks.md Schedules a task to send a popup message to all online players every 20 ticks (approximately 1 second). This snippet is intended for use within an Endstone plugin's on_enable method. ```python from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" # ... def on_enable(self) -> None: self.logger.info("on_enable is called!") self.server.scheduler.run_task(self, self.say_hi, delay=0, period=20) def say_hi(self) -> None: for player in self.server.online_players: player.send_popup("Hi!") ``` -------------------------------- ### Python Player Join Event Handler Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/register-event-listeners.md Defines a method to handle PlayerJoinEvent in a Python Endstone plugin. This method is decorated with @event_handler. ```python from endstone import ColorFormat from endstone.event import event_handler, PlayerJoinEvent from endstone.plugin import Plugin class MyPlugin(Plugin): api_version = "{{ git.short_tag[1:].rsplit('.', 1)[0] }}" # ... def on_enable(self) -> None: self.logger.info("on_enable is called!") @event_handler def on_player_join(self, event: PlayerJoinEvent): self.server.broadcast_message(ColorFormat.YELLOW + f"{event.player.name} has joined the server") ``` -------------------------------- ### Apply Dark Green Color in C++ Source: https://github.com/endstonemc/endstone/blob/main/docs/tutorials/use-color-codes.md This C++ snippet shows how to apply the dark green color format to text using the endstone::ColorFormat enum. Ensure to use endstone::ColorFormat::Reset to end formatting. ```cpp #include auto my_beautiful_text = "This is " + endstone::ColorFormat::DarkGreen + "dark green." + endstone::ColorFormat::Reset; ``` -------------------------------- ### Pull Endstone Docker Image (Latest) Source: https://github.com/endstonemc/endstone/blob/main/docs/getting-started/installation.md Pulls the latest official Endstone Docker image from Docker Hub. This allows for running Endstone in a containerized environment. ```docker docker pull endstone/endstone ``` -------------------------------- ### Glob Source and Header Files Source: https://github.com/endstonemc/endstone/blob/main/recipes/raknet/all/cmake/CMakeLists.txt Uses file globbing to find all .cpp and .h files in the Source directory. CONFIGURE_DEPENDS ensures that CMake re-runs globbing if files are added or removed during the configuration process. ```cmake file(GLOB RAKNET_SRCS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.cpp") file(GLOB RAKNET_HDRS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.h") ```