|
51 | 51 | public class HypixelAbstractionLayer { |
52 | 52 |
|
53 | 53 | private static final HashMap<String, CompletableFuture<PlayerReply>> cachedPlayerData = new HashMap<>(); |
| 54 | + private static final HashMap<String, Integer> tempValues = new HashMap<>(); |
54 | 55 | private static final AtomicInteger hypixelApiCalls = new AtomicInteger(0); |
55 | 56 | private static Supplier<String> keySupplier; |
56 | 57 | private static HypixelAPI api; |
@@ -79,23 +80,25 @@ public static int getPlayerLevel(String uuid, String mode) { |
79 | 80 | if (loadPlayerDataIfAbsent(uuid)) { |
80 | 81 | PlayerReply.Player player = getPlayer(uuid); |
81 | 82 | if (player != null) { |
| 83 | + int value = -1; |
82 | 84 | if (Objects.equals(mode, LevelHeadMode.NETWORK.toString())) { |
83 | | - return (int) player.getNetworkLevel(); |
| 85 | + value = (int) player.getNetworkLevel(); |
84 | 86 | } 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); |
89 | 88 | } else if (Objects.equals(mode, LevelHeadMode.SKYWARS.toString())) { |
90 | 89 | int exp = player |
91 | 90 | .getIntProperty("stats.SkyWars.skywars_experience", -1); |
92 | 91 | if(exp != -1) { |
93 | | - return Math.round(ExpCalculator.getLevelForExp(exp)); |
| 92 | + value = Math.round(ExpCalculator.getLevelForExp(exp)); |
94 | 93 | } |
95 | 94 | } |
| 95 | + if(value > -1){ |
| 96 | + tempValues.remove(uuid); |
| 97 | + return value; |
| 98 | + } |
96 | 99 | } |
97 | 100 | } |
98 | | - return (int) (new Random().nextGaussian()*30+150); |
| 101 | + return tempValues.computeIfAbsent(uuid, s -> (int) (new Random().nextGaussian()*30+150)); |
99 | 102 | } |
100 | 103 |
|
101 | 104 | private static PlayerReply.Player getPlayer(String uuid) { |
|
0 commit comments