From c80b4608079536ec56538a576daf5f593c02dfa9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 3 Mar 2024 16:45:46 +0000 Subject: [PATCH] feat: add MinecraftCommands class --- .../bedrock/command/command_output_sender.h | 17 +++++++++ include/bedrock/command/minecraft_commands.h | 38 +++++++++++++++++++ .../dedicated_server.h => minecraft.h} | 16 ++------ src/endstone_runtime/bedrock/minecraft.cpp | 24 ++++++++++++ 4 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 include/bedrock/command/command_output_sender.h create mode 100644 include/bedrock/command/minecraft_commands.h rename include/bedrock/{server/dedicated_server.h => minecraft.h} (54%) create mode 100644 src/endstone_runtime/bedrock/minecraft.cpp diff --git a/include/bedrock/command/command_output_sender.h b/include/bedrock/command/command_output_sender.h new file mode 100644 index 000000000..898f9dbfd --- /dev/null +++ b/include/bedrock/command/command_output_sender.h @@ -0,0 +1,17 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +class CommandOutputSender {}; diff --git a/include/bedrock/command/minecraft_commands.h b/include/bedrock/command/minecraft_commands.h new file mode 100644 index 000000000..64f08582d --- /dev/null +++ b/include/bedrock/command/minecraft_commands.h @@ -0,0 +1,38 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "bedrock/command/command_output_sender.h" +#include "bedrock/command/command_registry.h" + +class MinecraftCommands { +public: + virtual ~MinecraftCommands() = default; + + [[nodiscard]] CommandOutputSender &getOutputSender() const + { + return *output_sender_; + } + + [[nodiscard]] CommandRegistry &getRegistry() const + { + return *registry_; + } + +private: + std::unique_ptr output_sender_; + std::unique_ptr registry_; +}; +static_assert(sizeof(MinecraftCommands) == 24); diff --git a/include/bedrock/server/dedicated_server.h b/include/bedrock/minecraft.h similarity index 54% rename from include/bedrock/server/dedicated_server.h rename to include/bedrock/minecraft.h index 72f36b963..0ce24cd80 100644 --- a/include/bedrock/server/dedicated_server.h +++ b/include/bedrock/minecraft.h @@ -1,4 +1,4 @@ -// Copyright (c) 2023, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,17 +14,9 @@ #pragma once -#include +#include "bedrock/command/minecraft_commands.h" -#include "bedrock/bedrock.h" -#include "bedrock/core.h" - -class DedicatedServer { +class Minecraft { public: - enum class StartResult; - - BEDROCK_API DedicatedServer::StartResult runDedicatedServerLoop( - Core::FilePathManager &file_path_manager, class PropertiesSettings &properties_settings, - class LevelSettings &level_settings, class AllowListFile &allow_list_file, - class std::unique_ptr &permissions_file); + MinecraftCommands &getCommands(); }; diff --git a/src/endstone_runtime/bedrock/minecraft.cpp b/src/endstone_runtime/bedrock/minecraft.cpp new file mode 100644 index 000000000..b32241476 --- /dev/null +++ b/src/endstone_runtime/bedrock/minecraft.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bedrock/minecraft.h" + +MinecraftCommands &Minecraft::getCommands() +{ +#ifdef __linux__ + return *reinterpret_cast(reinterpret_cast(this) + 22); +#elif _WIN32 + return *reinterpret_cast(reinterpret_cast(this) + 23); +#endif +}