diff --git a/endstone/_internal/endstone_python.pyi b/endstone/_internal/endstone_python.pyi index c77d57bf2..9c0ca005b 100644 --- a/endstone/_internal/endstone_python.pyi +++ b/endstone/_internal/endstone_python.pyi @@ -4,7 +4,7 @@ import numpy import os import typing import uuid -__all__ = ['ActionForm', 'Actor', 'ActorDeathEvent', 'ActorEvent', 'ActorExplodeEvent', 'ActorKnockbackEvent', 'ActorRemoveEvent', 'ActorSpawnEvent', 'ActorTeleportEvent', 'BanEntry', 'BarColor', 'BarFlag', 'BarStyle', 'Block', 'BlockBreakEvent', 'BlockData', 'BlockEvent', 'BlockFace', 'BlockPlaceEvent', 'BlockState', 'BossBar', 'BroadcastMessageEvent', 'Cancellable', 'ColorFormat', 'Command', 'CommandExecutor', 'CommandSender', 'CommandSenderWrapper', 'ConsoleCommandSender', 'Criteria', 'Dimension', 'DisplaySlot', 'Dropdown', 'Event', 'EventPriority', 'GameMode', 'Inventory', 'IpBanEntry', 'IpBanList', 'ItemStack', 'Label', 'Language', 'Level', 'Location', 'Logger', 'MessageForm', 'Mob', 'ModalForm', 'Objective', 'ObjectiveSortOrder', 'OfflinePlayer', 'Packet', 'PacketType', 'Permissible', 'Permission', 'PermissionAttachment', 'PermissionAttachmentInfo', 'PermissionDefault', 'Player', 'PlayerBanEntry', 'PlayerBanList', 'PlayerChatEvent', 'PlayerCommandEvent', 'PlayerDeathEvent', 'PlayerEmoteEvent', 'PlayerEvent', 'PlayerGameModeChangeEvent', 'PlayerInteractActorEvent', 'PlayerInteractEvent', 'PlayerInventory', 'PlayerJoinEvent', 'PlayerKickEvent', 'PlayerLoginEvent', 'PlayerQuitEvent', 'PlayerTeleportEvent', 'Plugin', 'PluginCommand', 'PluginDescription', 'PluginDisableEvent', 'PluginEnableEvent', 'PluginLoadOrder', 'PluginLoader', 'PluginManager', 'Position', 'RenderType', 'Scheduler', 'Score', 'Scoreboard', 'ScriptMessageEvent', 'Server', 'ServerCommandEvent', 'ServerEvent', 'ServerListPingEvent', 'ServerLoadEvent', 'Skin', 'Slider', 'SocketAddress', 'SpawnParticleEffectPacket', 'StepSlider', 'Task', 'TextInput', 'ThunderChangeEvent', 'Toggle', 'Translatable', 'Vector', 'WeatherChangeEvent', 'WeatherEvent'] +__all__ = ['ActionForm', 'Actor', 'ActorDeathEvent', 'ActorEvent', 'ActorExplodeEvent', 'ActorKnockbackEvent', 'ActorRemoveEvent', 'ActorSpawnEvent', 'ActorTeleportEvent', 'BanEntry', 'BarColor', 'BarFlag', 'BarStyle', 'Block', 'BlockBreakEvent', 'BlockData', 'BlockEvent', 'BlockFace', 'BlockPlaceEvent', 'BlockState', 'BossBar', 'BroadcastMessageEvent', 'Cancellable', 'ColorFormat', 'Command', 'CommandExecutor', 'CommandSender', 'CommandSenderWrapper', 'ConsoleCommandSender', 'Criteria', 'Dimension', 'DisplaySlot', 'Dropdown', 'Event', 'EventPriority', 'GameMode', 'Inventory', 'IpBanEntry', 'IpBanList', 'ItemStack', 'Label', 'Language', 'Level', 'Location', 'Logger', 'MessageForm', 'Mob', 'ModalForm', 'Objective', 'ObjectiveSortOrder', 'OfflinePlayer', 'Packet', 'PacketType', 'Permissible', 'Permission', 'PermissionAttachment', 'PermissionAttachmentInfo', 'PermissionDefault', 'Player', 'PlayerBanEntry', 'PlayerBanList', 'PlayerChatEvent', 'PlayerCommandEvent', 'PlayerDeathEvent', 'PlayerEmoteEvent', 'PlayerEvent', 'PlayerGameModeChangeEvent', 'PlayerInteractActorEvent', 'PlayerInteractEvent', 'PlayerInventory', 'PlayerJoinEvent', 'PlayerKickEvent', 'PlayerLoginEvent', 'PlayerQuitEvent', 'PlayerRespawnEvent', 'PlayerTeleportEvent', 'Plugin', 'PluginCommand', 'PluginDescription', 'PluginDisableEvent', 'PluginEnableEvent', 'PluginLoadOrder', 'PluginLoader', 'PluginManager', 'Position', 'RenderType', 'Scheduler', 'Score', 'Scoreboard', 'ScriptMessageEvent', 'Server', 'ServerCommandEvent', 'ServerEvent', 'ServerListPingEvent', 'ServerLoadEvent', 'Skin', 'Slider', 'SocketAddress', 'SpawnParticleEffectPacket', 'StepSlider', 'Task', 'TextInput', 'ThunderChangeEvent', 'Toggle', 'Translatable', 'Vector', 'WeatherChangeEvent', 'WeatherEvent'] class ActionForm: """ Represents a form with buttons that let the player take action. @@ -2615,6 +2615,13 @@ class PlayerQuitEvent(PlayerEvent): @quit_message.setter def quit_message(self, arg1: str) -> None: ... +class PlayerRespawnEvent(PlayerEvent): + """ + Called when a player respawns. + """ + @staticmethod + def _pybind11_conduit_v1_(*args, **kwargs): + ... class PlayerTeleportEvent(PlayerEvent, Cancellable): """ Called when a player is teleported from one location to another. diff --git a/endstone/event.py b/endstone/event.py index fb3512a3c..63e147423 100644 --- a/endstone/event.py +++ b/endstone/event.py @@ -25,6 +25,7 @@ PlayerKickEvent, PlayerLoginEvent, PlayerQuitEvent, + PlayerRespawnEvent, PlayerTeleportEvent, PluginDisableEvent, PluginEnableEvent, @@ -45,7 +46,6 @@ "ActorEvent", "ActorExplodeEvent", "ActorDeathEvent", - "PlayerEmoteEvent", "ActorKnockbackEvent", "ActorRemoveEvent", "ActorSpawnEvent", @@ -58,6 +58,7 @@ "PlayerChatEvent", "PlayerCommandEvent", "PlayerDeathEvent", + "PlayerEmoteEvent", "PlayerGameModeChangeEvent", "PlayerInteractEvent", "PlayerInteractActorEvent", @@ -65,6 +66,7 @@ "PlayerKickEvent", "PlayerLoginEvent", "PlayerQuitEvent", + "PlayerRespawnEvent", "PlayerTeleportEvent", "BroadcastMessageEvent", "PluginEnableEvent", diff --git a/include/endstone/endstone.hpp b/include/endstone/endstone.hpp index e78302b3c..14ef76a26 100644 --- a/include/endstone/endstone.hpp +++ b/include/endstone/endstone.hpp @@ -75,6 +75,7 @@ static_assert(_ITERATOR_DEBUG_LEVEL == 0, #include "event/player/player_kick_event.h" #include "event/player/player_login_event.h" #include "event/player/player_quit_event.h" +#include "event/player/player_respawn_event.h" #include "event/player/player_teleport_event.h" #include "event/server/broadcast_message_event.h" #include "event/server/plugin_disable_event.h" diff --git a/include/endstone/event/player/player_emote_event.h b/include/endstone/event/player/player_emote_event.h index be572258e..ef72d699e 100644 --- a/include/endstone/event/player/player_emote_event.h +++ b/include/endstone/event/player/player_emote_event.h @@ -14,7 +14,6 @@ #pragma once -#include "endstone/event/cancellable.h" #include "endstone/event/player/player_event.h" namespace endstone { diff --git a/include/endstone/event/player/player_respawn_event.h b/include/endstone/event/player/player_respawn_event.h new file mode 100644 index 000000000..c92e23439 --- /dev/null +++ b/include/endstone/event/player/player_respawn_event.h @@ -0,0 +1,36 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "endstone/event/player/player_event.h" + +namespace endstone { + +/** + * @brief Called when a player respawns. + */ +class PlayerRespawnEvent : public PlayerEvent { +public: + explicit PlayerRespawnEvent(Player &player) : PlayerEvent(player) {} + ~PlayerRespawnEvent() override = default; + + inline static const std::string NAME = "PlayerRespawnEvent"; + [[nodiscard]] std::string getEventName() const override + { + return NAME; + } +}; + +} // namespace endstone diff --git a/src/endstone/core/event/handlers/player_gameplay_handler.cpp b/src/endstone/core/event/handlers/player_gameplay_handler.cpp index a7aa459a0..ece16d45a 100644 --- a/src/endstone/core/event/handlers/player_gameplay_handler.cpp +++ b/src/endstone/core/event/handlers/player_gameplay_handler.cpp @@ -27,6 +27,7 @@ #include "endstone/event/player/player_game_mode_change_event.h" #include "endstone/event/player/player_interact_actor_event.h" #include "endstone/event/player/player_interact_event.h" +#include "endstone/event/player/player_respawn_event.h" namespace endstone::core { @@ -57,7 +58,8 @@ GameplayHandlerResult EndstonePlayerGameplayHandler::handleEv using T = std::decay_t; if constexpr (std::is_same_v> || std::is_same_v> || - std::is_same_v>) { + std::is_same_v> || + std::is_same_v>) { if (!handleEvent(arg.value())) { return {HandlerResult::BypassListeners, CoordinatorResult::Cancel}; } @@ -98,6 +100,26 @@ bool EndstonePlayerGameplayHandler::handleEvent(const PlayerFormCloseEvent &even return true; } +bool EndstonePlayerGameplayHandler::handleEvent(const ::PlayerRespawnEvent &event) +{ + if (const auto *player = WeakEntityRef(event.player).tryUnwrap<::Player>(); player) { + const auto &server = entt::locator::value(); + PlayerRespawnEvent e{player->getEndstoneActor()}; + server.getPluginManager().callEvent(e); + } + return true; +} + +bool EndstonePlayerGameplayHandler::handleEvent(const ::PlayerEmoteEvent &event) +{ + if (const auto *player = WeakEntityRef(event.player).tryUnwrap<::Player>(); player) { + const auto &server = entt::locator::value(); + PlayerEmoteEvent e{player->getEndstoneActor(), event.emote_piece_id}; + server.getPluginManager().callEvent(e); + } + return true; +} + bool EndstonePlayerGameplayHandler::handleEvent(const PlayerInteractWithBlockBeforeEvent &event) { if (auto *player = WeakEntityRef(event.player).tryUnwrap<::Player>(); player) { @@ -142,16 +164,6 @@ bool EndstonePlayerGameplayHandler::handleEvent(const PlayerInteractWithEntityBe return true; } -bool EndstonePlayerGameplayHandler::handleEvent(const ::PlayerEmoteEvent &event) -{ - if (const auto *player = WeakEntityRef(event.player).tryUnwrap<::Player>(); player) { - const auto &server = entt::locator::value(); - PlayerEmoteEvent e{player->getEndstoneActor(), event.emote_piece_id}; - server.getPluginManager().callEvent(e); - } - return true; -} - bool EndstonePlayerGameplayHandler::handleEvent(::PlayerGameModeChangeEvent &event) { if (auto *player = event.player.tryUnwrap<::Player>(); player) { diff --git a/src/endstone/core/event/handlers/player_gameplay_handler.h b/src/endstone/core/event/handlers/player_gameplay_handler.h index d78969661..ca74c04d1 100644 --- a/src/endstone/core/event/handlers/player_gameplay_handler.h +++ b/src/endstone/core/event/handlers/player_gameplay_handler.h @@ -30,6 +30,7 @@ class EndstonePlayerGameplayHandler final : public PlayerGameplayHandler { private: bool handleEvent(const PlayerFormResponseEvent &event); bool handleEvent(const PlayerFormCloseEvent &event); + bool handleEvent(const PlayerRespawnEvent &event); bool handleEvent(const PlayerEmoteEvent &event); bool handleEvent(const PlayerInteractWithBlockBeforeEvent &event); bool handleEvent(const PlayerInteractWithEntityBeforeEvent &event); diff --git a/src/endstone/python/event.cpp b/src/endstone/python/event.cpp index dfc7f12cd..dcb1c1a34 100644 --- a/src/endstone/python/event.cpp +++ b/src/endstone/python/event.cpp @@ -162,6 +162,7 @@ void init_event(py::module_ &m, py::class_ &event, py::enum_(m, "PlayerQuitEvent", "Called when a player leaves a server.") .def_property("quit_message", &PlayerQuitEvent::getQuitMessage, &PlayerQuitEvent::setQuitMessage, "Gets or sets the quit message to send to all online players."); + py::class_(m, "PlayerRespawnEvent", "Called when a player respawns."); py::class_( m, "PlayerTeleportEvent", "Called when a player is teleported from one location to another.") .def_property("from_location", &PlayerTeleportEvent::getFrom, &PlayerTeleportEvent::setFrom,