-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
441 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "CommandSenderAPI.h" | ||
#include "API/APIHelper.h" | ||
#include "Utils/Convert.h" | ||
#include "Utils/Using.h" | ||
#include <cstddef> | ||
#include <sstream> | ||
|
||
|
||
namespace jse { | ||
|
||
ClassDefine<CommandSenderAPI> CommandSenderAPI::builder = | ||
defineClass<CommandSenderAPI>("CommandSender") | ||
.constructor(nullptr) | ||
.instanceFunction("toString", &CommandSenderAPI::toString) | ||
.instanceFunction("asCommandSender", &CommandSenderAPI::asCommandSender) | ||
.instanceFunction("asConsole", &CommandSenderAPI::asConsole) | ||
.instanceFunction("asActor", &CommandSenderAPI::asActor) | ||
.instanceFunction("asPlayer", &CommandSenderAPI::asPlayer) | ||
.instanceFunction("sendMessage", &CommandSenderAPI::sendMessage) | ||
.instanceFunction("sendErrorMessage", &CommandSenderAPI::sendErrorMessage) | ||
.instanceFunction("getServer", &CommandSenderAPI::getServer) | ||
.instanceFunction("getName", &CommandSenderAPI::getName) | ||
|
||
// parent class | ||
// .instanceFunction("toString", &PermissibleAPI::toString) | ||
.instanceFunction("isOp", &PermissibleAPI::isOP) | ||
.instanceFunction("setOp", &PermissibleAPI::setOp) | ||
.instanceFunction("isPermissionSet", &PermissibleAPI::isPermissionSet) | ||
.instanceFunction("hasPermission", &PermissibleAPI::hasPermission) | ||
.instanceFunction("addAttachment", &PermissibleAPI::addAttachment) | ||
.instanceFunction("removeAttachment", &PermissibleAPI::removeAttachment) | ||
.instanceFunction("recalculatePermissions", &PermissibleAPI::recalculatePermissions) | ||
.instanceFunction("getEffectivePermissions", &PermissibleAPI::getEffectivePermissions) | ||
// .instanceFunction("asCommandSender", &PermissibleAPI::getEffectivePermissions) | ||
|
||
.build(); | ||
|
||
|
||
Local<Value> CommandSenderAPI::toString(Arguments const& args) { return ConvertToScriptX("<CommandSender>"); } | ||
|
||
// Local<Value> CommandSenderAPI::asCommandSender(Arguments const& args) {} | ||
|
||
Local<Value> CommandSenderAPI::asConsole(Arguments const& args) { return Local<Value>(); } | ||
|
||
Local<Value> CommandSenderAPI::asActor(Arguments const& args) { return Local<Value>(); } | ||
|
||
Local<Value> CommandSenderAPI::asPlayer(Arguments const& args) { return Local<Value>(); } | ||
|
||
Local<Value> CommandSenderAPI::sendMessage(Arguments const& args) { | ||
try { | ||
std::ostringstream oss; | ||
for (size_t i = 0; i < args.size(); ++i) ToString(args[i], oss); | ||
this->mSender->sendMessage(oss.str()); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> CommandSenderAPI::sendErrorMessage(Arguments const& args) { | ||
try { | ||
std::ostringstream oss; | ||
for (size_t i = 0; i < args.size(); ++i) ToString(args[i], oss); | ||
this->mSender->sendErrorMessage(oss.str()); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> CommandSenderAPI::getServer(Arguments const& args) { return Local<Value>(); } | ||
|
||
Local<Value> CommandSenderAPI::getName(Arguments const& args) { | ||
try { | ||
return ConvertToScriptX(this->mSender->getName()); | ||
} | ||
Catch; | ||
} | ||
|
||
|
||
} // namespace jse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include "API/PermissibleAPI.h" | ||
#include "Utils/Defines.h" | ||
#include "Utils/Using.h" | ||
#include "endstone/command/command_sender.h" | ||
namespace jse { | ||
|
||
|
||
class CommandSenderAPI : public PermissibleAPI { | ||
endstone::CommandSender* mSender; | ||
|
||
public: | ||
CommandSenderAPI(endstone::CommandSender* sender) | ||
: PermissibleAPI(sender, ScriptClass::ConstructFromCpp<CommandSenderAPI>{}), | ||
mSender(sender) {} | ||
|
||
static Local<Object> newCommandSenderAPI(endstone::CommandSender* sender) { | ||
return (new CommandSenderAPI(sender))->getScriptObject(); | ||
} | ||
|
||
METHODS(toString); | ||
// METHODS(asCommandSender); | ||
METHODS(asConsole); | ||
METHODS(asActor); | ||
METHODS(asPlayer); | ||
METHODS(sendMessage); | ||
METHODS(sendErrorMessage); | ||
METHODS(getServer); | ||
METHODS(getName); | ||
|
||
|
||
static ClassDefine<CommandSenderAPI> builder; | ||
}; | ||
|
||
|
||
} // namespace jse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "PermissibleAPI.h" | ||
#include "API/CommandSenderAPI.h" | ||
#include "API/PluginAPI.h" | ||
#include "APIHelper.h" | ||
#include "Loader/JavaScriptPlugin.h" | ||
#include "Utils/Convert.h" | ||
#include "Utils/Defines.h" | ||
#include "Utils/Using.h" | ||
#include "endstone/permissions/permissible.h" | ||
#include "endstone/plugin/plugin.h" | ||
#include "endstone/util/result.h" | ||
#include "fmt/core.h" | ||
#include <stdexcept> | ||
|
||
|
||
namespace jse { | ||
|
||
ClassDefine<PermissibleAPI> PermissibleAPI::builder = | ||
defineClass<PermissibleAPI>("Permissible") | ||
.constructor(nullptr) | ||
.instanceFunction("toString", &PermissibleAPI::toString) | ||
.instanceFunction("isOp", &PermissibleAPI::isOP) | ||
.instanceFunction("setOp", &PermissibleAPI::setOp) | ||
.instanceFunction("isPermissionSet", &PermissibleAPI::isPermissionSet) | ||
.instanceFunction("hasPermission", &PermissibleAPI::hasPermission) | ||
.instanceFunction("addAttachment", &PermissibleAPI::addAttachment) | ||
.instanceFunction("removeAttachment", &PermissibleAPI::removeAttachment) | ||
.instanceFunction("recalculatePermissions", &PermissibleAPI::recalculatePermissions) | ||
.instanceFunction("getEffectivePermissions", &PermissibleAPI::getEffectivePermissions) | ||
.instanceFunction("asCommandSender", &PermissibleAPI::getEffectivePermissions) | ||
.build(); | ||
|
||
|
||
Local<Value> PermissibleAPI::toString(Arguments const& args) { return ConvertToScriptX("<Permissible>"); }; | ||
|
||
Local<Value> PermissibleAPI::isOP(Arguments const& args) { | ||
try { | ||
return ConvertToScriptX(this->mPermissible->isOp()); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::setOp(Arguments const& args) { | ||
try { | ||
this->mPermissible->setOp(args[0].asBoolean().value()); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::isPermissionSet(Arguments const& args) { | ||
try { | ||
if (args[0].isString()) { | ||
// overload 1 | ||
return ConvertToScriptX(this->mPermissible->isPermissionSet(args[0].asString().toString())); | ||
} | ||
// TODO: overload 2 | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::hasPermission(Arguments const& args) { | ||
try { | ||
if (args[0].isString()) { | ||
// overload 1 | ||
return ConvertToScriptX(this->mPermissible->hasPermission(args[0].asString().toString())); | ||
} | ||
// TODO: overload 2 | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::addAttachment(Arguments const& args) { | ||
try { | ||
endstone::Result<endstone::PermissionAttachment*> val; | ||
if (IsInstanceOf<PluginAPI>(args[0]) && args.size() == 1) { | ||
// overload 1 | ||
val = this->mPermissible->addAttachment(*ENGINE_DATA()->mPlugin); | ||
} else if (IsInstanceOf<PluginAPI>(args[0]) && args[1].isString() && args.size() == 3) { | ||
// overload 2 | ||
val = this->mPermissible->addAttachment( | ||
*ENGINE_DATA()->mPlugin, | ||
args[1].asString().toString(), | ||
args[2].asBoolean().value() | ||
); | ||
} | ||
|
||
if (!val.has_value()) { | ||
throw std::runtime_error(fmt::format("{}\n{}", val.error().getMessage(), val.error().getStackTrace())); | ||
} | ||
|
||
// TODO: PermissionAttachment constructor | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::removeAttachment(Arguments const& args) { | ||
try { | ||
// TODO: PermissionAttachment | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::recalculatePermissions(Arguments const& args) { | ||
try { | ||
this->mPermissible->recalculatePermissions(); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::getEffectivePermissions(Arguments const& args) { | ||
try { | ||
// TODO: PermissionAttachmentInfo | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissibleAPI::asCommandSender(Arguments const& args) { | ||
try { | ||
// TODO: CommandSender | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
|
||
} // namespace jse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
#include "Utils/Defines.h" | ||
#include "Utils/Using.h" | ||
#include "endstone/permissions/permissible.h" | ||
|
||
|
||
namespace jse { | ||
|
||
|
||
class PermissibleAPI : public ScriptClass { | ||
endstone::Permissible* mPermissible; | ||
|
||
public: | ||
template <typename T> | ||
explicit PermissibleAPI(endstone::Permissible* permissible, ScriptClass::ConstructFromCpp<T> tag) | ||
: ScriptClass(tag), | ||
mPermissible(permissible) {} | ||
|
||
explicit PermissibleAPI(endstone::Permissible* permissible) | ||
: ScriptClass(ScriptClass::ConstructFromCpp<PermissibleAPI>{}), | ||
mPermissible(permissible) {} | ||
|
||
static Local<Object> newPermissibleAPI(endstone::Permissible* permissible) { | ||
return (new PermissibleAPI(permissible))->getScriptObject(); | ||
} | ||
|
||
METHODS(toString); | ||
METHODS(isOP); | ||
METHODS(setOp); | ||
METHODS(isPermissionSet); | ||
METHODS(hasPermission); | ||
METHODS(addAttachment); | ||
METHODS(removeAttachment); | ||
METHODS(recalculatePermissions); | ||
METHODS(getEffectivePermissions); | ||
METHODS(asCommandSender); | ||
|
||
|
||
static ClassDefine<PermissibleAPI> builder; | ||
}; | ||
|
||
|
||
} // namespace jse |
Oops, something went wrong.