diff --git a/include/endstone_core/endstone_server.h b/include/endstone/detail/endstone_server.h similarity index 93% rename from include/endstone_core/endstone_server.h rename to include/endstone/detail/endstone_server.h index 08d77fcb1..c7c2afa60 100644 --- a/include/endstone_core/endstone_server.h +++ b/include/endstone/detail/endstone_server.h @@ -18,11 +18,11 @@ #include #include - - +#include "endstone/detail/plugin/endstone_plugin_manager.h" #include "endstone/plugin/plugin_manager.h" #include "endstone/server.h" -#include "endstone_core/plugin/endstone_plugin_manager.h" + +namespace endstone::detail { class EndstoneServer : public Server { public: @@ -55,3 +55,5 @@ class EndstoneServer : public Server { Logger &logger_; std::unique_ptr plugin_manager_; }; + +} // namespace endstone::detail diff --git a/include/endstone_runtime/hook.h b/include/endstone/detail/hook.h similarity index 91% rename from include/endstone_runtime/hook.h rename to include/endstone/detail/hook.h index bd8013a92..1493de3f6 100644 --- a/include/endstone_runtime/hook.h +++ b/include/endstone/detail/hook.h @@ -17,12 +17,12 @@ #include #include -namespace endstone::hook { +namespace endstone::detail::hook { void install(); const std::error_category &hook_error_category() noexcept; -} // namespace endstone::hook +} // namespace endstone::detail::hook -namespace endstone::hook::detail { +namespace endstone::detail::hook { /** * @brief Cast a function pointer to void pointer @@ -88,13 +88,13 @@ void *fp_cast(Return (Class::*fp)(Args...) const) temp.p = fp; return temp.v; } -} // namespace endstone::hook::detail +} // namespace endstone::detail::hook -namespace endstone::hook::detail { +namespace endstone::detail::hook { void *get_original(void *detour); } -namespace endstone::hook::detail { +namespace endstone::detail::hook { /** * @brief Construct a std::function from a function pointer */ @@ -127,10 +127,10 @@ inline std::function get_original(Return (Class:: return func(obj, std::forward(args)...); }; } -} // namespace endstone::hook::detail -#define ENDSTONE_HOOK_CALL_ORIGINAL(fp, ...) endstone::hook::detail::get_original(fp)(__VA_ARGS__) +} // namespace endstone::detail::hook +#define ENDSTONE_HOOK_CALL_ORIGINAL(fp, ...) endstone::detail::hook::get_original(fp)(__VA_ARGS__) -namespace endstone::hook::detail { +namespace endstone::detail::hook { /** * @brief Construct a std::function from a function pointer * with Return Value Optimization (RVO). @@ -180,6 +180,7 @@ inline std::function get_original_rvo }; #endif } -} // namespace endstone::hook::detail +} // namespace endstone::detail::hook -#define ENDSTONE_HOOK_CALL_ORIGINAL_RVO(fp, ret, ...) ret = *endstone::hook::detail::get_original_rvo(fp)(&ret, __VA_ARGS__) +#define ENDSTONE_HOOK_CALL_ORIGINAL_RVO(fp, ret, ...) \ + ret = *endstone::detail::hook::get_original_rvo(fp)(&ret, __VA_ARGS__) diff --git a/include/endstone_core/logger_factory.h b/include/endstone/detail/logger_factory.h similarity index 92% rename from include/endstone_core/logger_factory.h rename to include/endstone/detail/logger_factory.h index 97bc51645..e48dfbcc5 100644 --- a/include/endstone_core/logger_factory.h +++ b/include/endstone/detail/logger_factory.h @@ -20,7 +20,11 @@ #include "endstone/logger.h" +namespace endstone::detail { + class LoggerFactory { public: static Logger &getLogger(const std::string &name); }; + +} // namespace endstone::detail diff --git a/include/endstone_runtime/platform.h b/include/endstone/detail/os.h similarity index 92% rename from include/endstone_runtime/platform.h rename to include/endstone/detail/os.h index f020527e9..2d5f02c5e 100644 --- a/include/endstone_runtime/platform.h +++ b/include/endstone/detail/os.h @@ -17,11 +17,11 @@ #include #include -namespace endstone::platform { +namespace endstone::detail::os { void *get_module_base(); std::string get_module_pathname(); void *get_executable_base(); std::string get_executable_pathname(); -} // namespace endstone::platform +} // namespace endstone::detail::os diff --git a/include/endstone_core/plugin/cpp_plugin_loader.h b/include/endstone/detail/plugin/cpp_plugin_loader.h similarity index 92% rename from include/endstone_core/plugin/cpp_plugin_loader.h rename to include/endstone/detail/plugin/cpp_plugin_loader.h index 0929dd322..652866306 100644 --- a/include/endstone_core/plugin/cpp_plugin_loader.h +++ b/include/endstone/detail/plugin/cpp_plugin_loader.h @@ -20,6 +20,9 @@ #include "endstone/plugin/plugin_loader.h" +namespace endstone { +namespace detail { + class CppPluginLoader : public PluginLoader { public: using PluginLoader::PluginLoader; @@ -31,3 +34,6 @@ class CppPluginLoader : public PluginLoader { private: std::vector> plugins_; }; + +} // namespace detail +} // namespace endstone diff --git a/include/endstone_core/plugin/endstone_plugin_manager.h b/include/endstone/detail/plugin/endstone_plugin_manager.h similarity index 96% rename from include/endstone_core/plugin/endstone_plugin_manager.h rename to include/endstone/detail/plugin/endstone_plugin_manager.h index 83cfb1ff2..ad14b3043 100644 --- a/include/endstone_core/plugin/endstone_plugin_manager.h +++ b/include/endstone/detail/plugin/endstone_plugin_manager.h @@ -23,6 +23,8 @@ #include "endstone/plugin/plugin_manager.h" #include "endstone/server.h" +namespace endstone::detail { + class EndstonePluginManager : public PluginManager { public: explicit EndstonePluginManager(Server &server); @@ -44,3 +46,5 @@ class EndstonePluginManager : public PluginManager { std::vector plugins_; std::unordered_map lookup_names_; }; + +} // namespace endstone::detail diff --git a/include/endstone_runtime/python_plugin_loader.h b/include/endstone/detail/plugin/python_plugin_loader.h similarity index 95% rename from include/endstone_runtime/python_plugin_loader.h rename to include/endstone/detail/plugin/python_plugin_loader.h index cb3c92226..902061155 100644 --- a/include/endstone_runtime/python_plugin_loader.h +++ b/include/endstone/detail/plugin/python_plugin_loader.h @@ -20,6 +20,8 @@ #include "endstone/plugin/plugin_loader.h" +namespace endstone::detail { + class PythonPluginLoader : public PluginLoader { public: explicit PythonPluginLoader(Server &server); @@ -35,3 +37,5 @@ class PythonPluginLoader : public PluginLoader { pybind11::object obj_; pybind11::gil_scoped_release release_; }; + +} // namespace endstone::detail diff --git a/include/endstone_python/endstone_python.h b/include/endstone/detail/python.h similarity index 65% rename from include/endstone_python/endstone_python.h rename to include/endstone/detail/python.h index 12bfb4ce0..d17bc01f8 100644 --- a/include/endstone_python/endstone_python.h +++ b/include/endstone/detail/python.h @@ -16,12 +16,14 @@ #include -namespace py = pybind11; +namespace endstone::detail { -void def_color_format(py::module &m); -void def_logger(py::module &m); -void def_server(py::module &m); -void def_plugin(py::module &m); -void def_plugin_description(py::module &m); -void def_plugin_loader(py::module &m); -void def_plugin_manager(py::module &m); +void def_color_format(pybind11::module &m); +void def_logger(pybind11::module &m); +void def_server(pybind11::module &m); +void def_plugin(pybind11::module &m); +void def_plugin_description(pybind11::module &m); +void def_plugin_loader(pybind11::module &m); +void def_plugin_manager(pybind11::module &m); + +} // namespace endstone::detail diff --git a/include/endstone_core/spdlog/bedrock_level_formatter.h b/include/endstone/detail/spdlog/bedrock_level_formatter.h similarity index 93% rename from include/endstone_core/spdlog/bedrock_level_formatter.h rename to include/endstone/detail/spdlog/bedrock_level_formatter.h index 5a4d81201..f80c3a675 100644 --- a/include/endstone_core/spdlog/bedrock_level_formatter.h +++ b/include/endstone/detail/spdlog/bedrock_level_formatter.h @@ -17,9 +17,13 @@ #include #include +namespace endstone::detail { + class BedrockLevelFormatter : public spdlog::custom_flag_formatter { public: void format(const spdlog::details::log_msg &msg, const std::tm &, spdlog::memory_buf_t &dest) override; [[nodiscard]] std::unique_ptr clone() const override; }; + +} // namespace endstone::detail diff --git a/include/endstone_core/spdlog/bedrock_log_sink.h b/include/endstone/detail/spdlog/bedrock_log_sink.h similarity index 97% rename from include/endstone_core/spdlog/bedrock_log_sink.h rename to include/endstone/detail/spdlog/bedrock_log_sink.h index 7e1b13d6a..50d4807a1 100644 --- a/include/endstone_core/spdlog/bedrock_log_sink.h +++ b/include/endstone/detail/spdlog/bedrock_log_sink.h @@ -22,6 +22,8 @@ #include #include +namespace endstone::detail { + class BedrockLogSink : public spdlog::sinks::base_sink { public: explicit BedrockLogSink(FILE *target_file, spdlog::color_mode mode = spdlog::color_mode::automatic); @@ -76,3 +78,5 @@ class BedrockLogSink : public spdlog::sinks::base_sink colors_; }; + +} // namespace endstone::detail diff --git a/include/endstone_core/spdlog/bedrock_text_formatter.h b/include/endstone/detail/spdlog/bedrock_text_formatter.h similarity index 98% rename from include/endstone_core/spdlog/bedrock_text_formatter.h rename to include/endstone/detail/spdlog/bedrock_text_formatter.h index 01a74533c..5260dbf75 100644 --- a/include/endstone_core/spdlog/bedrock_text_formatter.h +++ b/include/endstone/detail/spdlog/bedrock_text_formatter.h @@ -19,6 +19,8 @@ #include "endstone/util/color_format.h" +namespace endstone::detail { + class BedrockTextFormatter : public spdlog::custom_flag_formatter { public: explicit BedrockTextFormatter(bool should_do_colors) : should_do_colors_(should_do_colors){}; @@ -67,3 +69,5 @@ class BedrockTextFormatter : public spdlog::custom_flag_formatter { bool should_do_colors_; }; + +} // namespace endstone::detail diff --git a/include/endstone_core/spdlog/spdlog_adapter.h b/include/endstone/detail/spdlog/spdlog_adapter.h similarity index 94% rename from include/endstone_core/spdlog/spdlog_adapter.h rename to include/endstone/detail/spdlog/spdlog_adapter.h index 280ff63b6..63e115313 100644 --- a/include/endstone_core/spdlog/spdlog_adapter.h +++ b/include/endstone/detail/spdlog/spdlog_adapter.h @@ -18,6 +18,8 @@ #include "endstone/logger.h" +namespace endstone::detail { + class SpdLogAdapter : public Logger { public: explicit SpdLogAdapter(std::shared_ptr logger); @@ -29,3 +31,5 @@ class SpdLogAdapter : public Logger { private: std::shared_ptr logger_; }; + +} // namespace endstone::detail diff --git a/include/endstone/logger.h b/include/endstone/logger.h index 015f61be5..40e7a708f 100644 --- a/include/endstone/logger.h +++ b/include/endstone/logger.h @@ -19,6 +19,8 @@ #include +namespace endstone { + class Logger { public: /** @@ -84,3 +86,5 @@ class Logger { log(Level::Critical, fmt::format(format, std::forward(args)...)); } }; + +} // namespace endstone diff --git a/include/endstone/plugin/plugin.h b/include/endstone/plugin/plugin.h index 529d21c68..7c7271da4 100644 --- a/include/endstone/plugin/plugin.h +++ b/include/endstone/plugin/plugin.h @@ -23,6 +23,8 @@ #include "endstone/plugin/plugin_description.h" #include "endstone/server.h" +namespace endstone { + class PluginLoader; class Plugin { @@ -123,6 +125,7 @@ class Plugin { Server *server_ = nullptr; Logger *logger_ = nullptr; }; +} // namespace endstone #ifndef ENDSTONE_PLUGIN #if defined(WIN32) diff --git a/include/endstone/plugin/plugin_description.h b/include/endstone/plugin/plugin_description.h index 6b462aa16..352c6f93a 100644 --- a/include/endstone/plugin/plugin_description.h +++ b/include/endstone/plugin/plugin_description.h @@ -24,6 +24,8 @@ #include +namespace endstone { + class PluginDescription { public: PluginDescription(std::string name, std::string version, std::optional description = std::nullopt, @@ -79,3 +81,5 @@ class PluginDescription { std::optional> authors_; std::optional prefix_; }; + +} // namespace endstone diff --git a/include/endstone/plugin/plugin_loader.h b/include/endstone/plugin/plugin_loader.h index 1873dc895..86663b2f8 100644 --- a/include/endstone/plugin/plugin_loader.h +++ b/include/endstone/plugin/plugin_loader.h @@ -22,6 +22,8 @@ #include "endstone/plugin/plugin.h" #include "endstone/server.h" +namespace endstone { + class PluginLoader { public: explicit PluginLoader(Server &server) noexcept : server_(server) {} @@ -63,3 +65,5 @@ class PluginLoader { private: Server &server_; }; + +} // namespace endstone diff --git a/include/endstone/plugin/plugin_manager.h b/include/endstone/plugin/plugin_manager.h index 3916a865e..e5a92d767 100644 --- a/include/endstone/plugin/plugin_manager.h +++ b/include/endstone/plugin/plugin_manager.h @@ -21,6 +21,8 @@ #include "endstone/plugin/plugin.h" #include "endstone/plugin/plugin_loader.h" +namespace endstone { + class PluginManager { public: PluginManager() = default; @@ -38,3 +40,5 @@ class PluginManager { virtual void disablePlugins() const = 0; virtual void clearPlugins() = 0; }; + +} // namespace endstone diff --git a/include/endstone/server.h b/include/endstone/server.h index 525158b4f..6c09dc649 100644 --- a/include/endstone/server.h +++ b/include/endstone/server.h @@ -20,6 +20,8 @@ #include "endstone/logger.h" +namespace endstone { + class PluginManager; /** @@ -61,3 +63,5 @@ class Server { */ [[nodiscard]] virtual std::string getMinecraftVersion() const = 0; }; + +} // namespace endstone diff --git a/include/endstone/util/color_format.h b/include/endstone/util/color_format.h index da02e9134..cc6871009 100644 --- a/include/endstone/util/color_format.h +++ b/include/endstone/util/color_format.h @@ -16,6 +16,8 @@ #include +namespace endstone { + struct ColorFormat { // Escape inline static const std::string ESCAPE = "ยง"; @@ -55,3 +57,5 @@ struct ColorFormat { inline static const std::string ITALIC = ESCAPE + 'o'; inline static const std::string RESET = ESCAPE + 'r'; }; + +} // namespace endstone diff --git a/src/endstone_core/endstone_server.cpp b/src/endstone_core/endstone_server.cpp index 5a98b89c8..7259d0dbb 100644 --- a/src/endstone_core/endstone_server.cpp +++ b/src/endstone_core/endstone_server.cpp @@ -12,20 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/endstone_server.h" +#include "endstone/detail/endstone_server.h" #include #include namespace fs = std::filesystem; #include "bedrock/common.h" -#include "endstone_core/logger_factory.h" -#include "endstone_core/plugin/cpp_plugin_loader.h" +#include "endstone/detail/logger_factory.h" +#include "endstone/detail/plugin/cpp_plugin_loader.h" #if !defined(ENDSTONE_VERSION) #error ENDSTONE_VERSION is not defined #endif +namespace endstone::detail { + EndstoneServer::EndstoneServer() : logger_(LoggerFactory::getLogger("EndstoneServer")) { plugin_manager_ = std::make_unique(*this); @@ -87,3 +89,5 @@ std::string EndstoneServer::getMinecraftVersion() const { return Common::getGameVersionString(); } + +} // namespace endstone::detail diff --git a/src/endstone_core/logger_factory.cpp b/src/endstone_core/logger_factory.cpp index 8b1b1865c..70e204615 100644 --- a/src/endstone_core/logger_factory.cpp +++ b/src/endstone_core/logger_factory.cpp @@ -12,14 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/logger_factory.h" +#include "endstone/detail/logger_factory.h" #include #include #include -#include "endstone_core/spdlog/bedrock_log_sink.h" -#include "endstone_core/spdlog/spdlog_adapter.h" +#include "endstone/detail/spdlog/bedrock_log_sink.h" +#include "endstone/detail/spdlog/spdlog_adapter.h" + +namespace endstone::detail { Logger &LoggerFactory::getLogger(const std::string &name) { @@ -38,3 +40,5 @@ Logger &LoggerFactory::getLogger(const std::string &name) it = loggers.emplace(name, SpdLogAdapter(console)).first; return it->second; } + +} // namespace endstone::detail diff --git a/src/endstone_core/plugin/cpp_plugin_loader.cpp b/src/endstone_core/plugin/cpp_plugin_loader.cpp index 89166847f..d554dbbfd 100644 --- a/src/endstone_core/plugin/cpp_plugin_loader.cpp +++ b/src/endstone_core/plugin/cpp_plugin_loader.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/plugin/cpp_plugin_loader.h" +#include "endstone/detail/plugin/cpp_plugin_loader.h" #ifdef _WIN32 #include @@ -23,9 +23,11 @@ #include namespace fs = std::filesystem; +#include "endstone/detail/endstone_server.h" +#include "endstone/detail/logger_factory.h" #include "endstone/plugin/plugin.h" -#include "endstone_core/endstone_server.h" -#include "endstone_core/logger_factory.h" + +namespace endstone::detail { std::vector CppPluginLoader::loadPlugins(const std::string &directory) noexcept { @@ -153,3 +155,5 @@ std::vector CppPluginLoader::getPluginFileFilters() const } #endif + +} // namespace endstone::detail diff --git a/src/endstone_core/plugin/endstone_plugin_manager.cpp b/src/endstone_core/plugin/endstone_plugin_manager.cpp index 8c79e363e..4e9ee5d06 100644 --- a/src/endstone_core/plugin/endstone_plugin_manager.cpp +++ b/src/endstone_core/plugin/endstone_plugin_manager.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/plugin/endstone_plugin_manager.h" +#include "endstone/detail/plugin/endstone_plugin_manager.h" #include #include @@ -23,6 +23,8 @@ #include "endstone/plugin/plugin_loader.h" #include "endstone/server.h" +namespace endstone::detail { + EndstonePluginManager::EndstonePluginManager(Server &server) : server_(server) {} void EndstonePluginManager::registerLoader(std::unique_ptr loader) @@ -121,3 +123,5 @@ void EndstonePluginManager::clearPlugins() plugins_.clear(); lookup_names_.clear(); } + +} // namespace endstone::detail diff --git a/src/endstone_core/spdlog/bedrock_level_formatter.cpp b/src/endstone_core/spdlog/bedrock_level_formatter.cpp index 66df9469d..fa2c43826 100644 --- a/src/endstone_core/spdlog/bedrock_level_formatter.cpp +++ b/src/endstone_core/spdlog/bedrock_level_formatter.cpp @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/spdlog/bedrock_level_formatter.h" +#include "endstone/detail/spdlog/bedrock_level_formatter.h" #include +namespace endstone::detail { + void BedrockLevelFormatter::format(const spdlog::details::log_msg &msg, const tm &, spdlog::memory_buf_t &dest) { static const std::unordered_map level_names = { @@ -32,3 +34,5 @@ std::unique_ptr BedrockLevelFormatter::clone() co { return spdlog::details::make_unique(); } + +} // namespace endstone::detail diff --git a/src/endstone_core/spdlog/bedrock_log_sink.cpp b/src/endstone_core/spdlog/bedrock_log_sink.cpp index bc6f5ad9b..2e088b3cf 100644 --- a/src/endstone_core/spdlog/bedrock_log_sink.cpp +++ b/src/endstone_core/spdlog/bedrock_log_sink.cpp @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/spdlog/bedrock_log_sink.h" +#include "endstone/detail/spdlog/bedrock_log_sink.h" #include #include -#include "endstone_core/spdlog/bedrock_level_formatter.h" -#include "endstone_core/spdlog/bedrock_text_formatter.h" +#include "endstone/detail/spdlog/bedrock_level_formatter.h" +#include "endstone/detail/spdlog/bedrock_text_formatter.h" + +namespace endstone::detail { BedrockLogSink::BedrockLogSink(FILE *target_file, spdlog::color_mode mode) : target_file_(target_file), spdlog::sinks::base_sink( @@ -95,3 +97,5 @@ void BedrockLogSink::printRange(const spdlog::memory_buf_t &formatted, size_t st { fwrite(formatted.data() + start, sizeof(char), end - start, target_file_); } + +} // namespace endstone::detail diff --git a/src/endstone_core/spdlog/bedrock_text_formatter.cpp b/src/endstone_core/spdlog/bedrock_text_formatter.cpp index a197df92d..e185a24ce 100644 --- a/src/endstone_core/spdlog/bedrock_text_formatter.cpp +++ b/src/endstone_core/spdlog/bedrock_text_formatter.cpp @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/spdlog/bedrock_text_formatter.h" +#include "endstone/detail//spdlog/bedrock_text_formatter.h" #include +namespace endstone::detail { + void BedrockTextFormatter::format(const spdlog::details::log_msg &msg, const tm &, spdlog::memory_buf_t &dest) { @@ -49,3 +51,5 @@ std::unique_ptr BedrockTextFormatter::clone() con { return spdlog::details::make_unique(should_do_colors_); } + +} // namespace endstone::detail diff --git a/src/endstone_core/spdlog/spdlog_adapter.cpp b/src/endstone_core/spdlog/spdlog_adapter.cpp index a2e60c131..5e43bf65b 100644 --- a/src/endstone_core/spdlog/spdlog_adapter.cpp +++ b/src/endstone_core/spdlog/spdlog_adapter.cpp @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_core/spdlog/spdlog_adapter.h" +#include "endstone/detail/spdlog/spdlog_adapter.h" + +namespace endstone::detail { SpdLogAdapter::SpdLogAdapter(std::shared_ptr logger) : logger_(std::move(logger)) {} @@ -37,3 +39,5 @@ std::string_view SpdLogAdapter::getName() const { return logger_->name(); } + +} // namespace endstone::detail diff --git a/src/endstone_python/color_format.cpp b/src/endstone_python/python/color_format.cpp similarity index 94% rename from src/endstone_python/color_format.cpp rename to src/endstone_python/python/color_format.cpp index 9ec0a1797..ff13ce1ff 100644 --- a/src/endstone_python/color_format.cpp +++ b/src/endstone_python/python/color_format.cpp @@ -14,10 +14,14 @@ #include "endstone/util/color_format.h" -#include "endstone_python/endstone_python.h" +#include "endstone/detail/python.h" + +namespace py = pybind11; #define ADD_COLOR_FORMAT(Name) def_property_readonly_static(#Name, [](const py::object &) { return ColorFormat::Name; }) +namespace endstone::detail { + void def_color_format(py::module &m) { py::class_(m, "ColorFormat") @@ -53,3 +57,5 @@ void def_color_format(py::module &m) .ADD_COLOR_FORMAT(ITALIC) .ADD_COLOR_FORMAT(RESET); } + +} // namespace endstone::detail diff --git a/src/endstone_python/endstone_python.cpp b/src/endstone_python/python/endstone_python.cpp similarity index 90% rename from src/endstone_python/endstone_python.cpp rename to src/endstone_python/python/endstone_python.cpp index 4733c17d9..efdc0f92c 100644 --- a/src/endstone_python/endstone_python.cpp +++ b/src/endstone_python/python/endstone_python.cpp @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_python/endstone_python.h" - #include +#include "endstone/detail/python.h" + +namespace endstone::detail { + PYBIND11_MODULE(endstone_python, m) // NOLINT(*-use-anonymous-namespace) { def_color_format(m); @@ -26,3 +28,5 @@ PYBIND11_MODULE(endstone_python, m) // NOLINT(*-use-anonymous-namespace) def_plugin_manager(m); def_server(m); } + +} // namespace endstone::detail diff --git a/src/endstone_python/logger.cpp b/src/endstone_python/python/logger.cpp similarity index 95% rename from src/endstone_python/logger.cpp rename to src/endstone_python/python/logger.cpp index d768a0bcc..aebb96c48 100644 --- a/src/endstone_python/logger.cpp +++ b/src/endstone_python/python/logger.cpp @@ -16,10 +16,12 @@ #include -#include "endstone_python/endstone_python.h" +#include "endstone/detail/python.h" namespace py = pybind11; +namespace endstone::detail { + void def_logger(py::module &m) { auto logger = // @@ -54,3 +56,5 @@ void def_logger(py::module &m) .value("CRITICAL", Logger::Level::Critical) .export_values(); } + +} // namespace endstone::detail diff --git a/src/endstone_python/plugin/plugin.cpp b/src/endstone_python/python/plugin/plugin.cpp similarity index 96% rename from src/endstone_python/plugin/plugin.cpp rename to src/endstone_python/python/plugin/plugin.cpp index ed6f77d9d..aa9c1f92b 100644 --- a/src/endstone_python/plugin/plugin.cpp +++ b/src/endstone_python/python/plugin/plugin.cpp @@ -16,13 +16,15 @@ #include +#include "endstone/detail/python.h" #include "endstone/logger.h" #include "endstone/plugin/plugin_loader.h" #include "endstone/server.h" -#include "endstone_python/endstone_python.h" namespace py = pybind11; +namespace endstone::detail { + class PyPlugin : public Plugin { public: using Plugin::Plugin; @@ -85,3 +87,5 @@ void def_plugin(py::module &m) .def_property_readonly("server", &Plugin::getServer, py::return_value_policy::reference) .def_property_readonly("enabled", &Plugin::isEnabled); } + +} // namespace endstone::detail diff --git a/src/endstone_python/plugin/plugin_description.cpp b/src/endstone_python/python/plugin/plugin_description.cpp similarity index 94% rename from src/endstone_python/plugin/plugin_description.cpp rename to src/endstone_python/python/plugin/plugin_description.cpp index 42cb4ab10..a1a4dbe45 100644 --- a/src/endstone_python/plugin/plugin_description.cpp +++ b/src/endstone_python/python/plugin/plugin_description.cpp @@ -19,13 +19,16 @@ #include #include +#include "endstone/detail/python.h" #include "endstone/logger.h" #include "endstone/plugin/plugin.h" #include "endstone/server.h" -#include "endstone_python/endstone_python.h" namespace py = pybind11; +namespace endstone::detail { + +namespace { PluginDescription createPluginDescription(std::string name, std::string version, std::optional description, std::optional> authors, std::optional prefix, const py::args & /*args*/, @@ -33,6 +36,7 @@ PluginDescription createPluginDescription(std::string name, std::string version, { return {std::move(name), std::move(version), std::move(description), std::move(authors), std::move(prefix)}; } +} // namespace void def_plugin_description(py::module &m) { @@ -46,3 +50,5 @@ void def_plugin_description(py::module &m) .def_property_readonly("authors", &PluginDescription::getAuthors) .def_property_readonly("prefix", &PluginDescription::getPrefix); } + +} // namespace endstone::detail diff --git a/src/endstone_python/plugin/plugin_loader.cpp b/src/endstone_python/python/plugin/plugin_loader.cpp similarity index 95% rename from src/endstone_python/plugin/plugin_loader.cpp rename to src/endstone_python/python/plugin/plugin_loader.cpp index ca962d7a2..9a99f372e 100644 --- a/src/endstone_python/plugin/plugin_loader.cpp +++ b/src/endstone_python/python/plugin/plugin_loader.cpp @@ -17,13 +17,15 @@ #include #include +#include "endstone/detail/python.h" #include "endstone/logger.h" #include "endstone/plugin/plugin.h" #include "endstone/server.h" -#include "endstone_python/endstone_python.h" namespace py = pybind11; +namespace endstone::detail { + class PyPluginLoader : public PluginLoader { public: using PluginLoader::PluginLoader; @@ -52,3 +54,5 @@ void def_plugin_loader(py::module &m) .def("disable_plugin", &PluginLoader::enablePlugin, py::arg("plugin")) .def_property_readonly("server", &PluginLoader::getServer, py::return_value_policy::reference); } + +} // namespace endstone::detail diff --git a/src/endstone_python/plugin/plugin_manager.cpp b/src/endstone_python/python/plugin/plugin_manager.cpp similarity index 94% rename from src/endstone_python/plugin/plugin_manager.cpp rename to src/endstone_python/python/plugin/plugin_manager.cpp index a6252dbe7..0e2197362 100644 --- a/src/endstone_python/plugin/plugin_manager.cpp +++ b/src/endstone_python/python/plugin/plugin_manager.cpp @@ -17,13 +17,15 @@ #include #include +#include "endstone/detail/python.h" #include "endstone/logger.h" #include "endstone/plugin/plugin.h" #include "endstone/server.h" -#include "endstone_python/endstone_python.h" namespace py = pybind11; +namespace endstone::detail { + void def_plugin_manager(py::module &m) { py::class_(m, "PluginManager") @@ -39,3 +41,5 @@ void def_plugin_manager(py::module &m) .def("disable_plugins", &PluginManager::disablePlugins) .def("clear_plugins", &PluginManager::clearPlugins); } + +} // namespace endstone::detail diff --git a/src/endstone_python/server.cpp b/src/endstone_python/python/server.cpp similarity index 92% rename from src/endstone_python/server.cpp rename to src/endstone_python/python/server.cpp index 681965246..69940d585 100644 --- a/src/endstone_python/server.cpp +++ b/src/endstone_python/python/server.cpp @@ -17,12 +17,14 @@ #include #include +#include "endstone/detail/python.h" #include "endstone/logger.h" #include "endstone/plugin/plugin_manager.h" -#include "endstone_python/endstone_python.h" namespace py = pybind11; +namespace endstone::detail { + void def_server(py::module &m) { py::class_(m, "Server") @@ -31,3 +33,5 @@ void def_server(py::module &m) .def_property_readonly("version", &Server::getVersion) .def_property_readonly("minecraft_version", &Server::getMinecraftVersion); } + +} // namespace endstone::detail diff --git a/src/endstone_runtime/bedrock/bedrock_log.cpp b/src/endstone_runtime/bedrock/bedrock_log.cpp index 86eb5d664..fb664bcd9 100644 --- a/src/endstone_runtime/bedrock/bedrock_log.cpp +++ b/src/endstone_runtime/bedrock/bedrock_log.cpp @@ -14,32 +14,30 @@ #include "bedrock/bedrock_log.h" -#include #include #include -#include #include #include +#include "endstone/detail/logger_factory.h" #include "endstone/logger.h" -#include "endstone_core/logger_factory.h" void BedrockLog::log_va(BedrockLog::LogCategory /*category*/, std::bitset<3> /*flags*/, BedrockLog::LogRule /*rule*/, LogAreaID area, LogLevel level, const char * /*function*/, int /*line*/, const char *format, va_list args) { auto name = magic_enum::enum_name(area); - auto &logger = LoggerFactory::getLogger(std::string(name)); + auto &logger = endstone::detail::LoggerFactory::getLogger(std::string(name)); - static const std::unordered_map log_levels = { - {1, Logger::Level::Debug}, - {2, Logger::Level::Info}, - {4, Logger::Level::Warning}, - {8, Logger::Level::Error}, + static const std::unordered_map log_levels = { + {1, endstone::Logger::Level::Debug}, + {2, endstone::Logger::Level::Info}, + {4, endstone::Logger::Level::Warning}, + {8, endstone::Logger::Level::Error}, }; - Logger::Level log_level = Logger::Level::Critical; + endstone::Logger::Level log_level = endstone::Logger::Level::Critical; auto iter = log_levels.find(level); if (iter != log_levels.end()) { log_level = iter->second; diff --git a/src/endstone_runtime/bedrock/command_registry.cpp b/src/endstone_runtime/bedrock/command_registry.cpp index a868c89df..e0031fa2c 100644 --- a/src/endstone_runtime/bedrock/command_registry.cpp +++ b/src/endstone_runtime/bedrock/command_registry.cpp @@ -17,7 +17,7 @@ #include #include "bedrock/type_id.h" -#include "endstone_runtime/hook.h" +#include "endstone/detail/hook.h" namespace { diff --git a/src/endstone_runtime/bedrock/common.cpp b/src/endstone_runtime/bedrock/common.cpp index f5de46d3e..ce342bebf 100644 --- a/src/endstone_runtime/bedrock/common.cpp +++ b/src/endstone_runtime/bedrock/common.cpp @@ -14,7 +14,7 @@ #include "bedrock/common.h" -#include "endstone_runtime/hook.h" +#include "endstone/detail/hook.h" std::string Common::getGameVersionString() { diff --git a/src/endstone_runtime/bedrock/dedicated_server.cpp b/src/endstone_runtime/bedrock/dedicated_server.cpp index d5dd3d107..9752faa6f 100644 --- a/src/endstone_runtime/bedrock/dedicated_server.cpp +++ b/src/endstone_runtime/bedrock/dedicated_server.cpp @@ -1,7 +1,7 @@ #include "bedrock/server/dedicated_server.h" -#include "endstone_core/endstone_server.h" -#include "endstone_runtime/hook.h" +#include "endstone/detail/endstone_server.h" +#include "endstone/detail/hook.h" DedicatedServer::StartResult DedicatedServer::runDedicatedServerLoop(Core::FilePathManager &file_path_manager, PropertiesSettings &properties_settings, @@ -9,7 +9,7 @@ DedicatedServer::StartResult DedicatedServer::runDedicatedServerLoop(Core::FileP AllowListFile &allow_list_file, std::unique_ptr &permissions_file) { - auto &server = EndstoneServer::getInstance(); + auto &server = endstone::detail::EndstoneServer::getInstance(); server.getLogger().info("Version: {} (Minecraft: {})", server.getVersion(), server.getMinecraftVersion()); return ENDSTONE_HOOK_CALL_ORIGINAL(&DedicatedServer::runDedicatedServerLoop, this, file_path_manager, properties_settings, level_settings, allow_list_file, permissions_file); diff --git a/src/endstone_runtime/bedrock/server_instance.cpp b/src/endstone_runtime/bedrock/server_instance.cpp index eb649cfcb..dc9e088c8 100644 --- a/src/endstone_runtime/bedrock/server_instance.cpp +++ b/src/endstone_runtime/bedrock/server_instance.cpp @@ -14,23 +14,23 @@ #include "bedrock/server/server_instance.h" -#include "endstone_core/endstone_server.h" -#include "endstone_runtime/hook.h" +#include "endstone/detail/endstone_server.h" +#include "endstone/detail/hook.h" void ServerInstance::startServerThread() { - EndstoneServer::getInstance().loadPlugins(); + endstone::detail::EndstoneServer::getInstance().loadPlugins(); ENDSTONE_HOOK_CALL_ORIGINAL(&ServerInstance::startServerThread, this); } void ServerInstanceEventCoordinator::sendServerThreadStarted(ServerInstance &instance) { - EndstoneServer::getInstance().enablePlugins(); + endstone::detail::EndstoneServer::getInstance().enablePlugins(); ENDSTONE_HOOK_CALL_ORIGINAL(&ServerInstanceEventCoordinator::sendServerThreadStarted, this, instance); } void ServerInstanceEventCoordinator::sendServerThreadStopped(ServerInstance &instance) { - EndstoneServer::getInstance().disablePlugins(); + endstone::detail::EndstoneServer::getInstance().disablePlugins(); ENDSTONE_HOOK_CALL_ORIGINAL(&ServerInstanceEventCoordinator::sendServerThreadStopped, this, instance); } diff --git a/src/endstone_runtime/linux/hook.cpp b/src/endstone_runtime/linux/hook.cpp index 80c11be61..c95b1308f 100644 --- a/src/endstone_runtime/linux/hook.cpp +++ b/src/endstone_runtime/linux/hook.cpp @@ -14,7 +14,7 @@ #ifdef __linux__ -#include "endstone_runtime/hook.h" +#include "endstone/runtime/hook.h" #include @@ -23,7 +23,7 @@ #include #include -#include "endstone_runtime/platform.h" +#include "endstone/runtime/platform.h" namespace endstone::hook { diff --git a/src/endstone_runtime/linux/platform.cpp b/src/endstone_runtime/linux/platform.cpp index 558eca68b..0fbe7ffde 100644 --- a/src/endstone_runtime/linux/platform.cpp +++ b/src/endstone_runtime/linux/platform.cpp @@ -14,7 +14,7 @@ #ifdef __linux__ -#include "endstone_runtime/platform.h" +#include "endstone/detail/runtime/platform.h" #include #include diff --git a/src/endstone_runtime/main.cpp b/src/endstone_runtime/main.cpp index 765d7d7e2..8056aafe3 100644 --- a/src/endstone_runtime/main.cpp +++ b/src/endstone_runtime/main.cpp @@ -16,9 +16,9 @@ #include -#include "endstone_core/endstone_server.h" -#include "endstone_runtime/hook.h" -#include "endstone_runtime/python_plugin_loader.h" +#include "endstone/detail/endstone_server.h" +#include "endstone/detail/hook.h" +#include "endstone/detail/plugin/python_plugin_loader.h" #if __GNUC__ #define ENDSTONE_RUNTIME_CTOR __attribute__((constructor)) @@ -29,11 +29,11 @@ ENDSTONE_RUNTIME_CTOR int main() { try { - auto &server = EndstoneServer::getInstance(); + auto &server = endstone::detail::EndstoneServer::getInstance(); server.getLogger().info("Initialising..."); - server.getPluginManager().registerLoader(std::make_unique(server)); + server.getPluginManager().registerLoader(std::make_unique(server)); - endstone::hook::install(); + endstone::detail::hook::install(); return 0; } catch (const std::exception &e) { diff --git a/src/endstone_runtime/python/python_plugin_loader.cpp b/src/endstone_runtime/python/python_plugin_loader.cpp index 5db22607f..0c1744a7e 100644 --- a/src/endstone_runtime/python/python_plugin_loader.cpp +++ b/src/endstone_runtime/python/python_plugin_loader.cpp @@ -12,12 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "endstone_runtime/python_plugin_loader.h" +#include "endstone/detail/plugin/python_plugin_loader.h" #include namespace py = pybind11; -#include "endstone_core/logger_factory.h" +#include "endstone/detail/logger_factory.h" + +namespace endstone::detail { PythonPluginLoader::PythonPluginLoader(Server &server) : PluginLoader(server) { @@ -58,3 +60,5 @@ PluginLoader *PythonPluginLoader::pimpl() const { return obj_.cast(); } + +} // namespace endstone::detail diff --git a/src/endstone_runtime/windows/hook.cpp b/src/endstone_runtime/windows/hook.cpp index 371fa5857..b69e0df8c 100644 --- a/src/endstone_runtime/windows/hook.cpp +++ b/src/endstone_runtime/windows/hook.cpp @@ -14,7 +14,7 @@ #ifdef _WIN32 -#include "endstone_runtime/hook.h" +#include "endstone/detail/hook.h" #include // DbgHelp.h must be included after Windows.h @@ -28,9 +28,9 @@ #include #include -#include "endstone_runtime/platform.h" +#include "endstone/detail/os.h" -namespace endstone::hook { +namespace endstone::detail { namespace { std::unordered_map gOriginals; @@ -75,7 +75,8 @@ void enumerate_symbols(const char *path, std::functionsecond; } -} // namespace detail void install() { - namespace ep = endstone::platform; // Find detours - auto *module_base = ep::get_module_base(); - auto module_pathname = ep::get_module_pathname(); + auto *module_base = os::get_module_base(); + auto module_pathname = os::get_module_pathname(); std::unordered_map detours; enumerate_symbols( // @@ -104,10 +103,10 @@ void install() }); // Find targets - auto *executable_base = ep::get_executable_base(); + auto *executable_base = os::get_executable_base(); std::unordered_map targets; - const auto executable_pathname = ep::get_executable_pathname(); + const auto executable_pathname = os::get_executable_pathname(); enumerate_symbols( // executable_pathname.c_str(), [&](const std::string &name, size_t offset) -> bool { auto it = detours.find(name); @@ -195,6 +194,7 @@ const std::error_category &hook_error_category() noexcept } category; return category; } -} // namespace endstone::hook +} // namespace hook +} // namespace endstone::detail #endif diff --git a/src/endstone_runtime/windows/platform.cpp b/src/endstone_runtime/windows/platform.cpp index cfe3ec62e..6f4e9e9b9 100644 --- a/src/endstone_runtime/windows/platform.cpp +++ b/src/endstone_runtime/windows/platform.cpp @@ -20,9 +20,9 @@ #include -#include "endstone_runtime/platform.h" +#include "endstone/detail/os.h" -namespace endstone::platform { +namespace endstone::detail::os { namespace { HMODULE get_module_handle(const char *module_name) @@ -78,6 +78,6 @@ std::string get_executable_pathname() return file_name; } -} // namespace endstone::platform +} // namespace endstone::detail::os #endif diff --git a/tests/test_endstone_server.cpp b/tests/test_endstone_server.cpp index 5bc14eee9..ce88d7cd2 100644 --- a/tests/test_endstone_server.cpp +++ b/tests/test_endstone_server.cpp @@ -12,29 +12,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include "bedrock/common.h" -#include "endstone_core/endstone_server.h" +#include "endstone/detail/endstone_server.h" std::string Common::getGameVersionString() { return "1.2.3"; } +namespace endstone { + class EndstoneServerTest : public ::testing::Test { protected: - EndstoneServer &server_ = EndstoneServer::getInstance(); + detail::EndstoneServer &server_ = detail::EndstoneServer::getInstance(); }; TEST_F(EndstoneServerTest, GetInstance) { - EXPECT_NO_THROW(EndstoneServer::getInstance()); - EXPECT_EQ(&EndstoneServer::getInstance(), &server_); + EXPECT_NO_THROW(detail::EndstoneServer::getInstance()); + EXPECT_EQ(&detail::EndstoneServer::getInstance(), &server_); } TEST_F(EndstoneServerTest, GetMinecraftVersion) { EXPECT_EQ(server_.getMinecraftVersion(), "1.2.3"); } + +} // namespace endstone diff --git a/tests/test_logger.cpp b/tests/test_logger.cpp index da07740d9..17cb4528a 100644 --- a/tests/test_logger.cpp +++ b/tests/test_logger.cpp @@ -14,27 +14,29 @@ #include +#include "endstone/detail/logger_factory.h" #include "endstone/logger.h" -#include "endstone_core/logger_factory.h" + +namespace endstone { class LoggerFactoryTest : public ::testing::Test {}; TEST_F(LoggerFactoryTest, CreateLogger) { - auto &logger = LoggerFactory::getLogger("TestLogger"); + auto &logger = detail::LoggerFactory::getLogger("TestLogger"); ASSERT_EQ("TestLogger", logger.getName()); } TEST_F(LoggerFactoryTest, GetLogger) { - auto &logger1 = LoggerFactory::getLogger("TestLogger"); - auto &logger2 = LoggerFactory::getLogger("TestLogger"); + auto &logger1 = detail::LoggerFactory::getLogger("TestLogger"); + auto &logger2 = detail::LoggerFactory::getLogger("TestLogger"); ASSERT_EQ(&logger1, &logger2); } TEST_F(LoggerFactoryTest, SetLevel) { - auto &logger = LoggerFactory::getLogger("TestLogger"); + auto &logger = detail::LoggerFactory::getLogger("TestLogger"); ASSERT_FALSE(logger.isEnabledFor(Logger::Level::Debug)); ASSERT_TRUE(logger.isEnabledFor(Logger::Level::Info)); @@ -46,3 +48,5 @@ TEST_F(LoggerFactoryTest, SetLevel) ASSERT_FALSE(logger.isEnabledFor(Logger::Level::Warning)); ASSERT_TRUE(logger.isEnabledFor(Logger::Level::Error)); } + +} // namespace endstone