@@ -212,18 +212,8 @@ private int setMoneyInternal(String id, double amount, boolean force) {
212212 SetMoneyEvent event = new SetMoneyEvent (id , amount );
213213 this .getServer ().getPluginManager ().callEvent (event );
214214 if (!event .isCancelled () || force ) {
215- if (this .provider .accountExists (id )) {
216- amount = event .getAmount ();
217-
218- if (amount <= this .getMaxMoney ()) {
219- this .provider .setMoney (id , amount );
220- return RET_SUCCESS ;
221- } else {
222- return RET_INVALID ;
223- }
224- } else {
225- return RET_NO_ACCOUNT ;
226- }
215+ return this .provider .setMoneyChecked (
216+ MAIN_CONFIG .getDefaultCurrency ().getName (), id , event .getAmount (), this .getMaxMoney ());
227217 }
228218 return RET_CANCELLED ;
229219 }
@@ -271,18 +261,8 @@ private int addMoneyInternal(String id, double amount, boolean force) {
271261 AddMoneyEvent event = new AddMoneyEvent (id , amount );
272262 this .getServer ().getPluginManager ().callEvent (event );
273263 if (!event .isCancelled () || force ) {
274- amount = event .getAmount ();
275- double money ;
276- if ((money = this .provider .getMoney (id )) != -1 ) {
277- if (money + amount > this .getMaxMoney ()) {
278- return RET_INVALID ;
279- } else {
280- this .provider .addMoney (id , amount );
281- return RET_SUCCESS ;
282- }
283- } else {
284- return RET_NO_ACCOUNT ;
285- }
264+ return this .provider .addMoneyChecked (
265+ MAIN_CONFIG .getDefaultCurrency ().getName (), id , event .getAmount (), this .getMaxMoney ());
286266 }
287267 return RET_CANCELLED ;
288268 }
@@ -331,19 +311,8 @@ private int reduceMoneyInternal(String id, double amount, boolean force) {
331311 ReduceMoneyEvent event = new ReduceMoneyEvent (id , amount );
332312 this .getServer ().getPluginManager ().callEvent (event );
333313 if (!event .isCancelled () || force ) {
334- amount = event .getAmount ();
335-
336- double money ;
337- if ((money = this .provider .getMoney (id )) != -1 ) {
338- if (money - amount < 0 ) {
339- return RET_INVALID ;
340- } else {
341- this .provider .reduceMoney (id , amount );
342- return RET_SUCCESS ;
343- }
344- } else {
345- return RET_NO_ACCOUNT ;
346- }
314+ return this .provider .reduceMoneyChecked (
315+ MAIN_CONFIG .getDefaultCurrency ().getName (), id , event .getAmount ());
347316 }
348317 return RET_CANCELLED ;
349318 }
@@ -442,17 +411,7 @@ private int setMoneyInternal(String id, double amount, String currencyName, bool
442411 SetMoneyEvent event = new SetMoneyEvent (id , amount , currencyName );
443412 this .getServer ().getPluginManager ().callEvent (event );
444413 if (!event .isCancelled () || force ) {
445- if (this .provider .accountExists (currencyName , id )) {
446- amount = event .getAmount ();
447- if (amount <= getMaxMoney (currencyName )) {
448- this .provider .setMoney (currencyName , id , amount );
449- return RET_SUCCESS ;
450- } else {
451- return RET_INVALID ;
452- }
453- } else {
454- return RET_NO_ACCOUNT ;
455- }
414+ return this .provider .setMoneyChecked (currencyName , id , event .getAmount (), getMaxMoney (currencyName ));
456415 }
457416 return RET_CANCELLED ;
458417 }
@@ -500,18 +459,7 @@ private int addMoneyInternal(String id, double amount, String currencyName, bool
500459 AddMoneyEvent event = new AddMoneyEvent (id , amount , currencyName );
501460 this .getServer ().getPluginManager ().callEvent (event );
502461 if (!event .isCancelled () || force ) {
503- amount = event .getAmount ();
504- double money = this .provider .getMoney (currencyName , id );
505- if (money != -1 ) {
506- if (money + amount > getMaxMoney (currencyName )) {
507- return RET_INVALID ;
508- } else {
509- this .provider .addMoney (currencyName , id , amount );
510- return RET_SUCCESS ;
511- }
512- } else {
513- return RET_NO_ACCOUNT ;
514- }
462+ return this .provider .addMoneyChecked (currencyName , id , event .getAmount (), getMaxMoney (currencyName ));
515463 }
516464 return RET_CANCELLED ;
517465 }
@@ -559,18 +507,7 @@ private int reduceMoneyInternal(String id, double amount, String currencyName, b
559507 ReduceMoneyEvent event = new ReduceMoneyEvent (id , amount , currencyName );
560508 this .getServer ().getPluginManager ().callEvent (event );
561509 if (!event .isCancelled () || force ) {
562- amount = event .getAmount ();
563- double money = this .provider .getMoney (currencyName , id );
564- if (money != -1 ) {
565- if (money - amount < 0 ) {
566- return RET_INVALID ;
567- } else {
568- this .provider .reduceMoney (currencyName , id , amount );
569- return RET_SUCCESS ;
570- }
571- } else {
572- return RET_NO_ACCOUNT ;
573- }
510+ return this .provider .reduceMoneyChecked (currencyName , id , event .getAmount ());
574511 }
575512 return RET_CANCELLED ;
576513 }
0 commit comments