Skip to content

Commit

Permalink
feat: add ProxiedCommandSender in type caster
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Feb 10, 2025
1 parent df567c9 commit 747637a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/endstone/command/command_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ConsoleCommandSender;
class Mob;
class Server;
class Player;
class ProxiedCommandSender;

/**
* @brief Represents a command sender.
Expand Down Expand Up @@ -80,6 +81,16 @@ class CommandSender : public Permissible {
return nullptr;
}

/**
* @brief Gets a CommandSender as ProxiedCommandSender
*
* @return ProxiedCommandSender, nullptr if not a ProxiedCommandSender
*/
[[nodiscard]] virtual ProxiedCommandSender *asProxiedCommandSender() const
{
return nullptr;
}

/**
* @brief Sends this sender a message
*
Expand Down
5 changes: 5 additions & 0 deletions include/endstone/command/proxied_command_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ namespace endstone {
*/
class ProxiedCommandSender : public CommandSender {
public:
[[nodiscard]] ProxiedCommandSender *asProxiedCommandSender() const override
{
return const_cast<ProxiedCommandSender *>(this);
}

/**
* @brief Returns the CommandSender which triggered this proxied command.
*
Expand Down
4 changes: 4 additions & 0 deletions src/endstone/python/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ struct polymorphic_type_hook<endstone::CommandSender> {
type = &typeid(endstone::ConsoleCommandSender);
return console;
}
if (const auto *proxied = src->asProxiedCommandSender()) {
type = &typeid(endstone::ProxiedCommandSender);
return proxied;
}
type = &typeid(endstone::CommandSender);
return src;
}
Expand Down

0 comments on commit 747637a

Please sign in to comment.