Skip to content

Commit

Permalink
fix CommonVariableBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Mar 6, 2024
1 parent f65e701 commit 30b1322
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.hsgamer.hscore.common.StringReplacer;
import me.hsgamer.hscore.common.Validate;

import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;

/**
Expand All @@ -26,15 +27,20 @@ public static void registerVariables(VariableBundle bundle) {
String[] split = original.split(":", 2);
String s1 = split[0].trim();
String s2 = split[1].trim();
if (Validate.isValidInteger(s1) && Validate.isValidInteger(s2)) {
int i1 = Integer.parseInt(s1);
int i2 = Integer.parseInt(s2);
Optional<Integer> optional1 = Validate.getNumber(s1).map(Number::intValue);
Optional<Integer> optional2 = Validate.getNumber(s2).map(Number::intValue);
if (optional1.isPresent() && optional2.isPresent()) {
int i1 = optional1.get();
int i2 = optional2.get();
int max = Math.max(i1, i2);
int min = Math.min(i1, i2);
return String.valueOf(ThreadLocalRandom.current().nextInt(min, max + 1));
}
} else if (Validate.isValidInteger(original)) {
return String.valueOf(ThreadLocalRandom.current().nextInt(Integer.parseInt(original)));
} else {
Optional<Integer> optional = Validate.getNumber(original).map(Number::intValue);
if (optional.isPresent()) {
return String.valueOf(ThreadLocalRandom.current().nextInt(optional.get()));
}
}
return null;
}));
Expand Down

0 comments on commit 30b1322

Please sign in to comment.