Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 69d1c0c

Browse files
committed
do not recalculate random level values every call
1 parent f56803d commit 69d1c0c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

common/src/main/java/io/github/axolotlclient/modules/hypixel/HypixelAbstractionLayer.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
public class HypixelAbstractionLayer {
5252

5353
private static final HashMap<String, CompletableFuture<PlayerReply>> cachedPlayerData = new HashMap<>();
54+
private static final HashMap<String, Integer> tempValues = new HashMap<>();
5455
private static final AtomicInteger hypixelApiCalls = new AtomicInteger(0);
5556
private static Supplier<String> keySupplier;
5657
private static HypixelAPI api;
@@ -79,23 +80,25 @@ public static int getPlayerLevel(String uuid, String mode) {
7980
if (loadPlayerDataIfAbsent(uuid)) {
8081
PlayerReply.Player player = getPlayer(uuid);
8182
if (player != null) {
83+
int value = -1;
8284
if (Objects.equals(mode, LevelHeadMode.NETWORK.toString())) {
83-
return (int) player.getNetworkLevel();
85+
value = (int) player.getNetworkLevel();
8486
} else if (Objects.equals(mode, LevelHeadMode.BEDWARS.toString())) {
85-
int level = player.getIntProperty("achievements.bedwars_level", -1);
86-
if(level != -1){
87-
return level;
88-
}
87+
value = player.getIntProperty("achievements.bedwars_level", -1);
8988
} else if (Objects.equals(mode, LevelHeadMode.SKYWARS.toString())) {
9089
int exp = player
9190
.getIntProperty("stats.SkyWars.skywars_experience", -1);
9291
if(exp != -1) {
93-
return Math.round(ExpCalculator.getLevelForExp(exp));
92+
value = Math.round(ExpCalculator.getLevelForExp(exp));
9493
}
9594
}
95+
if(value > -1){
96+
tempValues.remove(uuid);
97+
return value;
98+
}
9699
}
97100
}
98-
return (int) (new Random().nextGaussian()*30+150);
101+
return tempValues.computeIfAbsent(uuid, s -> (int) (new Random().nextGaussian()*30+150));
99102
}
100103

101104
private static PlayerReply.Player getPlayer(String uuid) {

0 commit comments

Comments
 (0)