From c01d1a05da169a5765439af7286d1bcf56fbbf75 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 May 2024 04:53:12 +0100 Subject: [PATCH] feat: add python binding for Player::isFlying --- include/endstone/detail/player.h | 1 + include/endstone/player.h | 7 ++++++ .../endstone/_internal/endstone_python.pyi | 5 ++++ src/endstone_core/player.cpp | 25 +++++++++++-------- src/endstone_python/endstone_python.cpp | 2 ++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/endstone/detail/player.h b/include/endstone/detail/player.h index 5f368b842..710bf86f9 100644 --- a/include/endstone/detail/player.h +++ b/include/endstone/detail/player.h @@ -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) diff --git a/include/endstone/player.h b/include/endstone/player.h index 30dc99a9c..db805ac6c 100644 --- a/include/endstone/player.h +++ b/include/endstone/player.h @@ -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 * diff --git a/python/src/endstone/_internal/endstone_python.pyi b/python/src/endstone/_internal/endstone_python.pyi index c8db1c714..1733a6bf9 100644 --- a/python/src/endstone/_internal/endstone_python.pyi +++ b/python/src/endstone/_internal/endstone_python.pyi @@ -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. diff --git a/src/endstone_core/player.cpp b/src/endstone_core/player.cpp index cb3f0d149..283f4bb90 100644 --- a/src/endstone_core/player.cpp +++ b/src/endstone_core/player.cpp @@ -219,16 +219,6 @@ 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(); @@ -236,6 +226,11 @@ void EndstonePlayer::kick(std::string message) const Connection::DisconnectFailReason::NoReason, message, message.empty()); } +bool EndstonePlayer::isFlying() const +{ + return player_.isFlying(); +} + std::chrono::milliseconds EndstonePlayer::getPing() const { auto *peer = entt::locator::value(); @@ -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 diff --git a/src/endstone_python/endstone_python.cpp b/src/endstone_python/endstone_python.cpp index 6667b846f..10656736d 100644 --- a/src/endstone_python/endstone_python.cpp +++ b/src/endstone_python/endstone_python.cpp @@ -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"),