Skip to content

Commit

Permalink
feat(command): implement ProxiedCommandSender
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Sep 25, 2024
1 parent 7c7ef21 commit fca4c7b
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
33 changes: 33 additions & 0 deletions include/endstone/detail/command/proxied_command_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,36 @@
#pragma once

#include "endstone/command/proxied_command_sender.h"

namespace endstone::detail {

class EndstoneProxiedCommandSender : public ProxiedCommandSender {
public:
EndstoneProxiedCommandSender(CommandSender &caller, CommandSender &callee);
[[nodiscard]] bool isOp() const override;
void setOp(bool value) override;
[[nodiscard]] bool isPermissionSet(std::string name) const override;
[[nodiscard]] bool isPermissionSet(const Permission &perm) const override;
[[nodiscard]] bool hasPermission(std::string name) const override;
[[nodiscard]] bool hasPermission(const Permission &perm) const override;
PermissionAttachment *addAttachment(Plugin &plugin, const std::string &name, bool value) override;
PermissionAttachment *addAttachment(Plugin &plugin) override;
bool removeAttachment(PermissionAttachment &attachment) override;
void recalculatePermissions() override;
[[nodiscard]] std::unordered_set<PermissionAttachmentInfo *> getEffectivePermissions() const override;
[[nodiscard]] CommandSender *asCommandSender() const override;
[[nodiscard]] ConsoleCommandSender *asConsole() const override;
[[nodiscard]] Player *asPlayer() const override;
void sendMessage(const Message &message) const override;
void sendErrorMessage(const Message &message) const override;
[[nodiscard]] Server &getServer() const override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] CommandSender &getCaller() const override;
[[nodiscard]] CommandSender &getCallee() const override;

private:
CommandSender &caller_;
CommandSender &callee_;
};

} // namespace endstone::detail
108 changes: 108 additions & 0 deletions src/endstone_core/command/proxied_command_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,111 @@
// limitations under the License.

#include "endstone/detail/command/proxied_command_sender.h"

namespace endstone::detail {

EndstoneProxiedCommandSender::EndstoneProxiedCommandSender(CommandSender &caller, CommandSender &callee)
: caller_(caller), callee_(callee)
{
}
bool EndstoneProxiedCommandSender::isOp() const
{
return getCaller().isOp();
}

void EndstoneProxiedCommandSender::setOp(bool value)
{
getCaller().setOp(value);
}

bool EndstoneProxiedCommandSender::isPermissionSet(std::string name) const
{
return getCaller().isPermissionSet(name);
}

bool EndstoneProxiedCommandSender::isPermissionSet(const Permission &perm) const
{
return getCaller().isPermissionSet(perm);
}

bool EndstoneProxiedCommandSender::hasPermission(std::string name) const
{
return getCaller().hasPermission(name);
}

bool EndstoneProxiedCommandSender::hasPermission(const Permission &perm) const
{
return getCaller().hasPermission(perm);
}

PermissionAttachment *EndstoneProxiedCommandSender::addAttachment(Plugin &plugin, const std::string &name, bool value)
{
return getCaller().addAttachment(plugin, name, value);
}

PermissionAttachment *EndstoneProxiedCommandSender::addAttachment(Plugin &plugin)
{
return getCaller().addAttachment(plugin);
}

bool EndstoneProxiedCommandSender::removeAttachment(PermissionAttachment &attachment)
{
return getCaller().removeAttachment(attachment);
}

void EndstoneProxiedCommandSender::recalculatePermissions()
{
getCaller().recalculatePermissions();
}

std::unordered_set<PermissionAttachmentInfo *> EndstoneProxiedCommandSender::getEffectivePermissions() const
{
return getCaller().getEffectivePermissions();
}

CommandSender *EndstoneProxiedCommandSender::asCommandSender() const
{
return ProxiedCommandSender::asCommandSender();
}

ConsoleCommandSender *EndstoneProxiedCommandSender::asConsole() const
{
return ProxiedCommandSender::asConsole();
}

Player *EndstoneProxiedCommandSender::asPlayer() const
{
return ProxiedCommandSender::asPlayer();
}

void EndstoneProxiedCommandSender::sendMessage(const Message &message) const
{
getCaller().sendMessage(message);
}

void EndstoneProxiedCommandSender::sendErrorMessage(const Message &message) const
{
getCaller().sendErrorMessage(message);
}

Server &EndstoneProxiedCommandSender::getServer() const
{
return getCallee().getServer();
}

std::string EndstoneProxiedCommandSender::getName() const
{
return getCallee().getName();
}

CommandSender &EndstoneProxiedCommandSender::getCaller() const
{
return caller_;
}

CommandSender &EndstoneProxiedCommandSender::getCallee() const
{
return callee_;
}

} // namespace endstone::detail

0 comments on commit fca4c7b

Please sign in to comment.