1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

[IMPROVE] Add random argument for /exp command

ex: rand_5-10
This commit is contained in:
Teyir 2022-11-28 16:26:43 +01:00
parent 5a5b82e630
commit 3fc3da0659

View File

@ -9,6 +9,8 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import java.util.Random;
public class exp implements Cmd {
private enum Action {
@ -51,11 +53,28 @@ public class exp implements Cmd {
}
double amount = 0.0;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
return true;
/* Add random argument, ex: rand_5-10 */
if(args[3].startsWith("rand_")){
String data= args[3].split("(?i)rand_")[1];
String[] arr = data.split("-");
int amountMin = Integer.parseInt(arr[0]);
int amountMax = Integer.parseInt(arr[1]);
if(amountMin <= amountMax){
amount = amountMin + new Random().nextDouble() * (amountMax - amountMin);
} else {
amount = amountMax;
}
} else {
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
return true;
}
}
try {