Skip to content

Commit

Permalink
feat: add PlayerEmoteEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jan 22, 2025
1 parent a68fd25 commit 3a54aab
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
14 changes: 13 additions & 1 deletion endstone/_internal/endstone_python.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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', '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', '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.
Expand Down Expand Up @@ -2463,6 +2463,18 @@ class PlayerDeathEvent(ActorDeathEvent, PlayerEvent):
@death_message.setter
def death_message(self, arg1: str) -> None:
...
class PlayerEmoteEvent(PlayerEvent):
"""
Called when a player uses and emote
"""
@staticmethod
def _pybind11_conduit_v1_(*args, **kwargs):
...
@property
def emote_id(self) -> str:
"""
Gets the emote ID
"""
class PlayerEvent(Event):
"""
Represents a player related event
Expand Down
2 changes: 2 additions & 0 deletions endstone/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PlayerChatEvent,
PlayerCommandEvent,
PlayerDeathEvent,
PlayerEmoteEvent,
PlayerEvent,
PlayerGameModeChangeEvent,
PlayerInteractActorEvent,
Expand Down Expand Up @@ -44,6 +45,7 @@
"ActorEvent",
"ActorExplodeEvent",
"ActorDeathEvent",
"PlayerEmoteEvent",
"ActorKnockbackEvent",
"ActorRemoveEvent",
"ActorSpawnEvent",
Expand Down
1 change: 1 addition & 0 deletions include/endstone/endstone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static_assert(_ITERATOR_DEBUG_LEVEL == 0,
#include "event/player/player_chat_event.h"
#include "event/player/player_command_event.h"
#include "event/player/player_death_event.h"
#include "event/player/player_emote_event.h"
#include "event/player/player_event.h"
#include "event/player/player_game_mode_change_event.h"
#include "event/player/player_interact_actor_event.h"
Expand Down
53 changes: 53 additions & 0 deletions include/endstone/event/player/player_emote_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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/cancellable.h"
#include "endstone/event/player/player_event.h"

namespace endstone {

/**
* @brief Called when a player uses an emote.
*/
class PlayerEmoteEvent : public PlayerEvent {
public:
explicit PlayerEmoteEvent(Player &player, std::string emote_id)
: PlayerEvent(player), emote_id_(std::move(emote_id))
{
}
~PlayerEmoteEvent() override = default;

inline static const std::string NAME = "PlayerEmoteEvent";
[[nodiscard]] std::string getEventName() const override
{
return NAME;
}

/**
* @brief Gets the emote ID
*
* @return The emote ID
*/
[[nodiscard]] std::string getEmoteId() const
{
return emote_id_;
}

private:
std::string emote_id_;
};

} // namespace endstone
14 changes: 13 additions & 1 deletion src/endstone/core/event/handlers/player_gameplay_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "endstone/core/json.h"
#include "endstone/core/player.h"
#include "endstone/core/server.h"
#include "endstone/event/player/player_emote_event.h"
#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"
Expand Down Expand Up @@ -55,7 +56,8 @@ GameplayHandlerResult<CoordinatorResult> EndstonePlayerGameplayHandler::handleEv
auto visitor = [&](auto &&arg) -> GameplayHandlerResult<CoordinatorResult> {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, Details::ValueOrRef<const PlayerInteractWithBlockBeforeEvent>> ||
std::is_same_v<T, Details::ValueOrRef<const PlayerInteractWithEntityBeforeEvent>>) {
std::is_same_v<T, Details::ValueOrRef<const PlayerInteractWithEntityBeforeEvent>> ||
std::is_same_v<T, Details::ValueOrRef<const PlayerEmoteEvent>>) {
if (!handleEvent(arg.value())) {
return {HandlerResult::BypassListeners, CoordinatorResult::Cancel};
}
Expand Down Expand Up @@ -140,6 +142,16 @@ 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<EndstoneServer>::value();
PlayerEmoteEvent e{player->getEndstoneActor<EndstonePlayer>(), event.emote_piece_id};
server.getPluginManager().callEvent(e);
}
return true;
}

bool EndstonePlayerGameplayHandler::handleEvent(::PlayerGameModeChangeEvent &event)
{
if (auto *player = event.player.tryUnwrap<::Player>(); player) {
Expand Down
1 change: 1 addition & 0 deletions src/endstone/core/event/handlers/player_gameplay_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EndstonePlayerGameplayHandler final : public PlayerGameplayHandler {
private:
bool handleEvent(const PlayerFormResponseEvent &event);
bool handleEvent(const PlayerFormCloseEvent &event);
bool handleEvent(const PlayerEmoteEvent &event);
bool handleEvent(const PlayerInteractWithBlockBeforeEvent &event);
bool handleEvent(const PlayerInteractWithEntityBeforeEvent &event);
bool handleEvent(::PlayerGameModeChangeEvent &event);
Expand Down
2 changes: 2 additions & 0 deletions src/endstone/python/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void init_event(py::module_ &m, py::class_<Event> &event, py::enum_<EventPriorit
py::class_<PlayerDeathEvent, ActorDeathEvent, PlayerEvent>(m, "PlayerDeathEvent", "Called when a player dies")
.def_property("death_message", &PlayerDeathEvent::getDeathMessage, &PlayerDeathEvent::setDeathMessage,
"Gets or sets the death message that will appear to everyone on the server.");
py::class_<PlayerEmoteEvent, PlayerEvent>(m, "PlayerEmoteEvent", "Called when a player uses and emote")
.def_property_readonly("emote_id", &PlayerEmoteEvent::getEmoteId, "Gets the emote ID");
py::class_<PlayerGameModeChangeEvent, PlayerEvent, ICancellable>(
m, "PlayerGameModeChangeEvent", "Called when the GameMode of the player is changed.")
.def_property_readonly("new_game_mode", &PlayerGameModeChangeEvent::getNewGameMode,
Expand Down

0 comments on commit 3a54aab

Please sign in to comment.