Skip to content

Commit

Permalink
feat: add python binding for Player::isFlying
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed May 24, 2024
1 parent 8ccd5d8 commit c01d1a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/endstone/detail/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class EndstonePlayer : public EndstoneActor, public endstone::Player {
void sendPopup(std::string message) const override;
void sendTip(std::string message) const override;
void kick(std::string message) const override;
[[nodiscard]] bool isFlying() const override;
[[nodiscard]] std::chrono::milliseconds getPing() const override;
void updateCommands() const override;
bool performCommand(std::string command) const override; // NOLINT(*-use-nodiscard)
Expand Down
7 changes: 7 additions & 0 deletions include/endstone/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class Player : public Actor {
*/
virtual void kick(std::string message) const = 0;

/**
* @brief Checks to see if this player is currently flying or not.
*
* @return True if the player is flying, else false.
*/
[[nodiscard]] virtual bool isFlying() const = 0;

/**
* @brief Gets the player's average ping
*
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 @@ -766,6 +766,11 @@ class Player(Actor):
def game_mode(self, arg1: GameMode) -> None:
...
@property
def is_flying(self) -> bool:
"""
Checks to see if this player is currently flying or not.
"""
@property
def ping(self) -> datetime.timedelta:
"""
Gets the player's average ping.
Expand Down
25 changes: 15 additions & 10 deletions src/endstone_core/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,18 @@ void EndstonePlayer::sendTip(std::string message) const
player_.sendNetworkPacket(*packet);
}

void EndstonePlayer::init(ServerNetworkHandler &network_handler)
{
network_handler_ = &network_handler;
}

void EndstonePlayer::disconnect()
{
perm_.clearPermissions();
}

void EndstonePlayer::kick(std::string message) const
{
auto *component = player_.tryGetComponent<UserEntityIdentifierComponent>();
network_handler_->disconnectClient(component->network_id, component->sub_client_id,
Connection::DisconnectFailReason::NoReason, message, message.empty());
}

bool EndstonePlayer::isFlying() const
{
return player_.isFlying();
}

std::chrono::milliseconds EndstonePlayer::getPing() const
{
auto *peer = entt::locator<RakNet::RakPeerInterface *>::value();
Expand Down Expand Up @@ -323,4 +318,14 @@ void EndstonePlayer::setGameMode(GameMode mode)
}
}

void EndstonePlayer::init(ServerNetworkHandler &network_handler)
{
network_handler_ = &network_handler;
}

void EndstonePlayer::disconnect()
{
perm_.clearPermissions();
}

} // namespace endstone::detail
2 changes: 2 additions & 0 deletions src/endstone_python/endstone_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ void init_player(py::module_ &m)
.def("send_popup", &Player::sendPopup, py::arg("message"), "Sends this player a popup message")
.def("send_tip", &Player::sendTip, py::arg("message"), "Sends this player a tip message")
.def("kick", &Player::kick, py::arg("message"), "Kicks player with custom kick message.")
.def_property_readonly("is_flying", &Player::isFlying,
"Checks to see if this player is currently flying or not.")
.def_property_readonly("ping", &Player::getPing, "Gets the player's average ping.")
.def("update_commands", &Player::updateCommands, "Send the list of commands to the client.")
.def("perform_command", &Player::performCommand, py::arg("command"),
Expand Down

0 comments on commit c01d1a0

Please sign in to comment.