-
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
8 changed files
with
254 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
declare class Permission { | ||
toString(): "Permission" | ||
|
||
getName(): string; | ||
|
||
getChildren(): { [k: string]: boolean }; | ||
|
||
getDefault(): Enums.PermissionDefault; | ||
|
||
setDefault(default_: Enums.PermissionDefault): void; | ||
|
||
getDescription(): string | ||
|
||
setDescription(description: string): void; | ||
|
||
getPermissibles(): Permissible[]; | ||
|
||
recalculatePermissibles(): void; | ||
|
||
addParent(name: string, value: boolean): Permission; | ||
|
||
addParent(perm: Permission, value: boolean): void; | ||
|
||
// init(): any; // TODO | ||
} | ||
|
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
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,97 @@ | ||
#include "PermissionAPI.h" | ||
#include "API/APIHelper.h" | ||
#include "API/PermissibleAPI.h" | ||
#include "Utils/Convert.h" | ||
#include "endstone/permissions/permission_default.h" | ||
|
||
namespace jse { | ||
|
||
Local<Value> PermissionAPI::toString(Arguments const& args) { return ConvertToScriptX("Permission"); } | ||
|
||
Local<Value> PermissionAPI::getName(Arguments const& args) { | ||
try { | ||
return ConvertToScriptX(this->mPermission->getName()); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::getChildren(Arguments const& args) { | ||
try { | ||
return ConvertToScriptX(this->mPermission->getChildren()); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::getDefault(Arguments const& args) { | ||
try { | ||
return ConvertToScriptX(this->mPermission->getDefault()); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::setDefault(Arguments const& args) { | ||
try { | ||
this->mPermission->setDefault(ConvertFromScriptX<endstone::PermissionDefault>(args[0])); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::getDescription(Arguments const& args) { | ||
try { | ||
return ConvertToScriptX(this->mPermission->getDescription()); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::setDescription(Arguments const& args) { | ||
try { | ||
this->mPermission->setDescription(args[0].asString().toString()); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::getPermissibles(Arguments const& args) { | ||
try { | ||
auto perms = this->mPermission->getPermissibles(); | ||
auto array = Array::newArray(perms.size()); | ||
for (auto p : perms) { | ||
array.add(PermissibleAPI::newPermissibleAPI(p)); | ||
} | ||
return array; | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::recalculatePermissibles(Arguments const& args) { | ||
try { | ||
this->mPermission->recalculatePermissibles(); | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::addParent(Arguments const& args) { | ||
try { | ||
if (args[0].isString()) { | ||
if (auto val = this->mPermission->addParent(args[0].asString().toString(), args[1].asBoolean().value())) { | ||
return PermissionAPI::newPermissionAPI(val); | ||
} | ||
} else if (IsInstanceOf<PermissionAPI>(args[0])) { | ||
this->mPermission->addParent(*unWarp(args[0]), args[1].asBoolean().value()); | ||
} | ||
return Local<Value>(); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> PermissionAPI::init(Arguments const& args) { | ||
try { | ||
// TODO | ||
} | ||
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,46 @@ | ||
#pragma once | ||
#include "API/APIHelper.h" | ||
#include "Utils/Defines.h" | ||
#include "Utils/Using.h" | ||
#include "endstone/permissions/permission.h" | ||
|
||
|
||
namespace jse { | ||
|
||
|
||
class PermissionAPI : public ScriptClass { | ||
endstone::Permission* mPermission; | ||
|
||
public: | ||
explicit PermissionAPI(endstone::Permission* permission) | ||
: ScriptClass(ScriptClass::ConstructFromCpp<PermissionAPI>{}), | ||
mPermission(permission) {} | ||
|
||
static Local<Object> newPermissionAPI(endstone::Permission* permission) { | ||
return (new PermissionAPI{permission})->getScriptObject(); | ||
} | ||
|
||
static endstone::Permission* unWarp(Local<Value> val) { | ||
if (IsInstanceOf<PermissionAPI>(val)) { | ||
return EngineScope::currentEngine()->getNativeInstance<PermissionAPI>(val)->get(); | ||
} | ||
return nullptr; | ||
} | ||
|
||
endstone::Permission* get() { return mPermission; } | ||
|
||
METHODS(toString); | ||
METHODS(getName); | ||
METHODS(getChildren); | ||
METHODS(getDefault); | ||
METHODS(setDefault); | ||
METHODS(getDescription); | ||
METHODS(setDescription); | ||
METHODS(getPermissibles); | ||
METHODS(recalculatePermissibles); | ||
METHODS(addParent); | ||
METHODS(init); | ||
}; | ||
|
||
|
||
} // 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