File tree Expand file tree Collapse file tree 6 files changed +37
-7
lines changed Expand file tree Collapse file tree 6 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -44,11 +44,20 @@ void DeviceClass::setPlayer(Player* player) {
4444 try {
4545 if (player) {
4646 mWeakEntity = player->getWeakEntity ();
47+ mValid = true ;
4748 }
48- } catch (...) {}
49+ } catch (...) {
50+ mValid = false ;
51+ }
4952}
5053
51- Player* DeviceClass::getPlayer () { return mWeakEntity .tryUnwrap <Player>().as_ptr (); }
54+ Player* DeviceClass::getPlayer () {
55+ if (mValid ) {
56+ return mWeakEntity .tryUnwrap <Player>().as_ptr ();
57+ } else {
58+ return nullptr ;
59+ }
60+ }
5261
5362Local<Value> DeviceClass::getIP () {
5463 try {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Player;
88class DeviceClass : public ScriptClass {
99private:
1010 WeakRef<EntityContext> mWeakEntity ;
11+ bool mValid ;
1112
1213public:
1314 explicit DeviceClass (Player* player) : ScriptClass(ScriptClass::ConstructFromCpp<DeviceClass>{}) {
Original file line number Diff line number Diff line change @@ -209,14 +209,23 @@ void EntityClass::set(Actor* actor) {
209209 try {
210210 if (actor) {
211211 mWeakEntity = actor->getWeakEntity ();
212+ mValid = true ;
212213 }
213- } catch (...) {}
214+ } catch (...) {
215+ mValid = false ;
216+ }
214217}
215218
216219WeakStorageEntity& WeakStorageEntity::operator =(WeakStorageEntity const &) = default ;
217220WeakStorageEntity::WeakStorageEntity (WeakStorageEntity const &) = default;
218221
219- Actor* EntityClass::get () { return mWeakEntity .tryUnwrap <Actor>().as_ptr (); }
222+ Actor* EntityClass::get () {
223+ if (mValid ) {
224+ return mWeakEntity .tryUnwrap <Actor>().as_ptr ();
225+ } else {
226+ return nullptr ;
227+ }
228+ }
220229
221230Local<Value> EntityClass::asPointer (const Arguments& args) {
222231 try {
Original file line number Diff line number Diff line change 11#pragma once
22#include " api/APIHelp.h"
3- #include " mc/world/ActorRuntimeID.h"
43#include " mc/entity/WeakEntityRef.h"
4+ #include " mc/world/ActorRuntimeID.h"
55
66// ////////////////// Classes ////////////////////
77class Actor ;
88class EntityClass : public ScriptClass {
99private:
1010 WeakRef<EntityContext> mWeakEntity ;
11+ bool mValid ;
1112
1213public:
1314 explicit EntityClass (Actor* actor) : ScriptClass(ScriptClass::ConstructFromCpp<EntityClass>{}) { set (actor); }
Original file line number Diff line number Diff line change @@ -723,11 +723,20 @@ void PlayerClass::set(Player* player) {
723723 try {
724724 if (player) {
725725 mWeakEntity = player->getWeakEntity ();
726+ mValid = true ;
726727 }
727- } catch (...) {}
728+ } catch (...) {
729+ mValid = false ;
730+ }
728731}
729732
730- Player* PlayerClass::get () { return mWeakEntity .tryUnwrap <Player>().as_ptr (); }
733+ Player* PlayerClass::get () {
734+ if (mValid ) {
735+ return mWeakEntity .tryUnwrap <Player>().as_ptr ();
736+ } else {
737+ return nullptr ;
738+ }
739+ }
731740
732741Local<Value> PlayerClass::getName () {
733742 try {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Player;
1010class PlayerClass : public ScriptClass {
1111private:
1212 WeakRef<EntityContext> mWeakEntity ;
13+ bool mValid ;
1314
1415public:
1516 explicit PlayerClass (Player* player);
You can’t perform that action at this time.
0 commit comments