-
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
5 changed files
with
91 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "OfflinePlayerAPI.h" | ||
#include "converter/Convert.h" | ||
#include "utils/Using.h" | ||
|
||
|
||
namespace jse { | ||
|
||
ClassDefine<OfflinePlayerAPI> OfflinePlayerAPI::builder = | ||
defineClass<OfflinePlayerAPI>("OfflinePlayer") | ||
.instanceFunction("getName", &OfflinePlayerAPI::getName) | ||
.instanceFunction("getUniqueId", &OfflinePlayerAPI::getUniqueId) | ||
.build(); | ||
|
||
|
||
Local<Value> OfflinePlayerAPI::toString(Arguments const& /* args */) { | ||
try { | ||
return ConvertToScript("OfflinePlayer"); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> OfflinePlayerAPI::getName(Arguments const& /* args */) { | ||
try { | ||
return ConvertToScript(get()->getName()); | ||
} | ||
Catch; | ||
} | ||
|
||
Local<Value> OfflinePlayerAPI::getUniqueId(Arguments const& /* args */) { | ||
try { | ||
return ConvertToScript(get()->getUniqueId()); | ||
} | ||
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,33 @@ | ||
#pragma once | ||
|
||
#include "api/APIHelper.h" | ||
#include "endstone/offline_player.h" | ||
#include "endstone/player.h" | ||
#include "utils/ResourceSafety.h" | ||
#include "utils/Using.h" | ||
namespace jse { | ||
|
||
|
||
class OfflinePlayerAPI : public ScriptClass { | ||
SafePointerHolder<endstone::OfflinePlayer> mData; | ||
|
||
public: | ||
explicit OfflinePlayerAPI(endstone::OfflinePlayer* data) | ||
: ScriptClass(ConstructFromCpp<OfflinePlayerAPI>{}), | ||
mData(data) {} | ||
|
||
Local<Object> newInstance(endstone::OfflinePlayer* data) { return (new OfflinePlayerAPI(data))->getScriptObject(); } | ||
|
||
endstone::OfflinePlayer* get() { return mData.get(); } | ||
|
||
public: | ||
METHODS(toString); | ||
METHODS(getName); | ||
METHODS(getUniqueId); | ||
|
||
public: | ||
static ClassDefine<OfflinePlayerAPI> 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,18 @@ | ||
/// <reference path="../index.d.ts"/> | ||
|
||
declare interface OfflinePlayer { | ||
/** | ||
* Returns the name of this player | ||
* 返回玩家的名字 | ||
* | ||
* @returns Player name or null if we have not seen a name for this player yet | ||
* @returns 玩家的名字,如果尚未看到该玩家的名字,则返回null | ||
*/ | ||
getName(): string; | ||
|
||
/** | ||
* Returns the UUID of this player | ||
* 返回玩家的UUID | ||
*/ | ||
getUniqueId(): UUID; | ||
} |
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