Skip to content

Commit

Permalink
feat(scoreboard): add Server::getScoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jul 22, 2024
1 parent 268c781 commit fb3def7
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/bedrock/world/scores/scoreboard_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "bedrock/forward.h"

class IdentityDefinition;
class ScoreboardId {
public:

struct ScoreboardId {
ScoreboardId() = default;
explicit ScoreboardId(std::int64_t id) : raw_id(id) {}
[[nodiscard]] bool isValid() const;
Expand Down
1 change: 1 addition & 0 deletions include/endstone/detail/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class EndstoneServer : public Server {

[[nodiscard]] bool isPrimaryThread() const override;

[[nodiscard]] Scoreboard *getScoreboard() const override;
void setScoreboard(std::unique_ptr<EndstoneScoreboard> scoreboard);
[[nodiscard]] ::ServerNetworkHandler &getServerNetworkHandler() const;

Expand Down
10 changes: 10 additions & 0 deletions include/endstone/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "endstone/level/level.h"
#include "endstone/logger.h"
#include "endstone/player.h"
#include "endstone/scoreboard/scoreboard.h"
#include "endstone/util/uuid.h"

namespace endstone {
Expand Down Expand Up @@ -188,6 +189,15 @@ class Server {
*/
[[nodiscard]] virtual bool isPrimaryThread() const = 0;

/**
* @brief Gets the scoreboard.
* <p>
* This will only exist after the first level has loaded.
*
* @return the scoreboard.
*/
[[nodiscard]] virtual Scoreboard *getScoreboard() const = 0;

/**
* @brief Used for all administrative messages, such as an operator using a command.
*/
Expand Down
5 changes: 5 additions & 0 deletions python/src/endstone/_internal/endstone_python.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,11 @@ class Server:
Gets the scheduler for managing scheduled events.
"""
@property
def scoreboard(self) -> Scoreboard:
"""
Gets the scoreboard.
"""
@property
def version(self) -> str:
"""
Gets the version of this server implementation.
Expand Down
5 changes: 5 additions & 0 deletions src/endstone_core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ bool EndstoneServer::isPrimaryThread() const
return Bedrock::Threading::getServerThread().isOnThread();
}

Scoreboard *EndstoneServer::getScoreboard() const
{
return scoreboard_.get();
}

void EndstoneServer::setScoreboard(std::unique_ptr<EndstoneScoreboard> scoreboard)
{
scoreboard_ = std::move(scoreboard);
Expand Down
4 changes: 3 additions & 1 deletion src/endstone_python/endstone_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ void init_server(py::class_<Server> &server)
"broadcast_message",
[](const Server &server, const std::string &message) { server.broadcastMessage(message); },
py::arg("message"),
"Broadcasts the specified message to every user with permission endstone.broadcast.user");
"Broadcasts the specified message to every user with permission endstone.broadcast.user")
.def_property_readonly("scoreboard", &Server::getScoreboard, "Gets the scoreboard.",
py::return_value_policy::reference);
}

void init_player(py::module_ &m)
Expand Down
1 change: 1 addition & 0 deletions tests/plugin/test_cpp_plugin_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MockServer : public endstone::Server {
MOCK_METHOD(void, broadcast, (const std::string &, const std::string &), (const, override));
MOCK_METHOD(void, broadcastMessage, (const std::string &), (const, override));
MOCK_METHOD(bool, isPrimaryThread, (), (const, override));
MOCK_METHOD(endstone::Scoreboard *, getScoreboard, (), (const, override));
MockServer()
{
ON_CALL(*this, getLogger())
Expand Down
1 change: 1 addition & 0 deletions tests/scheduler/test_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MockServer : public endstone::Server {
MOCK_METHOD(void, broadcast, (const std::string &, const std::string &), (const, override));
MOCK_METHOD(void, broadcastMessage, (const std::string &), (const, override));
MOCK_METHOD(bool, isPrimaryThread, (), (const, override));
MOCK_METHOD(endstone::Scoreboard *, getScoreboard, (), (const, override));
};

class MockPlugin : public endstone::Plugin {
Expand Down

0 comments on commit fb3def7

Please sign in to comment.