Skip to content

Commit fa1c1ab

Browse files
Fix stupid unsorted position bug
1 parent 39d794a commit fa1c1ab

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/main/java/net/pistonmaster/pistonqueue/bungee/PistonQueue.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,16 @@ private void sendMessage(QueueType queue, boolean bool, ChatMessageType type) {
269269

270270
int position = 0;
271271

272-
for (Entry<UUID, String> entry : new HashMap<>(queue.getQueueMap()).entrySet()) {
273-
position++;
274-
272+
for (Entry<UUID, String> entry : new LinkedHashMap<>(queue.getQueueMap()).entrySet()) {
275273
ProxiedPlayer player = getProxy().getPlayer(entry.getKey());
276274

277275
if (player == null || !player.isConnected()) {
278276
queue.getQueueMap().remove(entry.getKey());
279277
continue;
280278
}
281279

280+
position++;
281+
282282
player.sendMessage(type,
283283
ChatUtils.parseToComponent(Config.QUEUEPOSITION
284284
.replace("%position%", String.valueOf(position))
@@ -291,15 +291,15 @@ private void sendMessage(QueueType queue, boolean bool, ChatMessageType type) {
291291
private void updateTab(QueueType queue, List<String> header, List<String> footer) {
292292
int position = 0;
293293

294-
for (Entry<UUID, String> entry : new HashMap<>(queue.getQueueMap()).entrySet()) {
295-
position++;
296-
294+
for (Entry<UUID, String> entry : new LinkedHashMap<>(queue.getQueueMap()).entrySet()) {
297295
ProxiedPlayer player = getProxy().getPlayer(entry.getKey());
298296
if (player == null || !player.isConnected()) {
299297
queue.getQueueMap().remove(entry.getKey());
300298
continue;
301299
}
302300

301+
position++;
302+
303303
StringBuilder headerBuilder = new StringBuilder();
304304
StringBuilder footerBuilder = new StringBuilder();
305305

@@ -327,7 +327,10 @@ private void updateTab(QueueType queue, List<String> header, List<String> footer
327327

328328
private String replacePosition(String text, UUID uuid, int position, QueueType type) {
329329
if (type.getPositionCache().containsKey(uuid)) {
330-
type.getPositionCache().get(uuid).add(new Pair<>(position, Instant.now()));
330+
List<Pair<Integer, Instant>> list = type.getPositionCache().get(uuid);
331+
if (list.stream().map(Pair::getLeft).noneMatch(integer -> integer == position)) {
332+
list.add(new Pair<>(position, Instant.now()));
333+
}
331334
} else {
332335
List<Pair<Integer, Instant>> list = new ArrayList<>();
333336
list.add(new Pair<>(position, Instant.now()));
@@ -337,12 +340,7 @@ private String replacePosition(String text, UUID uuid, int position, QueueType t
337340
if (type.getDurationToPosition().containsKey(position)) {
338341
Duration duration = type.getDurationToPosition().get(position);
339342

340-
String format = String.format("%dh %dm", duration.toHours(), duration.toMinutes() % 60);
341-
342-
if (duration.toHours() == 0)
343-
format = String.format("%dm", duration.toMinutes());
344-
345-
return text.replace("%position%", String.valueOf(position)).replace("%wait%", format);
343+
return format(text, duration, position);
346344
} else {
347345
AtomicInteger biggestPositionAtomic = new AtomicInteger();
348346
AtomicReference<Duration> bestDurationAtomic = new AtomicReference<>(Duration.ZERO);

src/main/java/net/pistonmaster/pistonqueue/bungee/listeners/QueueListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private boolean isAuthToQueue(ServerSwitchEvent event) {
281281
}
282282

283283
private boolean isAnyoneQueued() {
284-
for (QueueType type :QueueType.values()) {
284+
for (QueueType type : QueueType.values()) {
285285
if (!type.getQueueMap().isEmpty())
286286
return true;
287287
}

0 commit comments

Comments
 (0)