Skip to content

Commit

Permalink
refactor: pass ServerInstance ref to EndstoneServer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 3, 2024
1 parent a7be72e commit ce0dca4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 29 deletions.
6 changes: 3 additions & 3 deletions include/endstone/detail/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string>
#include <string_view>

#include "bedrock/server/dedicated_server.h"
#include "bedrock/server/server_instance.h"
#include "endstone/detail/plugin/plugin_manager.h"
#include "endstone/plugin/plugin_manager.h"
#include "endstone/server.h"
Expand All @@ -27,7 +27,7 @@ namespace endstone::detail {

class EndstoneServer : public Server {
public:
explicit EndstoneServer(DedicatedServer &dedicated_server);
explicit EndstoneServer(ServerInstance &dedicated_server);
EndstoneServer(EndstoneServer const &) = delete;
EndstoneServer(EndstoneServer &&) = delete;
EndstoneServer &operator=(EndstoneServer const &) = delete;
Expand All @@ -47,7 +47,7 @@ class EndstoneServer : public Server {
private:
void enablePlugin(Plugin &plugin) const;

DedicatedServer &dedicated_server_;
ServerInstance &dedicated_server_;
Logger &logger_;
std::unique_ptr<EndstonePluginManager> plugin_manager_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace fs = std::filesystem;

namespace endstone::detail {

EndstoneServer::EndstoneServer(DedicatedServer &dedicated_server)
EndstoneServer::EndstoneServer(ServerInstance &dedicated_server)
: dedicated_server_(dedicated_server), logger_(LoggerFactory::getLogger("EndstoneServer"))
{
plugin_manager_ = std::make_unique<EndstonePluginManager>(*this);
Expand Down
24 changes: 0 additions & 24 deletions src/endstone_runtime/bedrock/dedicated_server.cpp

This file was deleted.

8 changes: 7 additions & 1 deletion src/endstone_runtime/bedrock/server_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@
#include "bedrock/server/server_instance.h"

#include "endstone/detail/hook.h"
#include "endstone/detail/plugin/python_plugin_loader.h"
#include "endstone/detail/server.h"
#include "endstone/detail/singleton.h"

using endstone::detail::EndstoneServer;
using endstone::detail::PythonPluginLoader;
using endstone::detail::Singleton;

void ServerInstance::startServerThread()
{
Singleton<EndstoneServer>::getInstance().loadPlugins();
Singleton<EndstoneServer>::setInstance(std::make_unique<EndstoneServer>(*this));
auto &server = Singleton<EndstoneServer>::getInstance();
server.getPluginManager().registerLoader(std::make_unique<PythonPluginLoader>(server));
server.getLogger().info("Version: {} (Minecraft: {})", server.getVersion(), server.getMinecraftVersion());
server.loadPlugins();
ENDSTONE_HOOK_CALL_ORIGINAL(&ServerInstance::startServerThread, this);
}

Expand Down

0 comments on commit ce0dca4

Please sign in to comment.