@@ -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>();
@@ -136,7 +140,7 @@ Local<Value> ObjectiveClass::addScore(const Arguments& args) {
136
140
if (args[0 ].isString ()) {
137
141
std::string name = args[0 ].toStr ();
138
142
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
139
- Objective* obj = scoreboard. getObjective (objname );
143
+ Objective* obj = get ( );
140
144
if (!obj) {
141
145
return Boolean::newBoolean (false );
142
146
}
@@ -148,21 +152,23 @@ Local<Value> ObjectiveClass::addScore(const Arguments& args) {
148
152
scoreboard
149
153
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Add);
150
154
if (isSuccess) return Number::newNumber (score);
155
+ return Local<Value>();
151
156
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
152
157
auto player = PlayerClass::extract (args[0 ]);
153
158
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
154
- Objective* obj = scoreboard. getObjective (objname );
159
+ Objective* obj = get ( );
155
160
if (!obj) {
156
161
return Boolean::newBoolean (false );
157
162
}
158
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
163
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
159
164
if (!id.isValid ()) {
160
165
scoreboard.createScoreboardId (*player);
161
166
}
162
167
bool isSuccess = false ;
163
168
scoreboard
164
169
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Add);
165
170
if (isSuccess) return Number::newNumber (score);
171
+ return Local<Value>();
166
172
} else {
167
173
LOG_WRONG_ARG_TYPE ();
168
174
return Local<Value>();
@@ -181,7 +187,7 @@ Local<Value> ObjectiveClass::reduceScore(const Arguments& args) {
181
187
if (args[0 ].isString ()) {
182
188
std::string name = args[0 ].toStr ();
183
189
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
184
- Objective* obj = scoreboard. getObjective (objname );
190
+ Objective* obj = get ( );
185
191
if (!obj) {
186
192
return Boolean::newBoolean (false );
187
193
}
@@ -193,21 +199,23 @@ Local<Value> ObjectiveClass::reduceScore(const Arguments& args) {
193
199
scoreboard
194
200
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Subtract);
195
201
if (isSuccess) return Number::newNumber (score);
202
+ return Local<Value>();
196
203
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
197
204
auto player = PlayerClass::extract (args[0 ]);
198
205
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
199
- Objective* obj = scoreboard. getObjective (objname );
206
+ Objective* obj = get ( );
200
207
if (!obj) {
201
208
return Boolean::newBoolean (false );
202
209
}
203
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
210
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
204
211
if (!id.isValid ()) {
205
212
scoreboard.createScoreboardId (*player);
206
213
}
207
214
bool isSuccess = false ;
208
215
scoreboard
209
216
.modifyPlayerScore (isSuccess, id, *obj, args[1 ].asNumber ().toInt32 (), PlayerScoreSetFunction::Subtract);
210
217
if (isSuccess) return Number::newNumber (score);
218
+ return Local<Value>();
211
219
} else {
212
220
LOG_WRONG_ARG_TYPE ();
213
221
return Local<Value>();
@@ -222,7 +230,7 @@ Local<Value> ObjectiveClass::deleteScore(const Arguments& args) {
222
230
try {
223
231
if (args[0 ].isString ()) {
224
232
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
225
- Objective* obj = scoreboard. getObjective (objname );
233
+ Objective* obj = get ( );
226
234
if (!obj) {
227
235
return Boolean::newBoolean (false );
228
236
}
@@ -234,11 +242,11 @@ Local<Value> ObjectiveClass::deleteScore(const Arguments& args) {
234
242
} else if (IsInstanceOf<PlayerClass>(args[0 ])) {
235
243
Player* player = PlayerClass::extract (args[0 ]);
236
244
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
237
- Objective* obj = scoreboard. getObjective (objname );
245
+ Objective* obj = get ( );
238
246
if (!obj) {
239
247
return Boolean::newBoolean (false );
240
248
}
241
- const ScoreboardId& id = scoreboard.getScoreboardId (player-> getOrCreateUniqueID () );
249
+ const ScoreboardId& id = scoreboard.getScoreboardId (* player);
242
250
if (!id.isValid ()) {
243
251
return Boolean::newBoolean (true );
244
252
}
@@ -258,8 +266,7 @@ Local<Value> ObjectiveClass::getScore(const Arguments& args) {
258
266
if (args[0 ].isString ()) {
259
267
Scoreboard& board = ll::service::getLevel ()->getScoreboard ();
260
268
Objective* objective = board.getObjective (objname);
261
- ScoreboardId sid =
262
- board.getScoreboardId (PlayerScoreboardId (std::atoll (args[0 ].asString ().toString ().c_str ())));
269
+ ScoreboardId sid = board.getScoreboardId (args[0 ].asString ().toString ());
263
270
if (!objective || !sid.isValid () || !objective->hasScore (sid)) {
264
271
return {};
265
272
}
@@ -291,7 +298,7 @@ Local<Value> McClass::getDisplayObjective(const Arguments& args) {
291
298
auto res = ll::service::getLevel ()->getScoreboard ().getDisplayObjective (slot);
292
299
293
300
if (!res) return Local<Value>();
294
- return ObjectiveClass::newObjective (( Objective*) res);
301
+ return ObjectiveClass::newObjective (const_cast < Objective*>( res-> mObjective ) );
295
302
}
296
303
CATCH (" Fail in GetDisplayObjective" );
297
304
}
@@ -304,8 +311,8 @@ Local<Value> McClass::clearDisplayObjective(const Arguments& args) {
304
311
string slot = args[0 ].toStr ();
305
312
auto res = ll::service::getLevel ()->getScoreboard ().clearDisplayObjective (slot);
306
313
307
- if (!res) return Local<Value>( );
308
- return ObjectiveClass::newObjective (res );
314
+ if (!res) return Boolean::newBoolean ( false );
315
+ return Boolean::newBoolean ( true );
309
316
}
310
317
CATCH (" Fail in ClearDisplayObjective" );
311
318
}
0 commit comments