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) {
44
44
try {
45
45
if (player) {
46
46
mWeakEntity = player->getWeakEntity ();
47
+ mValid = true ;
47
48
}
48
- } catch (...) {}
49
+ } catch (...) {
50
+ mValid = false ;
51
+ }
49
52
}
50
53
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
+ }
52
61
53
62
Local<Value> DeviceClass::getIP () {
54
63
try {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Player;
8
8
class DeviceClass : public ScriptClass {
9
9
private:
10
10
WeakRef<EntityContext> mWeakEntity ;
11
+ bool mValid ;
11
12
12
13
public:
13
14
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) {
209
209
try {
210
210
if (actor) {
211
211
mWeakEntity = actor->getWeakEntity ();
212
+ mValid = true ;
212
213
}
213
- } catch (...) {}
214
+ } catch (...) {
215
+ mValid = false ;
216
+ }
214
217
}
215
218
216
219
WeakStorageEntity& WeakStorageEntity::operator =(WeakStorageEntity const &) = default ;
217
220
WeakStorageEntity::WeakStorageEntity (WeakStorageEntity const &) = default;
218
221
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
+ }
220
229
221
230
Local<Value> EntityClass::asPointer (const Arguments& args) {
222
231
try {
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
#include " api/APIHelp.h"
3
- #include " mc/world/ActorRuntimeID.h"
4
3
#include " mc/entity/WeakEntityRef.h"
4
+ #include " mc/world/ActorRuntimeID.h"
5
5
6
6
// ////////////////// Classes ////////////////////
7
7
class Actor ;
8
8
class EntityClass : public ScriptClass {
9
9
private:
10
10
WeakRef<EntityContext> mWeakEntity ;
11
+ bool mValid ;
11
12
12
13
public:
13
14
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) {
723
723
try {
724
724
if (player) {
725
725
mWeakEntity = player->getWeakEntity ();
726
+ mValid = true ;
726
727
}
727
- } catch (...) {}
728
+ } catch (...) {
729
+ mValid = false ;
730
+ }
728
731
}
729
732
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
+ }
731
740
732
741
Local<Value> PlayerClass::getName () {
733
742
try {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Player;
10
10
class PlayerClass : public ScriptClass {
11
11
private:
12
12
WeakRef<EntityContext> mWeakEntity ;
13
+ bool mValid ;
13
14
14
15
public:
15
16
explicit PlayerClass (Player* player);
You can’t perform that action at this time.
0 commit comments