Skip to content

Commit 4ec3a04

Browse files
Improve caching!
1 parent a5cc98a commit 4ec3a04

5 files changed

Lines changed: 51 additions & 24 deletions

File tree

PistonQueuePlaceholder/src/main/java/net/pistonmaster/pistonqueueplaceholder/PistonQueuePlaceholder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void onPluginMessageReceived(String channel, @NotNull Player player, byte
5050

5151
private void checkIfBungee() {
5252
if (!PaperLib.isSpigot()) {
53-
getLogger().severe(ChatColor.RED + "You probably run CraftBukkit... Please update atleast to spigot for this to work...");
53+
getLogger().severe(ChatColor.RED + "You probably run CraftBukkit... Please update at least to spigot for this to work...");
5454
getLogger().severe(ChatColor.RED + "Plugin disabled!");
5555
getServer().getPluginManager().disablePlugin(this);
5656
}

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# PistonQueue
22

3-
[![PistonDev Discord](https://discord.com/api/guilds/739784741124833301/embed.png)](https://discord.gg/CDrcxzH)
3+
[![PistonDev Discord](https://discord.com/api/guilds/739784741124833301/embed.png)](https://discord.gg/CDrcxzH)
44
[![](https://img.shields.io/badge/contributions-welcome-brightgreen)](https://github.com/AlexProgrammerDE/PistonQueue)
55

66
## About
77

8-
PistonQueue is a basic and easy to use queue plugin designed for anarchy and survival servers. This plugin is a fork
9-
of LeeesBungeeQueue but LeeesBungeeQueue was a designed more for the server 6b6t.org, so a fork of the plugin was created
8+
PistonQueue is a basic and easy to use queue plugin designed for anarchy and survival servers. This plugin is a fork of
9+
LeeesBungeeQueue but LeeesBungeeQueue was a designed more for the server 6b6t.org, so a fork of the plugin was created
1010
that is designed for everyone and has more updates and support.
1111

1212
## Features
@@ -29,7 +29,8 @@ Instead of showing an error saying the server is down you can customize this mes
2929

3030
### Auth server support
3131

32-
Auth server support for cracked (offline mode: false) servers. You can now have the authserver go first and then the queue!
32+
Auth server support for cracked (offline mode: false) servers. You can now have the authserver go first and then the
33+
queue!
3334

3435
## Setup
3536

pom.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>net.pistonmaster</groupId>
@@ -13,7 +13,15 @@
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
</properties>
1515
<url>https://pistonmaster.net/</url>
16-
16+
17+
<licenses>
18+
<license>
19+
<name>Apache License Version 2.0</name>
20+
<url>LICENSE</url>
21+
<distribution>>repo</distribution>
22+
</license>
23+
</licenses>
24+
1725
<build>
1826
<defaultGoal>clean package</defaultGoal>
1927
<plugins>

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.net.Socket;
4545
import java.nio.file.Files;
4646
import java.time.Duration;
47-
import java.time.Instant;
4847
import java.time.temporal.ChronoUnit;
4948
import java.util.*;
5049
import java.util.Map.Entry;
@@ -304,15 +303,15 @@ private void updateTab(QueueType queue, List<String> header, List<String> footer
304303
StringBuilder footerBuilder = new StringBuilder();
305304

306305
for (int i = 0; i < header.size(); i++) {
307-
headerBuilder.append(ChatUtils.parseToString(replacePosition(header.get(i), player.getUniqueId(), position, queue)));
306+
headerBuilder.append(ChatUtils.parseToString(replacePosition(header.get(i), position, queue)));
308307

309308
if (i != (header.size() - 1)) {
310309
headerBuilder.append("\n");
311310
}
312311
}
313312

314313
for (int i = 0; i < footer.size(); i++) {
315-
footerBuilder.append(ChatUtils.parseToString(replacePosition(footer.get(i), player.getUniqueId(), position, queue)));
314+
footerBuilder.append(ChatUtils.parseToString(replacePosition(footer.get(i), position, queue)));
316315

317316
if (i != (footer.size() - 1)) {
318317
footerBuilder.append("\n");
@@ -325,18 +324,7 @@ private void updateTab(QueueType queue, List<String> header, List<String> footer
325324
}
326325
}
327326

328-
private String replacePosition(String text, UUID uuid, int position, QueueType type) {
329-
if (type.getPositionCache().containsKey(uuid)) {
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-
}
334-
} else {
335-
List<Pair<Integer, Instant>> list = new ArrayList<>();
336-
list.add(new Pair<>(position, Instant.now()));
337-
type.getPositionCache().put(uuid, list);
338-
}
339-
327+
private String replacePosition(String text, int position, QueueType type) {
340328
if (type.getDurationToPosition().containsKey(position)) {
341329
Duration duration = type.getDurationToPosition().get(position);
342330

@@ -367,12 +355,12 @@ private String format(String str, Duration duration, int position) {
367355
String format = String.format("%dh %dm", duration.toHours(), duration.toMinutes() % 60);
368356

369357
if (duration.toHours() == 0)
370-
format = String.format("%dm", duration.toMinutes());
358+
format = String.format("%dm", duration.toMinutes() == 0 ? 1 : duration.toMinutes());
371359

372360
return str.replace("%position%", String.valueOf(position)).replace("%wait%", format);
373361
}
374362

375-
public void sendCustomData() {
363+
private void sendCustomData() {
376364
Collection<ProxiedPlayer> networkPlayers = getProxy().getPlayers();
377365

378366
if (networkPlayers == null || networkPlayers.isEmpty()) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ private void connectPlayer(QueueType type) {
211211
return;
212212
}
213213

214+
indexPositionTime();
215+
214216
List<Pair<Integer, Instant>> cache = type.getPositionCache().get(entry.getKey());
215217

216218
if (cache != null) {
@@ -288,4 +290,32 @@ private boolean isAnyoneQueued() {
288290

289291
return false;
290292
}
293+
294+
private void indexPositionTime() {
295+
for (QueueType type : QueueType.values()) {
296+
int position = 0;
297+
298+
for (Entry<UUID, String> entry : new LinkedHashMap<>(type.getQueueMap()).entrySet()) {
299+
ProxiedPlayer player = plugin.getProxy().getPlayer(entry.getKey());
300+
if (player == null || !player.isConnected()) {
301+
type.getQueueMap().remove(entry.getKey());
302+
continue;
303+
}
304+
305+
position++;
306+
307+
if (type.getPositionCache().containsKey(player.getUniqueId())) {
308+
List<Pair<Integer, Instant>> list = type.getPositionCache().get(player.getUniqueId());
309+
int finalPosition = position;
310+
if (list.stream().map(Pair::getLeft).noneMatch(integer -> integer == finalPosition)) {
311+
list.add(new Pair<>(position, Instant.now()));
312+
}
313+
} else {
314+
List<Pair<Integer, Instant>> list = new ArrayList<>();
315+
list.add(new Pair<>(position, Instant.now()));
316+
type.getPositionCache().put(player.getUniqueId(), list);
317+
}
318+
}
319+
}
320+
}
291321
}

0 commit comments

Comments
 (0)