@@ -82,6 +82,8 @@ Local<Value> ObjectiveClass::setDisplay(const Arguments& args) {
82
82
CATCH (" Fail in setDisplay" );
83
83
}
84
84
85
+ // /////////////////////////////////////////////////////////////////
86
+
85
87
Local<Value> ObjectiveClass::setScore (const Arguments& args) {
86
88
CHECK_ARGS_COUNT (args, 2 )
87
89
CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber )
@@ -92,7 +94,7 @@ Local<Value> ObjectiveClass::setScore(const Arguments& args) {
92
94
if (args[0 ].isString ()) {
93
95
std::string name = args[0 ].toStr ();
94
96
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
95
- Objective* obj = scoreboard. getObjective (objname );
97
+ Objective* obj = get ( );
96
98
if (!obj) {
97
99
return Boolean::newBoolean (false );
98
100
}
@@ -103,21 +105,23 @@ Local<Value> ObjectiveClass::setScore(const Arguments& args) {
103
105
bool isSuccess = false ;
104
106
scoreboard.modifyPlayerScore (isSuccess, id, *obj, score, PlayerScoreSetFunction::Set);
105
107
if (isSuccess) return Number::newNumber (score);
108
+ return Local<Value>();
106
109
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
107
110
auto player = PlayerClass::extract (args[0 ]);
108
111
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
109
- Objective* obj = scoreboard. getObjective (objname );
112
+ Objective* obj = get ( );
110
113
if (!obj) {
111
114
return Boolean::newBoolean (false );
112
115
}
113
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
116
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
114
117
if (!id.isValid ()) {
115
118
scoreboard.createScoreboardId (*player);
116
119
}
117
120
bool isSuccess = false ;
118
121
scoreboard
119
122
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Set);
120
123
if (isSuccess) return Number::newNumber (score);
124
+ return Local<Value>();
121
125
} else {
122
126
LOG_WRONG_ARG_TYPE ();
123
127
return Local<Value>();
@@ -137,7 +141,7 @@ Local<Value> ObjectiveClass::addScore(const Arguments& args) {
137
141
if (args[0 ].isString ()) {
138
142
std::string name = args[0 ].toStr ();
139
143
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
140
- Objective* obj = scoreboard. getObjective (objname );
144
+ Objective* obj = get ( );
141
145
if (!obj) {
142
146
return Boolean::newBoolean (false );
143
147
}
@@ -149,21 +153,23 @@ Local<Value> ObjectiveClass::addScore(const Arguments& args) {
149
153
scoreboard
150
154
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Add);
151
155
if (isSuccess) return Number::newNumber (score);
156
+ return Local<Value>();
152
157
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
153
158
auto player = PlayerClass::extract (args[0 ]);
154
159
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
155
- Objective* obj = scoreboard. getObjective (objname );
160
+ Objective* obj = get ( );
156
161
if (!obj) {
157
162
return Boolean::newBoolean (false );
158
163
}
159
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
164
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
160
165
if (!id.isValid ()) {
161
166
scoreboard.createScoreboardId (*player);
162
167
}
163
168
bool isSuccess = false ;
164
169
scoreboard
165
170
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Add);
166
171
if (isSuccess) return Number::newNumber (score);
172
+ return Local<Value>();
167
173
} else {
168
174
LOG_WRONG_ARG_TYPE ();
169
175
return Local<Value>();
@@ -183,7 +189,7 @@ Local<Value> ObjectiveClass::reduceScore(const Arguments& args) {
183
189
if (args[0 ].isString ()) {
184
190
std::string name = args[0 ].toStr ();
185
191
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
186
- Objective* obj = scoreboard. getObjective (objname );
192
+ Objective* obj = get ( );
187
193
if (!obj) {
188
194
return Boolean::newBoolean (false );
189
195
}
@@ -195,21 +201,23 @@ Local<Value> ObjectiveClass::reduceScore(const Arguments& args) {
195
201
scoreboard
196
202
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Subtract);
197
203
if (isSuccess) return Number::newNumber (score);
204
+ return Local<Value>();
198
205
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
199
206
auto player = PlayerClass::extract (args[0 ]);
200
207
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
201
- Objective* obj = scoreboard. getObjective (objname );
208
+ Objective* obj = get ( );
202
209
if (!obj) {
203
210
return Boolean::newBoolean (false );
204
211
}
205
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
212
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
206
213
if (!id.isValid ()) {
207
214
scoreboard.createScoreboardId (*player);
208
215
}
209
216
bool isSuccess = false ;
210
217
scoreboard
211
218
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Subtract);
212
219
if (isSuccess) return Number::newNumber (score);
220
+ return Local<Value>();
213
221
} else {
214
222
LOG_WRONG_ARG_TYPE ();
215
223
return Local<Value>();
@@ -225,7 +233,7 @@ Local<Value> ObjectiveClass::deleteScore(const Arguments& args) {
225
233
try {
226
234
if (args[0 ].isString ()) {
227
235
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
228
- Objective* obj = scoreboard. getObjective (objname );
236
+ Objective* obj = get ( );
229
237
if (!obj) {
230
238
return Boolean::newBoolean (false );
231
239
}
@@ -237,11 +245,11 @@ Local<Value> ObjectiveClass::deleteScore(const Arguments& args) {
237
245
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
238
246
Player* player = PlayerClass::extract (args[0 ]);
239
247
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
240
- Objective* obj = scoreboard. getObjective (objname );
248
+ Objective* obj = get ( );
241
249
if (!obj) {
242
250
return Boolean::newBoolean (false );
243
251
}
244
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
252
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
245
253
if (!id.isValid ()) {
246
254
return Boolean::newBoolean (true );
247
255
}
@@ -261,8 +269,7 @@ Local<Value> ObjectiveClass::getScore(const Arguments& args) {
261
269
if (args[0 ].isString ()) {
262
270
Scoreboard& board = ll::service::getLevel ()->getScoreboard ();
263
271
Objective* objective = board.getObjective (objname);
264
- ScoreboardId sid =
265
- board.getScoreboardId (PlayerScoreboardId (std::atoll (args[0 ].asString ().toString ().c_str ())));
272
+ ScoreboardId sid = board.getScoreboardId (args[0 ].asString ().toString ());
266
273
if (!objective || !sid.isValid () || !objective->hasScore (sid)) {
267
274
return {};
268
275
}
@@ -294,7 +301,7 @@ Local<Value> McClass::getDisplayObjective(const Arguments& args) {
294
301
auto res = ll::service::getLevel ()->getScoreboard ().getDisplayObjective (slot);
295
302
296
303
if (!res) return Local<Value>();
297
- return ObjectiveClass::newObjective (( Objective*) res);
304
+ return ObjectiveClass::newObjective (const_cast < Objective*>( res-> mObjective ) );
298
305
}
299
306
CATCH (" Fail in GetDisplayObjective" );
300
307
}
@@ -307,8 +314,8 @@ Local<Value> McClass::clearDisplayObjective(const Arguments& args) {
307
314
string slot = args[0 ].toStr ();
308
315
auto res = ll::service::getLevel ()->getScoreboard ().clearDisplayObjective (slot);
309
316
310
- if (!res) return Local<Value>( );
311
- return ObjectiveClass::newObjective (res );
317
+ if (!res) return Boolean::newBoolean ( false );
318
+ return Boolean::newBoolean ( true );
312
319
}
313
320
CATCH (" Fail in ClearDisplayObjective" );
314
321
}
0 commit comments