|
28 | 28 | import net.pistonmaster.pistonqueue.shared.events.PQServerConnectedEvent; |
29 | 29 | import net.pistonmaster.pistonqueue.shared.events.PQServerPreConnectEvent; |
30 | 30 | import net.pistonmaster.pistonqueue.shared.utils.BanType; |
31 | | -import net.pistonmaster.pistonqueue.shared.utils.Pair; |
32 | 31 |
|
33 | 32 | import java.time.Duration; |
34 | 33 | import java.time.Instant; |
@@ -278,9 +277,10 @@ protected void connectPlayer(QueueType type) { |
278 | 277 |
|
279 | 278 | indexPositionTime(); |
280 | 279 |
|
281 | | - List<Pair<Integer, Instant>> cache = type.getPositionCache().get(entry.getKey()); |
| 280 | + Map<Integer, Instant> cache = type.getPositionCache().get(entry.getKey()); |
282 | 281 | if (cache != null) { |
283 | | - cache.forEach(pair -> type.getDurationToPosition().put(pair.getLeft(), Duration.between(pair.getRight(), Instant.now()))); |
| 282 | + cache.forEach((position, instant) -> |
| 283 | + type.getDurationToPosition().put(position, Duration.between(instant, Instant.now()))); |
284 | 284 | } |
285 | 285 |
|
286 | 286 | player.get().connect(entry.getValue()); |
@@ -309,24 +309,15 @@ protected void indexPositionTime() { |
309 | 309 | for (QueueType type : QueueType.values()) { |
310 | 310 | int position = 0; |
311 | 311 |
|
312 | | - for (Map.Entry<UUID, String> entry : new LinkedHashMap<>(type.getQueueMap()).entrySet()) { |
313 | | - Optional<PlayerWrapper> player = plugin.getPlayer(entry.getKey()); |
314 | | - if (!player.isPresent()) { |
315 | | - continue; |
316 | | - } |
317 | | - |
| 312 | + for (UUID uuid : new LinkedHashMap<>(type.getQueueMap()).keySet()) { |
318 | 313 | position++; |
319 | | - |
320 | | - if (type.getPositionCache().containsKey(player.get().getUniqueId())) { |
321 | | - List<Pair<Integer, Instant>> list = type.getPositionCache().get(player.get().getUniqueId()); |
322 | | - int finalPosition = position; |
323 | | - if (list.stream().map(Pair::getLeft).noneMatch(integer -> integer == finalPosition)) { |
324 | | - list.add(new Pair<>(position, Instant.now())); |
325 | | - } |
| 314 | + Map<Integer, Instant> list = type.getPositionCache().get(uuid); |
| 315 | + if (list == null) { |
| 316 | + type.getPositionCache().put(uuid, new HashMap<>(Collections.singletonMap(position, Instant.now()))); |
326 | 317 | } else { |
327 | | - List<Pair<Integer, Instant>> list = new ArrayList<>(); |
328 | | - list.add(new Pair<>(position, Instant.now())); |
329 | | - type.getPositionCache().put(player.get().getUniqueId(), list); |
| 318 | + if (!list.containsKey(position)) { |
| 319 | + list.put(position, Instant.now()); |
| 320 | + } |
330 | 321 | } |
331 | 322 | } |
332 | 323 | } |
|
0 commit comments